背景
使用Solr 4.0.0.我已将一组示例文档的文本编入索引并启用了术语向量,因此我可以使用快速向量突出显示
<field name="raw_text" type="text_en" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />
Run Code Online (Sandbox Code Playgroud)
为突出显示我正在使用具有SENTENCE边界的Break Iterator边界扫描器.
<boundaryScanner name="breakIterator" class="solr.highlight.BreakIteratorBoundaryScanner">
<lst name="defaults">
<!-- type should be one of CHARACTER, WORD(default), LINE and SENTENCE -->
<str name="hl.bs.type">SENTENCE</str>
</lst>
</boundaryScanner>
Run Code Online (Sandbox Code Playgroud)
我做了一个简单的查询
http://localhost:8983/solr/documents/select?q=raw_text%3AArtibonite&wt=xml&hl=true&hl.fl=raw_text&hl.useFastVectorHighlighter=true&hl.snippets=100&hl.boundaryScanner=breakIterator
Run Code Online (Sandbox Code Playgroud)
突出显示工作得相当好
<response>
...
<result name="response" numFound="5" start="0">
<doc>
<str name="id">-1071691270</str>
<str name="raw_text">
Final Report of the Independent Panel of Experts on the Cholera
Outbreak in Haiti Dr. Alejando Cravioto (Chair) International
Center for Diarrhoeal Disease Research, Dhaka, Bangladesh Dr.
Claudio F. Lanata Instituto de Investigación Nutricional, and
The US Navy Medical Research Unit 6, Lima, Peru Engr. Daniele
S. Lantagne Harvard University... ~SNIP~
</str>
<doc>
<lst name="highlighting">
<lst name="-1071691270">
<arr name="raw_text">
...
<str>
The timeline suggests that the outbreak spread along
the <em>Artibonite</em> River. After establishing that
the cases began in the upper reaches of the Artibonite
River, potential sources of contamination that could have
initiated the outbreak were investigated.
</str>
...
</arr>
</lst>
</lst>
Run Code Online (Sandbox Code Playgroud)
问题
我希望能够发送生成的句子以进行进一步处理(实体提取等),但我想跟踪原始(长)文本字段中突出显示的句子的开始/结束偏移.有直接的方法吗?
将hl.fragsize设置为返回整个字段然后以这种方式处理/提取感兴趣的句子会更好吗?
小智 5
除了进行某种定制之外,无法通过突出显示结果返回片段的偏移信息。
您似乎有几个选择:
1) 您可以通过创建将偏移信息编码到字符串中的自定义格式化程序来扩展 Solr 荧光笔。TokenGroup传递到格式化程序的每个术语将具有存储在其中的偏移量和位置信息。如果您的格式化程序返回 a<span data-offset=X>text</span>或类似的内容,那么这将是一种方式。这似乎不是最直接的。
2)正如你所说,使用返回整个字段hl.fragsize=0。
3)在附加请求中使用TermVectorsComponent并将其返回的偏移/位置信息与突出显示的片段进行映射。
如果您无论如何都要做自己的碎片,那么对您来说最好的解决方案可能是在 Solr 中进行 0 碎片并自己处理所有事情。或者,您可以在 Java 中实现您自己的BoundaryScanner实现,以在分解片段时使用您自己的实体提取专业知识。
| 归档时间: |
|
| 查看次数: |
2185 次 |
| 最近记录: |