我正在尝试优化我的 SOLR 实例中的突出显示,因为这似乎会使查询速度降低 2 个数量级。我有一个标记化的字段索引并存储有以下定义:
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.PatternReplaceCharFilterFactory" pattern="\+" replacement="%2B"/>
<tokenizer class="solr.UAX29URLEmailTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_en.txt" enablePositionIncrements="true" />
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<charFilter class="solr.PatternReplaceCharFilterFactory" pattern="\+" replacement="%2B"/>
<tokenizer class="solr.UAX29URLEmailTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_en.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
还生成了术语向量等:
<field name="Events" type="text_general" multiValued="true" stored="true" indexed="true" termVectors="true" termPositions="true" termOffsets="true"/>
对于高亮组件,我使用默认的 SOLR 配置。我尝试的查询使用 FastVectorHighlighter 但仍然需要 ~1500ms,这对于 ~1000 个文档来说太长了,每个文档的字段中存储了 10-20 个值。这是查询:
q=Events:http\://mydomain.com/resource/term/906&fq=(Document_Code:[*+TO+*])&hl.requireFieldMatch=true&facet=true&hl.simple.pre=<b>&hl.fl=*&hl=true&rows=10&version=2&fl=uri,Document_Type,Document_Title,Modification_Date,Study&hl.snippets=1&hl.useFastVectorHighlighter=true
令我感到好奇的是,在 solr 管理统计中,单个查询会生成 9146 个对 HtmlFormatter 和 GapFragmenter 的请求。关于为什么会发生这种情况以及如何改进荧光笔的性能有什么想法吗?
最佳答案
问题似乎是由“hl.fl=*”引起的,它导致 DefaultSolrHighlighter 为找到的每个文档(在我的例子中最多 10 个)迭代相对大量的字段(在我的索引中)。这会导致额外的 O(n^2) 时间。这是相关的代码片段:
for (int i = 0; i < docs.size(); i++) {
int docId = iterator.nextDoc();
Document doc = searcher.doc(docId, fset);
NamedList docSummaries = new SimpleOrderedMap();
for (String fieldName : fieldNames) {
fieldName = fieldName.trim();
if( useFastVectorHighlighter( params, schema, fieldName ) )
doHighlightingByFastVectorHighlighter( fvh, fieldQuery, req, docSummaries, docId, doc, fieldName );
else
doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName );
}
String printId = schema.printableUniqueKey(doc);
fragments.add(printId == null ? null : printId, docSummaries);
}
减少字段数量应该会大大改善行为。但是,在我的例子中,我无法将它减少到 20 个字段以下,因此我将检查是否为所有字段启用 FastVectorHighlighter 会提高整体性能。
我还想知道我们是否可以通过使用匹配文档(此时已经可用)中的一些信息来进一步减少此列表。
更新
对所有字段使用 FastVectorHighlighter(将所有标记化字段的 termVectors、termPositions 和 termOffsets 设置为 true)确实确实将突出显示速度提高了一个数量级,因此现在所有查询的运行时间都小于 1 秒。索引的大小增加了原来的 3 倍(从 500M 到 2G)。多值字段的分片如何生成也存在问题,但性能提升足够高。
关于performance - 优化 SOLR 荧光笔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774508/