在lucene中非常缓慢的突出表现

ste*_*eve 9 java lucene performance highlight

当搜索频繁的术语时,Lucene(4.6)荧光笔的性能非常慢.搜索速度很快(100毫秒),但突出显示可能需要一个多小时(!).

细节:使用了很棒的文本语料库(1.5GB纯文本).性能不依赖于文本是否被分成更小的部分.(也测试了500MB和5MB的部分.)存储位置和偏移.如果搜索非常频繁的术语或模式,TopDocs被快速检索(100ms),但每个"searcher.doc(id)"调用都很昂贵(5-50s),而getBestFragments()非常昂贵(超过1小时) .即使它们也是为此目的而存储和索引的.(硬件:核心i7,8GM内存)

更大的背景:它将用于语言分析研究.使用了一种特殊的词干:它也存储了词性信息.例如,如果搜索"adj adj adj adj noun",它将在文本中出现所有出现的上下文.

我可以调整其性能,还是应该选择其他工具?

二手代码:

            //indexing
            FieldType offsetsType = new FieldType(TextField.TYPE_STORED);
            offsetsType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);

            offsetsType.setStored(true);
            offsetsType.setIndexed(true);
            offsetsType.setStoreTermVectors(true);
            offsetsType.setStoreTermVectorOffsets(true);
            offsetsType.setStoreTermVectorPositions(true);
            offsetsType.setStoreTermVectorPayloads(true);


            doc.add(new Field("content", fileContent, offsetsType));


            //quering
            TopDocs results = searcher.search(query, limitStart+limit);

            int endPos = Math.min(results.scoreDocs.length, limitStart+limit);
            int startPos = Math.min(results.scoreDocs.length, limitStart);

            for (int i = startPos; i < endPos; i++) {
                int id = results.scoreDocs[i].doc;

                // bottleneck #1 (5-50s):
                Document doc = searcher.doc(id);

                FastVectorHighlighter h = new FastVectorHighlighter();

                // bottleneck #2 (more than 1 hour):   
                String[] hs = h.getBestFragments(h.getFieldQuery(query), m, id, "content", contextSize, 10000);
Run Code Online (Sandbox Code Playgroud)

相关(未答复)问题:https://stackoverflow.com/questions/19416804/very-slow-solr-performance-when-highlighting

AR1*_*AR1 4

BestFragments 依赖于您正在使用的分析器完成的标记化。如果你必须分析这么大的文本,你最好WITH_POSITIONS_OFFSETS在索引时存储术语向量。

请阅读本书 和这本书

通过这样做,您不需要在运行时分析所有文本,因为您可以选择一种方法来重用现有的术语向量,这将减少突出显示时间。