You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Krzysztof Szalast <kr...@gmail.com> on 2010/08/18 15:07:27 UTC

World order sensitivity query id Solr

Hi,

First I very sorry form my bad English :/

I am new user of Apache Solr. I have read documentation and check
Google, but I can not find solution of my problem:
I need "words order sensitivity" query, for example I have two
documents in Solr index:
1. one something two something three something four
2. four something three something two something one
and I run query:

a)
query: one AND two
I want in result:
1. one something two something three something four - "one" is before
"two", just like in query
2. four something three something two something one - I don't need
this result, but it don't disturb if it is returned

b)
query: two AND one
I want in result:
1. four something three something two something one - "one" is after
"two", just like in query
2. one something two something three something four - I don't need
this result, but it don't disturb if it is returned

Is it possible? If yes, how?

regards
 Krzysztof

Re: World order sensitivity query id Solr

Posted by Ahmet Arslan <io...@yahoo.com>.
> First I very sorry form my bad English :/
> 
> I am new user of Apache Solr. I have read documentation and
> check
> Google, but I can not find solution of my problem:
> I need "words order sensitivity" query, for example I have
> two
> documents in Solr index:
> 1. one something two something three something four
> 2. four something three something two something one
> and I run query:
> 
> a)
> query: one AND two
> I want in result:
> 1. one something two something three something four - "one"
> is before
> "two", just like in query
> 2. four something three something two something one - I
> don't need
> this result, but it don't disturb if it is returned
> 
> b)
> query: two AND one
> I want in result:
> 1. four something three something two something one - "one"
> is after
> "two", just like in query
> 2. one something two something three something four - I
> don't need
> this result, but it don't disturb if it is returned
> 
> Is it possible? If yes, how?

It is possible but not out-of-the-box. You need to override SolrQueryParser so that it returns SpanNearQuery instead of PhraseQuery. SpanNearQuery can do ordered proximity search. With a slop of Integer.MAX you can achieve what you want. "one two"~Integer.MAX

Lucene in Action Book has a code listing for this task. (replacing SpanNearQuery with PhraseQuery) You can copy and use it.