我正在使用apache lucene在我的应用程序中执行全文搜索。现在,我必须执行范围查询来搜索两个整数之间的记录。
我使用以下代码创建了索引
private void set(String fieldName, String fieldValue, Document luceneDocument, LuceneOptions options, Float boost) {
if (fieldName != null && fieldValue != null) {
Field luceneField =
new Field(fieldName,
fieldValue.toLowerCase(),
options.getStore(),
options.getIndex(),
options.getTermVector());
luceneField.setBoost(boost);
luceneDocument.add(luceneField);
}
}
上面的方法为我的字段名称"magnitude"创建了 lucene 索引,其可能的值是介于 -999 到 9999 之间的正整数和负整数。
现在,如果我创建一个 lucene 范围查询,例如 (magnitude:[10 to 345]) 或 (magnitude:[10 to null])。我没有得到正确的记录数。
你需要定义一个IntField
,让 Lucene 将这些值解释为数字。