【问题标题】:How to do facet search with Pysolr如何使用 Pysolr 进行构面搜索
【发布时间】:2018-06-06 12:14:57
【问题描述】:

当我们使用 curl 或 urlopen 和 facet 来执行查询时,我们得到一个包含 3 个元素的嵌套字典 1. responseHeader 2. response 3. facet_counts

我想在使用 Pysolr 搜索时显示 facet_counts。它只显示查询输出的“响应”值。我正在尝试以下代码,请帮助。

import pysolr
conn = pysolr.Solr('http://localhost:8983/solr/')
result = conn.search('enron', **{
    'fl' : 'body',
    'facet' : 'on'
})   
for r in result:
    print r

【问题讨论】:

  • 您不需要任何方面 - 您至少还需要一个 facet.field
  • 添加 { 'facet' : 'to' } 仍然没有任何改变
  • 我不确定您要说什么 - 您需要至少请求一个 facet.field。设置'facet': 'true', 'facet.field': '<name of field in index>'
  • 它仍然提供与以前相同的输出,添加 'facet.field' 不会在搜索中显示方面。即使在原始代码中,它也应该返回一个空字典。

标签: python solr pysolr


【解决方案1】:

当您迭代 result 变量时,您正在迭代 pysolr 自己的 Results object(而不是直接在 Solr 所示的 JSON 结构上)。

import pysolr
import pprint

conn = pysolr.Solr('http://localhost:8080/solr/corename')
result = conn.search('*:*', **{
    'fl': 'content',
    'facet': 'true',
    'facet.field': 'field_name'
})   

pprint.pprint(result.facets)

任何方面都将出现在此结果对象的facets 属性下。

上面的例子输出:

{'facet_dates': {},
 'facet_fields': {'field_name': ['value', 54439, 'value2', 21179]},
 'facet_intervals': {},
 'facet_queries': {},
 'facet_ranges': {}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 2021-05-12
    相关资源
    最近更新 更多