Tom_LK
Tom_LK

Reputation: 113

Ordered proximity search

By ordered I mean term1 will always come before term2 in the document.

I have two documents: 1. "By ordered I mean term1 will always come before term2 in the document" 2. "By ordered I mean term2 will always come before term1 in the document"

if I make the query:

"term1 term2"~Integer.MAX_VALUE

my results is: 2 documents

How can I query to have one result (only if term1 come before term2): "By ordered I mean term1 will always come before term2 in the document"

Any Ideas?

Upvotes: 1

Views: 598

Answers (2)

Jayendra
Jayendra

Reputation: 52769

You would need to use SpanNearQuery
This Matches spans which are near one another. One can specify slop, the maximum number of intervening unmatched positions, as well as whether matches are required to be in-order.

However, the dismax and edismax query parsers with Solr uses the phrase query and hence the match is always unordered.

SurroundQueryParser supports the Span queries with an option to make a query for both ordered and unordered terms with a slight change in the syntax.
Although this Query Parser is available with the trunk only.

More info @ http://www.lucidimagination.com/blog/2009/02/22/exploring-query-parsers/

Upvotes: 1

Mikos
Mikos

Reputation: 8553

Look up span query. http://www.lucidimagination.com/blog/2009/07/18/the-spanquery/

Upvotes: 0

Related Questions