Sukhdeep Singh Handa
Sukhdeep Singh Handa

Reputation: 413

ASP.NET and Lucene proximate search

In Lucene's proximity search the order of the words searched is not maintained.

Is there any way to filter the search so that word1 will always come before word2 in resulted docs.

Upvotes: 0

Views: 132

Answers (1)

Jf Beaulac
Jf Beaulac

Reputation: 5246

There is the SpanNearQuery for that.

http://lucene.apache.org/core/old_versioned_docs/versions/2_9_4/api/all/org/apache/lucene/search/spans/SpanNearQuery.html

SpanTermQuery tq1 = new SpanTermQuery(new Term("field", "word1"));
SpanTermQuery tq2 = new SpanTermQuery(new Term("field", "word2"));
SpanNearQuery spanNear = new SpanNearQuery(new SpanQuery[]{tq1,tq2}, 2, true);

Upvotes: 1

Related Questions