1

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?

3
  • What is a 'standard' way? Commented Jun 1, 2018 at 6:56
  • quotes around the string value Commented Jun 1, 2018 at 6:57
  • You could always implement your own query parser.. But it also depends on how your the field is indexed. If you have a text/string field; you will never be able to use numeric search. Commented Jun 1, 2018 at 9:53

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

12 Comments

I understand this. I don't understand why do not use for example TermRangeQuery.NumericRangeFilter in case of non-quoted values(like [2 TO 6]) in the range queries and textual range queries in case of quoted values like ['2' TO '6']?
whats the idea? you like to see immediately if it's a string or numberic range if you see the query syntax?
yes, I'd like to see the Lucene Query parser to be smart enough to be able to distinguish string literals(based on the quotes) and others. This is a huge blocker to me right now in order to port my Neo4j applications to use Lucene index instead of non-indexed properties on relationships.
afaik this is not possible with lucene query syntax (didn't had may use cases like this to be honest). so you tried with string literals and it's not going to work?
yeah :( unfortunately, I ran into the following issue stackoverflow.com/questions/50545551/… and don't see any solutions how it can be solved
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.