Solr 如何将搜索范围缩小到特定品牌,并在单个查询中获得该品牌的所有兄弟姐妹?
Solr how to narrow down the search to specific brand and also get all siblings of that brand in single query?
当我输入这个url
http://localhost:8983/solr/shop/select?facet.field=brand&facet=on&facet.mincount=1&fl=name,brand,cat&q=mobile
我得到了关注
response {
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"mobile",
"facet.field":"brand",
"fl":"name,brand,cat",
"facet.mincount":"1",
"facet":"on"}},
"response":{"numFound":7,"start":0,"docs":[
{
"name":"moto g",
"brand":"motorola",
"cat":["mobile"]},
{
"name":"moto x",
"brand":"motorola",
"cat":["mobile"]},
{
"name":"iphone 5",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5c",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4s",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5s",
"brand":"apple",
"cat":["mobile"]}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"brand":[
"apple",5,
"motorola",2]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
现在我想将搜索范围缩小到 apple 品牌的手机。为此,我使用这样的过滤器查询:
http://localhost:8983/solr/shop/select?facet.field=brand&facet=on&facet.mincount=1&fl=name,brand,cat&q=mobile&fq=brand:apple
我得到了这个结果:
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"mobile",
"facet.field":"brand",
"fl":"name,brand,cat",
"facet.mincount":"1",
"fq":"brand:apple",
"facet":"on"}},
"response":{"numFound":5,"start":0,"docs":[
{
"name":"iphone 5",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5c",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4s",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5s",
"brand":"apple",
"cat":["mobile"]}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"brand":[
"apple",5]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
我对结果很满意。但我也希望 facet_fields 包含 apple 和 motorola。
简而言之,我需要以下结果:
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"mobile",
"facet.field":"brand",
"fl":"name,brand,cat",
"facet.mincount":"1",
"fq":"brand:apple",
"facet":"on"}},
"response":{"numFound":5,"start":0,"docs":[
{
"name":"iphone 5",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5c",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4s",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5s",
"brand":"apple",
"cat":["mobile"]}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"brand":[
"apple",5,
"motorola",2]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
提前感谢您的回答。
您可以使用 filter tagging and filter exclusion 始终获得完整的方面列表,而不管特定的过滤器。
q=mobile&fq={!tag=brand}brand:apple&facet=on&facet.field={!ex=brand}brand
当我输入这个url
http://localhost:8983/solr/shop/select?facet.field=brand&facet=on&facet.mincount=1&fl=name,brand,cat&q=mobile
我得到了关注
response {
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"mobile",
"facet.field":"brand",
"fl":"name,brand,cat",
"facet.mincount":"1",
"facet":"on"}},
"response":{"numFound":7,"start":0,"docs":[
{
"name":"moto g",
"brand":"motorola",
"cat":["mobile"]},
{
"name":"moto x",
"brand":"motorola",
"cat":["mobile"]},
{
"name":"iphone 5",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5c",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4s",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5s",
"brand":"apple",
"cat":["mobile"]}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"brand":[
"apple",5,
"motorola",2]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
现在我想将搜索范围缩小到 apple 品牌的手机。为此,我使用这样的过滤器查询:
http://localhost:8983/solr/shop/select?facet.field=brand&facet=on&facet.mincount=1&fl=name,brand,cat&q=mobile&fq=brand:apple
我得到了这个结果:
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"mobile",
"facet.field":"brand",
"fl":"name,brand,cat",
"facet.mincount":"1",
"fq":"brand:apple",
"facet":"on"}},
"response":{"numFound":5,"start":0,"docs":[
{
"name":"iphone 5",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5c",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4s",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5s",
"brand":"apple",
"cat":["mobile"]}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"brand":[
"apple",5]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
我对结果很满意。但我也希望 facet_fields 包含 apple 和 motorola。 简而言之,我需要以下结果:
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"mobile",
"facet.field":"brand",
"fl":"name,brand,cat",
"facet.mincount":"1",
"fq":"brand:apple",
"facet":"on"}},
"response":{"numFound":5,"start":0,"docs":[
{
"name":"iphone 5",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5c",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 4s",
"brand":"apple",
"cat":["mobile"]},
{
"name":"iphone 5s",
"brand":"apple",
"cat":["mobile"]}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"brand":[
"apple",5,
"motorola",2]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
提前感谢您的回答。
您可以使用 filter tagging and filter exclusion 始终获得完整的方面列表,而不管特定的过滤器。
q=mobile&fq={!tag=brand}brand:apple&facet=on&facet.field={!ex=brand}brand