python - 在 Solr/Python 中处理 facet.pivot 数据

标签 python solr pysolr

我正在使用以下网址查询 Solr 核心:

select?q=*:*&rows=0&facet=on&facet.limit=-1&facet.mincount=0&facet.pivot=brand,series,sub_series

使用Facet Pivot特点

部分 JSON 响应,请注意字段如何适当嵌套:

"facet_pivot":{
  "brand,series,sub_series":[{
      "field":"brand",
      "value":"A. Lange & Sohne",
      "count":69,
      "pivot":[{
          "field":"series",
          "value":"1815 Manual Wind",
          "count":1},
        {
          "field":"series",
          "value":"1815 Up Down",
          "count":1},
        {
          "field":"series",
          "value":"Datograph",
          "count":3,
          "pivot":[{
              "field":"sub_series",
              "value":"Perpetual",
              "count":2},
            {
              "field":"sub_series",
              "value":"Up Down",
              "count":1}]},

现在我使用 pySolr 复制相同的查询:

def nested_navbar():
    result = solr.search('*:*', **{
        'rows': '0',
        'facet': 'on',
        'facet.limit': '-1',
        'facet.mincount': '0',
        'facet.pivot': ['brand_exact', 'series_exact', 'sub_series_exact']
        })

    result = result.facets['facet_pivot']
    return result

由于某种原因,当我打印数据(pdb或Django模板)时,结果中的字典有3个不同的品牌、系列和子系列数组,没有原始的嵌套。换句话说,枢轴字段消失了。

最佳答案

matslindh根据建议,我为 pySolr 设置日志记录:

  1. export DEBUG_PYSOLR='true' 添加到终端。
  2. 运行服务器并检查日志。

这是 pySolr 生成的链接:

/?q=%2A%3A%2A&rows=0&facet=on&facet.limit=-1&facet.mincount=0&facet.pivot=brand&facet.pivot=series&facet.pivot=sub_series&wt=json

问题在于 pySolr 正在为数组中的每个项目(“brand”、“series”和“sub_series”)创建一个新的 facet.pivot 字段。

我的新代码修复了问题并生成一个 facet.pivot 字段:

'facet.pivot': 'brand,series,sub_series'

关于python - 在 Solr/Python 中处理 facet.pivot 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49500733/

相关文章:

python - 在 Anaconda : ModuleNotFoundError: No module named 'solrSource' 中执行 solr-to-es 时出错

python - 如何解决我的 Django API 的 CORS 问题?

lucene - 在 Solr 中,为什么 'built' 没有被限制为 'build' 而 'building' 是?

java - Solr 中的 volatile 数据

Solr日期字段格式

elasticsearch - 我们可以将SOLR中未存储的索引数据迁移到Elastic搜索吗?

python - 使用 pyparsing 连接三元运算符

python - 使用 Pycharm pytest runner 时如何将插件选项传递给 pytest?

python - 在 Django 中获取 'popular categories'