1
或者我誤解了這個類的用法。看看下面的代碼...(這是Scala,但它應該是容易把握的想法)`FieldValueQuery`是越野車
import org.apache.lucene.store._
import org.apache.lucene.document._
import org.apache.lucene.index._
import org.apache.lucene.analysis.core._
import org.apache.lucene.search._
val directory = new RAMDirectory()
val config = new IndexWriterConfig(new WhitespaceAnalyzer())
val writer = new IndexWriter(directory, config)
writer.addDocument({
val document = new Document()
document.add(new StringField("foo", "bar", Field.Store.YES))
document
})
writer.commit()
val searcher = new IndexSearcher(DirectoryReader.open(directory))
{
val query = new ConstantScoreQuery(new FieldValueQuery("foo"))
Console.println(searcher.search(query, 1).totalHits)
}
{
val query = new TermQuery(new Term("foo", "bar"))
Console.println(searcher.search(query, 1).totalHits)
}
輸出,
[info] 0
[info] 1
它是一個錯誤或我失蹤什麼? (我正在使用Lucene 5.4.1)
謝謝!如果我只想搜索具有特定領域的文檔,該怎麼辦?在5之前,我使用了'FieldValueFilter',它像一個魅力。現在在5它已被棄用,我想知道應該用什麼來代替? – Sheng