Slav Boleslawski created LUCENE-6252: ----------------------------------------
Summary: Numeric range search does not find all expected results Key: LUCENE-6252 URL: https://issues.apache.org/jira/browse/LUCENE-6252 Project: Lucene - Core Issue Type: Bug Components: core/search Affects Versions: 4.10.2 Environment: Windows 7, Java 1.7.0_55 Reporter: Slav Boleslawski Hi Lucene Team, The below code creates an index with three documents, each document has one BirthDate field. Searching does not return expected results. Regards Slav import java.io.File; import java.io.IOException; import java.util.Date; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.LongField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.NumericRangeQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; public class LuceneTest { private static final java.text.SimpleDateFormat DATE_PARSER = new java.text.SimpleDateFormat("yyyy/MM/dd"); private static final String INDEX_PATH = "/tmp/lucene"; private static Date parseDate(String dateSt) { synchronized(DATE_PARSER) { try { return DATE_PARSER.parse(dateSt); } catch (java.text.ParseException e) { throw new IllegalArgumentException(e); } } } public static void main(String[] args) { //Create an index try { Directory dir = FSDirectory.open(new File(INDEX_PATH)); Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_2, analyzer); iwc.setOpenMode(OpenMode.CREATE); IndexWriter writer = new IndexWriter(dir, iwc); Document doc = new Document(); doc.add(new LongField("BirthDate", parseDate("1989/11/01").getTime(), Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LongField("BirthDate", parseDate("1973/03/02").getTime(), Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LongField("BirthDate", parseDate("1969/01/31").getTime(), Field.Store.YES)); writer.addDocument(doc); writer.close(); //Now do searching IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(INDEX_PATH))); IndexSearcher searcher = new IndexSearcher(reader); Query query = NumericRangeQuery.newLongRange("BirthDate", 4, parseDate("1969/01/30").getTime(), parseDate("1973/03/03").getTime(), true, true); TopDocs results = searcher.search(query, null, 100); ScoreDoc[] scoreDocs = results.scoreDocs; int hits = scoreDocs.length; int count = results.totalHits; for(int i = 0; i < hits; i++) { doc = searcher.doc(scoreDocs[i].doc); String value = doc.get("BirthDate"); System.out.println(new Date(Long.parseLong(value))); } } catch (Exception e) { e.printStackTrace(); } } } -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org