lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andi rexha <a_re...@hotmail.com>
Subject Integer Range Query in Lucene 4.10.4 not working as expected.
Date Fri, 30 Jun 2017 12:05:58 GMT
I have a numeric range query to perform in an index. I begin by indexing a document with a
field value of "300". When I search for a range [100 TO 400] I get results from the search
operation. Strangely enough, when I search for [100 TO 4000], I don't get any search results.


Here is a code snippet for the test I perform:


public static void main(String[] args) throws IOException {

String fileName = args[0];

File file = new File(fileName);

FSDirectory directory = FSDirectory.open(file);

IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_4_9_1, new WhitespaceAnalyzer());

IndexWriter indexWriter = new IndexWriter(directory, conf);

indexWriter.deleteAll();

indexWriter.commit();

//creating document

Document doc = new Document();

FieldType fieldType = new FieldType();

fieldType.setIndexed(true);

fieldType.setNumericType(NumericType.INT);

IntField intField = new IntField("field1", 300, fieldType);

doc.add(intField);

indexWriter.addDocument(doc);

indexWriter.commit();

indexWriter.close();

DirectoryReader directoryReader = DirectoryReader.open(directory);

IndexSearcher indexSearcher = new IndexSearcher(directoryReader);

//searching for numbers >= 100 and <= 400

Query rangeQueryWorking = NumericRangeQuery.newIntRange("field1", 100, 400, true, true);

TopDocs resultsWorking = indexSearcher.search(rangeQueryWorking, 10);

//searching for numbers >= 100 and <= 4000

Query rangeQueryNotWorking = NumericRangeQuery.newIntRange("field1", 100, 4000, true, true);

TopDocs resultsNotWorking = indexSearcher.search(rangeQueryNotWorking, 10);

//returns 1 as expected

System.out.println(resultsWorking.totalHits);

//returns 0 but expected 1

System.out.println(resultsNotWorking.totalHits);

}



Can someone help me with this issue?


Thank you in advance!


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message