I have a set of documents that all have a "timestamp" field which is stored as 
a long integer number. The field is indexed in my Lucene index as a number 
using NumericField with a precision step of 8: 

   Field field = new NumericField("timestamp", 8); 
   field.setLongValue( timestampValue); 

I do this so I can do numeric range queries to retrieve all documents that fall 
within a specific time range. 

The query I construct has two parts to it, a query, and a filter. I get the 
document hits as follows: 

   IndexReader reader = ...... some index reader..... 
   IndexSearcher searcher = new IndexSearcher(reader); 

   Filter filter = NumericRangeFilter.newLongRange("timestamp", 8, startTime, 
endTime, false, true); 
   Query query = new MatchAllDocsQuery(); 
   searcher.search( query, filter, myCollector); // My collector is a super 
class of Collector - saves all Hits 

Occasionally, I have a single document with a very specific timestamp I want to 
retrieve. Suppose that timestamp is timeX, I will create the filter as follows: 

   Filter filter = NumericRangeFilter.newLongRange("timestamp", 8, timeX-1, 
timeX, false, true); 

But with this filter, the document that should be found is never found. I have 
even tried expanding the time range as follows, but with no success: 

   Filter filter = NumericRangeFilter.newLongRange("timestamp", 8, timeX-1, 
timeX+500, false, true); 

Strangely, a filter that should NOT have found the document actually did find 
the document: 

   Filter filter = NumericRangeFilter.newLongRange("timestamp", 8, timeX, 
timeX+1000, false, true); 

This filter should NOT have found the document since the minInclusive argument 
is false. 

I have also noticed that sometimes when I have several documents with exactly 
the same timestamp, a query will return some, but not all, of the documents. 

I have also tried to use a NumericRangeQuery as follows: 

   Query query = NumericRangeQuery.newLongRange("timestamp", 8, timeX-1, timeX, 
false, true); 
   searcher.search( query, null, myCollector); 

This also fails to return my document(s). 

Am I doing something wrong here? Have I misunderstood how this is supposed to 
work? Has anyone else had problems like this? 


Thanks for any help or guidance or tips you can give me, 

-Daniel Sanders

Reply via email to