两个 Q 蒙特
解决方案优点:
- 注释与源文档逻辑存储
- 不需要荧光笔实现或自定义 Java 荧光笔开发知识
- 由于所有自定义都发生在 Solr 之外,因此该解决方案应该向前兼容未来的 Solr 版本。
解决方案缺点:
- 需要运行两个查询
- 需要您的搜索客户端中的代码才能将一个查询的结果合并到另一个查询中。
使用 Solr 4.8+,您可以在每个主文档(文本)下面嵌套子文档(注释)...
curl http://localhost:8983/solr/update/json?softCommit=true -H 'Content-type:application/json' -d '
[
{
"id": "123",
"text" : "Bill studied The Bill of Rights last summer.",
"content_type": "source",
"_childDocuments_": [
{
"id": "123-1",
"content_type": "source_annotation",
"annotation": "William Brown",
"start_offset": 0,
"end_offset": 4
},
{
"id": "123-2",
"content_type": "source_annotation",
"annotation": "legal term",
"start_offset": 13,
"end_offset": 31
},
{
"id": "123-3",
"content_type": "source_annotation",
"annotation": "summer 2011",
"start_offset": 32,
"end_offset": 43
}
]
}
]
...使用块连接查询注解。
1)注解查询:http://localhost:8983/solr/query?fl=id,start_offset,end_offset&q={!child of=content_type:source}annotation:"William Brown"
"response":{"numFound":1,"start":0,
"docs":[
{
"id": "123-1",
"content_type": "source_annotation",
"annotation": "William Brown",
"start_offset": 0,
"end_offset": 4
}
]
}
将这些结果存储在您的代码中,以便您可以在下一个查询返回后折叠注释偏移量。
2)来源查询+高亮:http://localhost:8983/solr/query?hl=true&hl.fl=text&fq=content_type:source&q=text:"William Brown" OR id:123
(在 Annotation Query 中发现的 id:123 被 ORed 到第二个查询中)
"response":{"numFound":1,"start":0,
"docs":[
{
"id": "123",
"content_type": "source",
"text": "Bill studied The Bill of Rights last summer."
}
],
"highlighting":{}
}
注意:在此示例中,没有返回突出显示信息,因为搜索词与任何 content_type:source 文档都不匹配。但是,我们有来自第一个查询的显式注释和偏移量!
然后,您的客户端代码需要从第一个查询中获取 content_type:source_annotation 结果,并手动将突出显示标记插入第二个查询的 content_type:source 结果中。
更多关于Yonik's blog here的区块加入信息。