0

I am working with apache-solr-3.6.0 on windows machine. I would like to search for two words with certain number of words apart (No more than this number). For example: Consider the following phrases, I would like to search for Daisy & exam with no more than 2 words apart.

Daisy has exam.
Daisy has an exam.
Daisy has a math exam.
Daisy has a difficult math exam.

I searched for such thing and I tried Term Proximity.

http://localhost:8983/solr/select/?q="Daisy exam"~2&version=2.2&start=0&rows=10&indent=on&debugQuery=true

The result that I need should be the phrase: Daisy has an exam. But using the above criteria, the result was the last 3 phrase.

So any ideas to use an exact number of words apart?

Daisy
  • 847
  • 3
  • 13
  • 34

1 Answers1

0

Check out the related question here: Solr proximity ordered vs unordered

When you say 'no more than 2 words apart', then you should have both first and second phrase matched. Then your query would be "Daisy exam"~1, which will match Daisy exam and an insertion between them (which is one change: changes exam position from 2 to 3).

In order to prevent "Daisy exam" from the matched result, you can add -"Daisy exam" to your query. Alternatively you may add fq=-"Daisy exam" to your query string params.

Community
  • 1
  • 1
Mohsen
  • 3,512
  • 3
  • 38
  • 66
  • Thanks for your reply, but I would like the result to be the phrase: `Daisy has an exam.` and using `~1` wont achieve that result. even using `~2` will not let me have the exact result as if there is a phrase: `Daisy exam.` it will be included, and this is not what I want. Any Ideas? – Daisy Sep 17 '12 at 08:18
  • I don't think this would be possible with Solr, since `q~x` matches documents with changes less than or equal to x. BTW, you may exclude directly "Daisy exam" in `fq` if it solves the case. – Mohsen Sep 17 '12 at 10:52