java - Lucene - 如何查询文本和过滤数字范围

标签 java lucene

请原谅,我是 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();
}

最佳答案

您是否考虑过添加 NumericRangeQuery并将其与 BooleanQuery 中的初始查询结合起来? 您可以使用 MUST clause 将它们组合起来

关于java - Lucene - 如何查询文本和过滤数字范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19842843/

相关文章:

java - 为什么我无法将类导入 Eclipse Maven 项目中的 java 文件?

java - 使用 ImageView 显示图库

java - 如何存储来自 InputStream 的 Blob

java - 如何在 Spring 中更新 @Autowired String bean 的值?

java - Parse Int/Parse long NumberFormatException 问题

lucene - 太多字段不利于 elasticsearch 索引?

java - lucene 在服务断开之前不会调用操作

c# - 在哪里可以找到使用 lucene.net 的开源应用程序

elasticsearch - 在不同索引上组合休眠搜索查询的最佳方法

java - Solr(php 与 java): query differences when determining number of documents