Lucene query language and numeric range - lucene

I'm applying the following Lucene query predicate in order to get all inclusive numbers in 2 to 6 range:
value:[2 TO 6]
and receive the documents with the following values:
567986400000
567986400000
567986400000
536450400000
536450400000
599608800000
536450400000
567986400000
I'm interested in the numeric range query and obviously, for example, the Long value 567986400000 is not in the range of [2 TO 6]. Looks like the range searches are strings and I don't know how to workaround it in mine application for the different numeric values.
How to properly use numeric range queries in Lucene?

To achieve a proper range query you need to use specific defined fields from lucene. See Field javadoc
IntPoint: int indexed for exact/range queries.
LongPoint: long indexed for exact/range queries.
FloatPoint: float indexed for exact/range queries.
DoublePoint: double indexed for exact/range queries.
So you need to be sure that your field you add this query is one of this types. As you said you use a Neo4j generated lucene index. There has to be an option to create this kind of fields otherwise you're not able to execute proper range queries.

Related

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?
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

RavenDB range querying documents by number field

I want to filter my documents in database through RavenDB Studio using range search in simple query by numeric field.
MyNumericCount:[100 TO 200]
Instead of correct result I receive set of documents with various values of my field.
Why does it happen? How to properly query RavenDB.
Thank you in advance.
You are querying on a numeric field, but you are looking at the textual representation.
You need to query using:
MyNumericCount_Range:[Ix100 TO Ix200]
The Ix prefix is for ints, Dx for double, Lx for longs, etc.

Alphanumeric range query

Is there an effective way to handle alphanumeric ranges in lucene?
Example ranges,
1 to 1 (includes 1A, 1B.. 1Z)
10A12 to 10A22 (includes 10A12, 10A13.. 120A22)
1 to 10 (includes 1A,1B..,2A,2B..,9Z,10) [Does not include 10A]
I have two approaches:
Expand each range and index all possible values. I guess the unique values won't be huge.
Index on low and high values. Then use range query. Not sure, how effective is range query on alphanumeric ranges
Need expert advice on this, please.
I hope you agree that your defined rules are very customary and not really suitable for a generic framework, such as Lucene. For example, why would range [1..1] include letters but [1..10] wouldn't?
I don't know if it is possible with your data set, but if you could come up with rules, converting each element (including element having letters) into a unique number using some arbitrary formula, you could use this formula both when indexing and querying. This would even allow range matching.

hibernate query builder for lucene time range

I am building a lucene query for an indexed object to determine if current time lies between the range of start Time and end Time. I'm unable to get the exact lucene query .
org.apache.lucene.search.Query luceneQuery5=queryBuilder3.bool()
.must(queryBuilder3.keyword().onFields("TimeDependentProfileKey").matching("TimeKey").createQuery())
.must(queryBuilder3.range().onField("StartTime").above(new Time(0)).createQuery())
.must(queryBuilder3.range().onField("StopTime").below(new Time(0)).createQuery()).createQuery();`
The lucene query which was generated looks like:
+TimeDependentProfileKey:3 +StartTime:[19700101000000000 TO *] +StopTime:[* TO 19700101000000000]
how do i change the format of timestamp, can anyone please help me.
By searching for a date object, you are deferring formatting to hibernate. I would consider the format you specified as functional, though perhaps not ideal. If you want to use your own formatting, you must deal in strings, be consistent in your formatting, and make sure your format will work well for sorting and range queries as a string.
If you want to have hibernate handle formatting dates for you, you need to define your date field with a #DateBridge(resolution = ...) annotation. This ensures that hibernate will format dates effective for correct range querying and sorting in lucene, and allows you to query against the field with date objects instead of strings.

Lucene.net 2.9.4 SimpleFacetedSearch with numeric range on NumericField

I put some fields like manufacturer, group, description, num.
SimpleFaceted works ok if I use query like sometext* with QueryParser.
Im trying to use num:[100 TO 200],
num is NumericField with SetIntValue(150).
I got nothing returned.
Am I missing something?
You can't use a normal query parser for numeric range queries. However, assuming you know at query time which fields are numeric, it isn't too hard to derive a class from the Lucene query parser and create numeric range queries as necessary.
Support for numeric queries in the standard query parser looks like it should be available in Lucene.Net when a port of v3.4 is available. (See Java Lucene issue 1768)
Good luck,