Incorrect Range Search Query Example in Solr Documentation

19 01 2009

Many of you may have seen this exception when trying out Solr’s range search query based on Solr’s documentation.

HTTP Status 400 - org.apache.lucene.queryParser.ParseException:
Cannot parse 'rank:[1 to 10]': Encountered "10" at line 1, column 11.
Was expecting: "]" ...

This exception is saying that Lucene’s query parser does not recognize a third value “10” in the range filter query.  The parser only expects two values.  It’s kind of confusing because Solr’s documentation gives an example of “field:[1 to 100]”.  Interestingly, the documentation is consistent between Solr and Lucene’s documentation regarding the range search query format: Searches

As you can see, they both describe range search query’s syntax as :[ to ].  However, this syntax is incorrect (at least for Solr 1.3).  The correct syntax should be :[ ].  Notice that the keyword “to” between from and to is not needed.  For example:

  • Return results with value in field “rank” between 1 and 100
    • fq=rank:[1 100] 
  • Return results with value in field “rank” less than or equal to 10
    • fq=rank:[* 10]
  • Return results with value in field “rank” greater than or equal to 10
    • fq=rank:[10 *]
Solr’s documentation was updated on 2008-10-20 as I write this post.  Hopefully, the documentation will be corrected soon.  There is also a possibility that the “to” keyword may be supported in future versions of Solr and Lucene.  For now, omit the “to”.

Join the forum discussion on this post - (2) Posts



3 responses to “Incorrect Range Search Query Example in Solr Documentation”

29 04 2010
  dumbfounder (09:28:46) :

These range queries definitely don’t work correctly in solr 1.4.

When using the range query on an integer field, when you use [1 to 2] or [1 2] it actually seems to do a wildcard and grab everything that STARTS with a 1, or is EQUAL to 2. It is very strange, no matter how you slice it, that is wrong.

When you do [1 TO 50] or [1 50] it gets everything that starts with a 1, 2, 3, 4 or is EQUAL to 50. Makes no sense to me!!!!

To verify, I tried searching for integer years in our index that are of the form 1998, 2010, etc, and when I use [1 TO 2] or [1 2] it seems to match all of the 19xx years, and none of the 20xx years.

22 11 2010
  Aaron (14:54:41) :

Just to answer the initial problem identified in this post, the documentation says [1 TO 10] not [1 to 10] . The parser seems to be case sensitive in that regard. Found this problem the other day.

20 07 2011
  Sowmya (02:57:19) :

Don’t these examples mean – filtering a query based on a field’s range, rather than giving a rangequery itself?

Filter Query: Get all results and just filter them based on the Range of a particular field.

Range Query: The query itself includes this range issue and all documents inside this range will be considered more relevant than others, in the ranking process itself.

So, is there a facility in Solr to do that? I tried &bq=…. but I wonder if the boosting with something like… &bq=XYZ:[20 TO 25]^10 – really works!

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.