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:

http://wiki.apache.org/solr/SolrQuerySyntax

http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Range 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