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



Welcome

16 01 2009

My name is Ed Ng.  I’m a software engineer with a decade of experience building software from client-server/desktop application to web based implementation.  I have a lot of experience in search technology includingSolr/Lucene, Endeca and Ultraseek.  I saw a lot changes in the IT scene in the past 10 years.  ERP, CRM and  E-Commerce used to be hot until the .com bombs.  Now, search is hot with Google leading the way.  However, Google is not the answer to everything when it comes to enterprise search.  Many retail companies and manufacturers have rigid requirements on search technology.  They can not live with an inflexible search engine that only focus on handling unstructured text.  They need control over how search is done.  Flexibility and customization is key to these companies.  There are quite a few vendors out there who provide solutions to them.  Some came and go (EasyAsk, FAST..etc) and some stay strong (Endeca).  Commercial solution is great but they can be very expensive at the same time.  Smaller company may not have the budget to purchase such solution.  Good news is, there is Solr.  Solr is an open source Apache project that’s built on top of Lucene.  Lucene is the underlying technology that provides search.  Solr is a wrapper that provides all the administrative tools and extra functionalities such as faceted search.  In this blog, I will write about search technology in general and development tips in Solr/Lucene.