lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Livia Hauser" <>
Subject Re: how to implement a proximity search feature using Queries instead of terms
Date Mon, 17 Jan 2011 07:50:36 GMT
Hi Robert,

it looks really good!
Many thanks!


-----Urspr√ľngliche Nachricht-----
Von: "Robert Muir" &lt;;
Gesendet: 16.01.2011 18:50:36
Betreff: Re: how to implement a proximity search feature using Queries instead of terms

>On Sun, Jan 16, 2011 at 12:42 PM, Livia Hauser <> 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):
>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:
>To unsubscribe, e-mail:
>For additional commands, e-mail:
Empfehlen Sie WEB.DE DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message