Hi,
I am new to lucene library. I need to write some numeric field in the doc
using indexwriter and using index searcher i need to search if the value
range (age > 40) as example.
IndexWriter Snippet below. The value is available in the doc properly.
(Document<indexed,tokenized,omitNorms,omitTermFreqAndPositions<title:40>>)
Document doc = new Document();
NumericField numericField = new NumericField("title",
Integer.parseInt(value));
numericField.setIntValue(Integer.parseInt(value));
doc.add(numericField);
iw.addDocument(doc);
iw.optimize();
iw.close();
indexSearcher snippet below. IndexSearcher prints the hits length correctly.
Having said the result is not getting printed from the doc. Any help ? I
spend so much time and failed to find.
Query queryParser = NumericRangeQuery.newIntRange("title", 40, 6000, true,
true);
// 3. Search
int hitsPerPage = 10;
IndexSearcher indexSearcher = new IndexSearcher(index, true);
TopScoreDocCollector collector = TopScoreDocCollector.create(
hitsPerPage, true);
indexSearcher.search(queryParser, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
// 4. Display result
log.info("List of docs found : " + hits.length);
for (int i = 0; i < hits.length; i++) {
int docId = hits[i].doc;
System.out.println(docId);
Document doc = indexSearcher.doc(docId);
log.info(i + 1 + " . " + doc.get("title"));
}
--
View this message in context:
http://lucene.472066.n3.nabble.com/indexSearcher-using-NumericRangeQuery-doesn-t-gives-result-Any-help-tp3569338p3569338.html
Sent from the Lucene - General mailing list archive at Nabble.com.