lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Muir <rcm...@gmail.com>
Subject Re: how to implement a proximity search feature using Queries instead of terms
Date Sun, 16 Jan 2011 17:50:36 GMT
On Sun, Jan 16, 2011 at 12:42 PM, Livia Hauser <livia.hauser@web.de> 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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message