On Sun, Jan 16, 2011 at 12:42 PM, Livia Hauser <[email protected]> wrote: > Hi All, > > i have my own query parser which generates fuzzy/wildcard queries instances. > It works fantastic, Lucene rocks ;-). > But i have to make sure the words are not to far apart. I checked current > proximity implementation. What i found is: PhraseQuery calculates a distance > between terms (no fuzzy logic possible). > I have to calculate the distance (proximity) on the base of fuzzy queries. > > Somebody a idea how i can implement this feature? > > Short example: > indexed string: "left word a b c d e f other right" > query string (fuzzy 0.5): "ohter word" > expected distance: 6 >
I think you can do this with lucene's stable branch (what should be our next 3.1 release): http://svn.apache.org/repos/asf/lucene/dev/branches/branch_3x/ Have a look at SpanMultiTermQueryWrapper: it allows you to rewrite any MultiTermQuery (such as Fuzzy/Wildcard) into a SpanQuery. For example in this case I think you would do: FuzzyQuery f1 = new FuzzyQuery(new Term("field", "ohter")); SpanQuery s1 = new SpanMultiTermQueryWrapper<FuzzyQuery>(f1); FuzzyQuery f2 = new FuzzyQuery(new Term("field", "word")); SpanQuery s2 = new SpanMultiTermQueryWrapper<FuzzyQuery>(f2); Now you can put the two spanqueries (s1 and s2) into a SpanNearQuery, and specify the maximum slop, and if they are required to be in order or not, etc etc. For more examples see the unit test: http://svn.apache.org/repos/asf/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpanMultiTermQueryWrapper.java --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
