Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lucene `FieldValueQuery'有问题_Lucene - Fatal编程技术网

Lucene `FieldValueQuery'有问题

Lucene `FieldValueQuery'有问题,lucene,Lucene,或者我误解了这个类的用法。查看下面的代码。。。(这是Scala版本,但应该很容易理解) import org.apache.lucene.store_ 导入org.apache.lucene.document_ 导入org.apache.lucene.index_ 导入org.apache.lucene.analysis.core_ 导入org.apache.lucene.search_ val directory=new RAMDirectory() val config=new IndexW

或者我误解了这个类的用法。查看下面的代码。。。(这是Scala版本,但应该很容易理解)

import org.apache.lucene.store_
导入org.apache.lucene.document_
导入org.apache.lucene.index_
导入org.apache.lucene.analysis.core_
导入org.apache.lucene.search_
val directory=new RAMDirectory()
val config=new IndexWriterConfig(new WhitespaceAnalyzer())
val writer=new IndexWriter(目录,配置)
writer.addDocument({
val文档=新文档()
添加(新的StringField(“foo”,“bar”,Field.Store.YES))
文件
})
writer.commit()
val searcher=newindexsearcher(DirectoryReader.open(directory))
{
val查询=新ConstantCoreQuery(新字段值查询(“foo”))
Console.println(searcher.search(query,1).totalHits)
}
{
val查询=新术语查询(新术语(“foo”、“bar”))
Console.println(searcher.search(query,1).totalHits)
}
输出是,

[info] 0
[info] 1

是虫子还是我遗漏了什么?(我使用的是Lucene 5.4.1)

FieldValueQuery
检查该字段是否有
DocValue
,而不是传统的索引/存储字段内容。如果将DocValuesField添加到文档中,您应该会看到它获取查询结果,例如:

val document=新文档()
添加(新的StringField(“foo”,“bar”,Field.Store.YES))
文件。添加(新字段(“foo”,新的BytesRef(“bar”))
文件

查看,了解DocValues的全部内容。

谢谢!如果我只想搜索具有特定字段的文档,该怎么办?在5之前,我使用的是
FieldValueFilter
,它工作起来很有魅力。现在在5中它被弃用了,我想知道应该使用什么来代替它?