gpt4 book ai didi

java - Lucene:FastVectorHighlighter 返回 null

转载 作者:行者123 更新时间:2023-11-30 07:00:14 26 4
gpt4 key购买 nike

这就是我所做的:

String textField1 = fastVectorHighlighter.getBestFragment(fastVectorHighlighter.getFieldQuery(query), indexReader, docId, SearchItem.FIELD_TEXT_FIELD1, DEFAULT_FRAGMENT_LENGTH);

这是查询:

((FIELD_TEXT_FIELD1:十五*)^4.0) (FIELD_TEXT_FIELD3:十五*)

原文是正确的(indexReader.document(docId).get(SearchItem.FIELD_TEXT_FIELD3)是正确的。),并且肯定包含query中的字符。

这是我索引 textField1 的方法:

Field textField1 = new TextField(SearchItem.FIELD_TEXT_FIELD1, "", Field.Store.YES);

最佳答案

问题解决了!

事实证明,我需要改变

fastVectorHighlighter.getFieldQuery(query)

fastVectorHighlighter.getFieldQuery(query, indexReader)

顺着代码进入FieldQuery#flatten,我们会发现Lucene并没有按照正常的方式处理PrefixQuery:

} else if (sourceQuery instanceof CustomScoreQuery) {
final Query q = ((CustomScoreQuery) sourceQuery).getSubQuery();
if (q != null) {
flatten( applyParentBoost( q, sourceQuery ), reader, flatQueries);
}
} else if (reader != null) { // <<====== Here it is!
Query query = sourceQuery;
if (sourceQuery instanceof MultiTermQuery) {
MultiTermQuery copy = (MultiTermQuery) sourceQuery.clone();
copy.setRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(MAX_MTQ_TERMS));
query = copy;
}
Query rewritten = query.rewrite(reader);
if (rewritten != query) {
// only rewrite once and then flatten again - the rewritten query could have a speacial treatment
// if this method is overwritten in a subclass.
flatten(rewritten, reader, flatQueries);

}

我们可以看到它需要一个 IndexReader 用于 PrefixQueryFuzzyQuery 等。

关于java - Lucene:FastVectorHighlighter 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41052864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com