优化SOLR荧光笔

时间:2012-08-02 09:20:27

标签: performance optimization solr highlight highlighting

我正在尝试优化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,这对于~000个文档非常长,每个文档在字段中存储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管理统计信息中,单个查询会向HtmlFormatter和GapFragmenter生成9146个请求。有关为什么会发生这种情况以及如何改善荧光笔性能的任何想法?

1 个答案:

答案 0 :(得分:4)

问题似乎是由“hl.fl = *”引起的,这导致DefaultSolrHighlighter为找到的每个文档(在我的索引中)迭代相对大量的字段(在我的情况下为10 max)。这导致额外的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 ,用于所有标记化字段)确实确实将突出显示速度提高了一个数量级,因此现在所有查询都运行&lt; 1秒。指数的大小增加了原始值的3倍(从500M到2G)。如何生成多值字段的片段也存在问题,但性能的提高足够高。