优化SOLR荧光笔
问题描述:
我试图在我的SOLR实例中优化突出显示,因为这似乎使查询速度减慢了2个数量级。我有一个标记化字段索引和存储的,定义如下:优化SOLR荧光笔
<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,对于每个文档中存储10-20个值的〜1000个文档非常长。下面是该查询:
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到真正所有记号化字段)由一个数量级确实提高了高亮的速度,所以现在所有查询都运行< 1秒。该指数的规模增加了其原始值的3倍(从500M到2G)。多值场的碎片如何产生也存在问题,但性能的改善足够高。
我使用在Tomcat 7.0.28上运行的Solr 3.6 – kpentchev 2012-08-02 09:22:42
在未启用termVectors的类似字段上运行相同的查询,显示响应时间没有显着差异。 – kpentchev 2012-08-02 10:50:01