Hi
I'm trying to submit a lucene query string to my index to return a data
based on a numeric range. I'm using the syntax provided in the Query
Parser Syntax document but the results I get indicate that the query is not
working correctly. Below is a unit test that proves that the range query
does not work, at least in this configuration.
@Test
public void test_lucene_numeric_range_query() throws IOException,
ParseException {
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_44,
analyzer);
Directory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, config);
Field longField1 = new LongField("longField1", 0L, Field.Store.YES);
Field longField2 = new LongField("longField2", 0L, Field.Store.YES);
for (long i = 1; i < 101; i++)
{
Document doc = new Document();
longField1.setLongValue(i);
longField2.setLongValue(i);
doc.add(longField1);
doc.add(longField2);
writer.addDocument(doc);
}
writer.commit();
IndexReader reader = DirectoryReader.open(writer, false);
IndexSearcher searcher = new IndexSearcher(reader);
Query query = new QueryParser(Version.LUCENE_44, "",
analyzer).parse("longField1:[51 TO 75]");
TopDocs docs = searcher.search(query, 100);
Assert.assertEquals(docs.totalHits, 25);
}
Is there something wrong with the query I'm submitting, or the way I'm
setting up the searcher, or something else? Or does submitting a query in
this way for a numeric field not work?
Thanks in advance,
Matt