lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Elschot <paul.elsc...@xs4all.nl>
Subject Re: Filtering a SpanQuery
Date Tue, 06 May 2008 15:39:38 GMT
Eran,

Op Tuesday 06 May 2008 10:15:10 schreef Eran Sevi:
> Hi,
>
> I am looking for a way to filter a SpanQuery according to some other
> query (on another field from the one used for the SpanQuery). I need
> to get access to the spans themselves of course.
>  I don't care about the scoring of the filter results and just need
> the positions of hits found in the documents that matches the filter.

I think you'll have to implement the filtering on the Spans yourself.
That's not really difficult, just use Spans.skipTo().
The code to do that could look sth like this (untested):

Spans spans = yourSpanQuery.getSpans(reader);
BitSet bits = yourFilter.bits(reader);
int filterDoc = bits.nextSetBit(0);
while ((filterDoc >= 0) and spans.skipTo(filterDoc)) {
  boolean more = true;
  while (more and (spans.doc() == filterDoc)) {
     // use spans.start() and spans.end() here
     // ...
     more = spans.next();
  }
  if (! more) {
    break;
  }
  filterDoc = bits.nextSetBit(spans.doc());
}

Please check the javadocs of java.util.BitSet, there may
be a 1 off error in the arguments to nextSetBit().

Regards,
Paul Elschot


>
> I tried looking through the archives and found some reference to a
> SpanQueryFilter patch, however I don't see how it can help me achieve
> what I want to do. This class receives only one query parameter
> (which I guess is the actual query) and not a query and a filter for
> example.
>
> Any help about how I can achieve this will be appreciated.
>
> Thanks,
> Eran.



---------------------------------------------------------------------
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