【发布时间】:2015-07-15 05:57:13
【问题描述】:
问题
我在哪里可以找到一个完整的示例来展示分层分面搜索如何从索引文档到检索搜索结果?
到目前为止我的研究
Stackoverflow 有一些帖子,但它们都只涉及分层分面搜索的某些方面;因此,我不会认为它们是重复的。我正在寻找一个完整的例子来理解它。我一直错过聚合工作的最后一个查询。
- 这几乎正是我正在寻找的内容,但同样不是完整的演练:Solr Hierarchical Faceting. Example needed
Solr 网页上有文档,但不理解那里给出的示例。
示例(概念上)
我想在这里创建一个完整的演练示例,并希望您能提供缺少的最终部分。
测试数据
输入
假设我们有 3 个文档,每个文档都是一个人。
Alice (document 1)
- Blond
- Europe
Jane (document 2)
- Brown
- Europe/Norway
Bob (document 3)
- Brown
- Europe/Norway
- Europe/Sweden
输出
此(当前错误)查询的预期输出
http://server:8983/solr/my_core/select?q=*%3A*&wt=json&indent=true&facet=true&facet.field=tags_ss
应该是
Hair_color (3)
- blond (1)
- brown (1)
- black (1)
Location (3)
- Europe (4) // This should be 4 not 3, i.e. the sum of the leaves, because Alice is tagged with "Europe" only, without a country
- Norway (2)
- Sweden (1)
因为所有文档都找到了。
示例(以编程方式)
这是我需要帮助的地方。如何实现上述概念性示例?
这是我已经走了多远。
1.创建测试数据 XML
这是solr-5.1.0/testdata 子文件夹中documents.xml 文件的内容:
<add>
<doc>
<field name="id">Alice</field>
<field name="tags_ss">hair_color/blond</field>
<field name="tags_ss">location/Europe</field>
</doc>
<doc>
<field name="id">Jane</field>
<field name="tags_ss">hair_color/brown</field>
<field name="tags_ss">location/Europe/Norway</field>
</doc>
<doc>
<field name="id">Bob</field>
<field name="tags_ss">hair_color/black</field>
<field name="tags_ss">location/Europe/Norway</field>
<field name="tags_ss">location/Europe/Sweden</field>
</doc>
</add>
_ss 在schema.xml 中定义为
<dynamicField name="*_ss" type="string" indexed="true" stored="true" multiValued="true"/>
请注意,所有标签,例如hair_color 和 location 以及将来添加的任何标签都存储在同一个tags_ss 字段中。
2。用 Solr 索引测试数据
c:\solr-5.1.0>java -classpath dist/solr-core-5.1.0.jar -Dauto=yes -Dc=gettingstarted -Ddata=files -Drecursive=yes -Durl=http://server:8983/solr/my_core/update org.apache.solr.util.SimplePostTool .\testdata
3.使用 Solr 查询检索所有数据(没有分面)
查询
http://server:8983/solr/my_core/select?q=*%3A*&wt=json&indent=true
结果
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"indent": "true",
"q": "*:*",
"_": "1430830360536",
"wt": "json"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [
{
"id": "Alice",
"tags_ss": [
"hair_color/blond",
"location/europe"
],
"_version_": 1500334369469890600
},
{
"id": "Jane",
"tags_ss": [
"hair_color/brown",
"location/europe/Norway"
],
"_version_": 1500334369469890600
},
{
"id": "Bob",
"tags_ss": [
"hair_color/black",
"location/europe/Norway",
"location/europe/Sweden"
],
"_version_": 1500334369469890600
}
]
}
}
4.使用 Solr 查询检索所有数据(带有分面)
查询
http://server:8983/solr/my_core/select?q=*%3A*&wt=json&indent=true&facet=true&facet.field=tags_ss
结果
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"facet": "true",
"indent": "true",
"q": "*:*",
"_": "1430830432389",
"facet.field": "tags_ss",
"wt": "json"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [
{
"id": "Alice",
"tags_ss": [
"hair_color/blond",
"location/europe"
],
"_version_": 1500334369469890600
},
{
"id": "Jane",
"tags_ss": [
"hair_color/brown",
"location/europe/Norway"
],
"_version_": 1500334369469890600
},
{
"id": "Bob",
"tags_ss": [
"hair_color/black",
"location/europe/Norway",
"location/europe/Sweden"
],
"_version_": 1500334369469890600
}
]
},
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"tags_ss": [
"location/europe/Norway",
2,
"hair_color/black",
1,
"hair_color/blond",
1,
"hair_color/brown",
1,
"location/europe",
1,
"location/europe/Sweden",
1
]
},
"facet_dates": {},
"facet_ranges": {},
"facet_intervals": {},
"facet_heatmaps": {}
}
}
请注意结果底部的此部分:
"facet_fields": {
"tags_ss": [
"location/europe/Norway",
2,
"hair_color/black",
1,
"hair_color/blond",
1,
"hair_color/brown",
1,
"location/europe",
1,
"location/europe/Sweden",
1
]
},
它将所有标签显示为一个平面列表(不是分层的)。
5.使用 Solr 查询检索所有数据(使用分层分面)
查询
这是我的问题。我不知道如何构造返回以下结果的查询(结果已经在上面的概念示例中显示)。
结果(虚构,为说明而手工制作)
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"facet":"true",
"indent":"true",
"q":"*:*",
"facet.field":"tags_ss",
"wt":"json",
"rows":"0"}},
"response":{"numFound":3,"start":0,"docs":[]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"tags_ss":[
"hair_color,3, // This aggregations is missing
"hair_color/black",1,
"hair_color/blond",1,
"hair_color/brown",1,
"location/europe",4, // This aggregation should be 4 but is 1
"location/europe/Norway",2,
"location/europe/Sweden",1]},
"facet_dates":{},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
这个标签列表仍然是扁平的,但至少location/europe = 4 会被正确聚合,但目前不是。我不断收到location/europe = 1,因为它只设置为Alice 和Bob 的Norway 和Sweden 没有汇总到Europe。
想法
- 我可能需要使用
facet.pivot,但我不知道如何使用。 - 我可能需要使用
facet.prefix,但我不知道如何使用。
版本
- Solr 5.1.0
- Windows 7
【问题讨论】:
标签: solr faceted-search hierarchical