lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <>
Subject Re: SpanNearQuery with minimum slop
Date Tue, 11 Apr 2006 15:56:00 GMT
Erik Hatcher wrote:
> I have a potential need for a SpanNearQuery with an exact non-zero  gap 
> specified

Ironically, you can now easily specify this with PhraseQuery, but not 
with SpanNearQuery.  You can construct a phrase query with explicit 
positions, e.g.:

PhraseQuery pq = new PhraseQuery();
pq.add(new Term("f", "x"), 0);
pq.add(new Term("f", "y"), 2);

This will match instances of "x" and "y" with exactly one word between 
them in field "f".

Unfortunately one cannot (yet) construct a SpanNearQuery with explicit 
positions.  I think that would be useful, and not too hard to add. 
Internally all the computation is in terms of positions, so adding this 
is mostly a matter of exposing this in the public API.

> Would this be as easy as modifying SpanNearQuery to have a minimum  and 
> maximum slop feature, and modifying NearSpans.checkSlop() to add  a 
> condition that the difference is >= the minimum slop?  At first  glance 
> it seems so, but I want to be sure I'm not missing something.

If you want to match something like "a ? b ? ? c", where "?" matches any 
word, then slop is not sufficient, you really need explicit positions, 
or else you'll match things like "a ? ? b ? c".


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

View raw message