请原谅我,但我是 Lucene 的新手。
我已将包含多个字段的文档添加到我的索引中
Document doc = new Document();
doc.add(new TextField("productName", productName, Field.Store.YES));
doc.add(new FloatField("price", Float.parseFloat(price), Field.Store.YES));
//+additional fields
我想搜索产品并过滤到价格范围。有人能告诉我如何对这些结果应用过滤器吗?
String[] queryStrings = {searchTerm};
String[] fields = {"itemName"}; //might query multiple fields in future
try {
Query q = MultiFieldQueryParser.parse(luceneVersion, queryStrings, fields, analyzer); // assuming I might want to search additional fields like description in the future
IndexReader reader = DirectoryReader.open(indexDirectory);
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs td = searcher.search(q, to);
// Not sure how to filter here, I eventually will want to save these results for pagination
} catch (Exception e){
e.printStackTrace();
}