Take the 2-minute tour ×
  • I am using solr 3.3.0 working out of the box using the example folder
  • solrQueryParser defaultOperator = "OR"

My problem is that Solr doesn't seem to be returning good results when I search for a multiple word phrase.

The following search return no results.

  1. http://localhost:8080/solr/select/?q=roof+fixing

However, when I search for roof or fixing, they both return a few good results.

  1. http://localhost:8080/solr/select/?q=roof returns 4 results
  2. http://localhost:8080/solr/select/?q=fixing returns 3 results

On the query for "roof fixing", I expect solr to return 7 results. The 4 records for roof and 3 records for fixing.

Is any special configuration necessary for that to happen?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You just expressed your query incorrectly.

Try the following query from the Admin page:

(roof OR fixing)

Or, if you want to find that in a particular field:

fieldname:(roof OR fixing)

When you give SOLR a query like "roof fixing" you are effectively asking for all documents which have "roof" AND "fixing" in the default field (or the default dismax set of fields. The only way to change the meaning is to rewrite the query that your users type in. That's what we do, but on a larger scale. We have a front end interface that provides a whole bunch of options and generate a SOLR query from it. People can enter a search term in a specific field and if there is more than one word and it's not quoted, we add the AND. Then we OR together all of the fields that are filled in. Some fields are special and have a MIN and a MAX version which we turn into a range query :[0 TO 125000]. And there are some dropdowns that support multiple selections which we also turn into an OR, e.g. State:("WA" OR "CA" OR "OR" OR "NV")

share|improve this answer
I think I understand your point but, I am letting users search through a front end interface, so I can't ask users to type (roof OR fixing). –  Filype Feb 27 '12 at 20:54
Thanks for the extra explanation, yet, I don't seem to get more results by typing localhost:8080/solr/select/?q=(roof%20OR%20fixing) –  Filype Feb 27 '12 at 22:14
Filype, if you're letting users search the front end, and expecting an or behavior for search, you should be processing their query on the back end before sending it to SOLR. You should be preparing your values with the parenthesis, as stated above. If you want to add OR or AND, give the user an option, detect that, and then prepare and inject those into your SOLR query before passing it to SOLR. –  Atomox Apr 30 '13 at 14:25
add comment

Solr won't necessarily return 7 results for "roof OR fixing" as one result could include both "roof" and "fixing". Suppose "roof" has 3 results, "fixing" has 4, but both "roof" and "fixing" appear in 2 results. You will get only 5 results on a search for "roof OR fixing" as Solr will not return duplicate results.

Have you tried using a url-encoded space ("%20") instead of the "+" sign? If the default operator is OR you should not need to include that operator.

share|improve this answer
roof%20fixing also returns 0 results, I understand your point, regardless of if it was 7 or 5, I would at least expect 4 results. –  Filype Feb 27 '12 at 21:04
Is it possible that the field on which you're searching is not tokenized? –  David Faber Feb 28 '12 at 2:54
My admin screen says it is a field Type TEXT_EN –  Filype Feb 28 '12 at 3:06
Maybe try a more flexible type like "text"? Sorry, I wish I could be more help. –  David Faber Feb 28 '12 at 3:18
add comment

Your Answer


