Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Incorrect Range Search Query Example in Solr Documentation
Read original blog post

UserPost

8:55 pm
January 29, 2009


admin

Admin

posts 17

1

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 <field>:[<from> to <to>].  However, this syntax is incorrect (at least for Solr 1.3).  The correct syntax should be <field>:[<from> <to>].  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”.

Read original blog post

3:39 pm
February 1, 2009


mojo

Member

posts 6

2

This is a good tips.  I haven't used range query myself yet but this sure come in handy.

Search 

About the MySolr forum

Most Users Ever Online:

9


Currently Online:

2 Guests

Forum Stats:

Groups: 2

Forums: 2

Topics: 9

Posts: 22

Membership:

There are 8 Members

There has been 1 Guest

There is 1 Admin

There is 1 Moderator

Top Posters:

mojo – 6

sturlese – 6

fudge – 1

blah – 1

egrobler – 1

phat – 0

Administrators: admin (17 Posts)

Moderators: mysolr (0 Posts)