单个构面字段上有多个 facet.prefix
Multiple facet.prefix on a single facet field
我正在创建一个搜索应用程序,它大量使用 Solr (5.2.1) 分面功能。一个要求是限制指定字段的前缀 return 面的数量。
标准 Solr 查询语法适用于单个前缀值:
/select?q=*%3A*&rows=0&wt=json&indent=true&facet=true&facet.field=DocumentKind&f.DocumentKind.facet.prefix=faq
输出:
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"DocumentKind": {
"faq": 1523
}
...
不幸的是,当我必须使用多个前缀限制字段上的方面时,这不起作用:
/select?q=*%3A*&rows=0&wt=json&indent=true&facet=true&facet.field=DocumentKind&f.DocumentKind.facet.prefix=manual&f.DocumentKind.facet.prefix=faq
我预计它会 return 像这样:
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"DocumentKind": {
"faq": 1523,
"manual": 2366
}
...
但它给出了与之前相同的输出。
在上面的示例中,我匹配了整个构面值,但在实际用例中,我确实必须匹配前缀。为了简洁起见,我展示了这个例子。
我可以在我的应用程序中过滤掉它,但 Solr 不必要地 returned 的数据量很大。
我在我的应用程序中遇到了类似的问题。该问题的解决方案是小平面局部参数。 IE。如果我从 Solr techproducts 示例中获取数据以找出可用或不可用的产品数量 inStock
我需要 运行 查询如下:
http://localhost:8983/solr/techproducts/select?q=*%3A*&wt=json&indent=true&facet=true&facet.field=inStock
我将得到以下结果,其中包括来自 inStock
字段的所有字典值:
...
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"inStock":[
"true",17,
"false",4]},
"facet_dates":{},
...
但在您的情况下,您希望使用字段值的多个前缀来区分分面结果。在这里,本地参数是非常方便的工具。现在,如果我想根据 inStock
字段的特定值(如 true
或 false
进行 facating,我需要使用 !key
来标记结果:
http://localhost:8983/solr/techproducts/select?q=*:*&wt=json&indent=true&facet=true&facet.field={!key=inStock_True+facet.prefix=true}inStock
...
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"inStock_True":[
"true",17]},
"facet_dates":{},
...
因此在使用多方面本地参数前缀查询数据后:
/select?q=*:*&rows=0&wt=json&indent=true&facet=true&facet.field={!key=DocumentKind_manual+facet.prefix=manual}DocumentKind&facet.field={!key=DocumentKind_faq+facet.prefix=faq}DocumentKind
你会看到这样的结果:
...
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"DocumentKind_faq":[
"faq",1523],
"DocumentKind_manual":[
"manual",2366]},
...
我正在创建一个搜索应用程序,它大量使用 Solr (5.2.1) 分面功能。一个要求是限制指定字段的前缀 return 面的数量。
标准 Solr 查询语法适用于单个前缀值:
/select?q=*%3A*&rows=0&wt=json&indent=true&facet=true&facet.field=DocumentKind&f.DocumentKind.facet.prefix=faq
输出:
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"DocumentKind": {
"faq": 1523
}
...
不幸的是,当我必须使用多个前缀限制字段上的方面时,这不起作用:
/select?q=*%3A*&rows=0&wt=json&indent=true&facet=true&facet.field=DocumentKind&f.DocumentKind.facet.prefix=manual&f.DocumentKind.facet.prefix=faq
我预计它会 return 像这样:
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"DocumentKind": {
"faq": 1523,
"manual": 2366
}
...
但它给出了与之前相同的输出。
在上面的示例中,我匹配了整个构面值,但在实际用例中,我确实必须匹配前缀。为了简洁起见,我展示了这个例子。
我可以在我的应用程序中过滤掉它,但 Solr 不必要地 returned 的数据量很大。
我在我的应用程序中遇到了类似的问题。该问题的解决方案是小平面局部参数。 IE。如果我从 Solr techproducts 示例中获取数据以找出可用或不可用的产品数量 inStock
我需要 运行 查询如下:
http://localhost:8983/solr/techproducts/select?q=*%3A*&wt=json&indent=true&facet=true&facet.field=inStock
我将得到以下结果,其中包括来自 inStock
字段的所有字典值:
...
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"inStock":[
"true",17,
"false",4]},
"facet_dates":{},
...
但在您的情况下,您希望使用字段值的多个前缀来区分分面结果。在这里,本地参数是非常方便的工具。现在,如果我想根据 inStock
字段的特定值(如 true
或 false
进行 facating,我需要使用 !key
来标记结果:
http://localhost:8983/solr/techproducts/select?q=*:*&wt=json&indent=true&facet=true&facet.field={!key=inStock_True+facet.prefix=true}inStock
...
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"inStock_True":[
"true",17]},
"facet_dates":{},
...
因此在使用多方面本地参数前缀查询数据后:
/select?q=*:*&rows=0&wt=json&indent=true&facet=true&facet.field={!key=DocumentKind_manual+facet.prefix=manual}DocumentKind&facet.field={!key=DocumentKind_faq+facet.prefix=faq}DocumentKind
你会看到这样的结果:
...
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"DocumentKind_faq":[
"faq",1523],
"DocumentKind_manual":[
"manual",2366]},
...