使用solr6、python3和pys突出显示每个匹配项

2024-09-30 04:37:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Solr索引,它包含大量相当长的文本文件,用text_sv模式编制索引。我想打印出每个索引文档的每个片段。但是,我只检索到几个,即使我已经尝试过按照documentation中指定的各种设置来操纵它们。在

以下是代码部分:

results = solr.search(search_string, rows = result_limit, sort = order,
            **{
                'hl':'true',
                'hl.fragsize': 100,
                'hl.fl': 'fulltext',
                'hl.maxAnalyzedChars': -1,
                'hl.snippets': 100,
                })
resultcounter = 0
for result in results:
    resultcounter += 1
    fulltexturl = '<a href="http://localhost/source/\
    ' + result['filename'] + '">' + result['filename'][:-4] + '</a>'
    year = str(result['year'])
    number = str(result['number'])
    highlights = results.highlighting
    print("Saw {0} result(s).".format(len(results)))
    print('<p>' + str(resultcounter) + '. <b>År:</b> ' + year + ', <b>Nummer\
            : </b>' + number +' ,<b>Fulltext:</b> ' + fulltexturl + '. <b>\
            </b> träffar.<br></p>')
    inSOUresults = 1
    for idnumber, h in highlights.items():
        for key, value in h.items():
            for v in value:
                print('<p>' + str(inSOUresults) + ". " +  v + "</p>")
                inSOUresults += 1

我做错什么了?在


Tags: innumberforsearchresultfilenameyearhl
1条回答
网友
1楼 · 发布于 2024-09-30 04:37:10

您可能需要hl.fragments参数(来自the Highlighting wiki page)的非常大(或0)值:

With the original Highlighter, if you have a use case where you need to highlight the complete text of a field and need to highlight every instance of the search term(s) you can set hl.fragsize to a very high value (whatever it takes to include all the text for the largest value for that field), for example &hl.fragsize=50000.

However, if you want to change fragsize to a value greater than 51200 to return long document texts with highlighting, you will need to pass the same value to hl.maxAnalyzedChars parameter too. These two parameters go hand in hand and changing just the hl.fragsize would not be sufficient for highlighting in very large fields.

相关问题 更多 >

    热门问题