lucenerange-query

Lucene String and Numeric range queries


I'm just curious why Lucene doesn't distinguish string and numeric values in a standard way.. for example ['2' TO '6'] and [2 TO 6] for range queries and treat all of them by default as String.

Is there any particular reason to treat both of these cases as the string values?


Solution

  • Your range query example is based on lucene query syntax. In this definition it's not defined in what kind of field type you execute this query.

    Basically if you apply this query to a TextField the evaluation will be based on String. If you apply this to a IntPoint the number will be interpreted as integer. Responsible for this is the QueryParser in which you add your query and your field you like to search.

    In your case using an IntPoint would make sense because you want to search for an numeric range.

    More details about the query parser see QueryParser Javadoc