如何在solr中按子文档最低价格对父文档进行排序

问题描述 投票:0回答:1

我是 solr 的新手,我想按子文档最低价格对父文档进行排序。请参阅下面提到的示例数据。

{
    "parentID": 1,
    "children": {
      "numFound": 2,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 1,
          "ID": "1",
          "price": 189.7
        },
        {
          "type": "child",
          "parentID": 1,
          "ID": "2",
          "price": 933.1
        }
      ]
    }   },   {
    "parentID": 2,
    "children": {
      "numFound": 2,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 2,
          "ID": "1",
          "price": 1180.0
        },
        {
          "type": "child",
          "parentID": 2,
          "ID": "2",
          "price": 238.0
        }
      ]
    }   },   {
    "parentID": 3,
    "children": {
      "numFound": 1,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 3,
          "ID": "1",
          "price": 1442.81,
        },
        {
            "type": "child",
            "parentID": 3,
            "ID": "2",
            "price": 42.81,
          }
      ]
    }   },   {
    "parentID": 4,
    "children": {
      "numFound": 1,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 4,
          "ID": "1",
          "price": 1140.8,
        }
      ]
    }   }

我想要得到下面提到的格式

{
    "parentID": 3,
    "children": {
      "numFound": 1,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 3,
          "ID": "1",
          "price": 1442.81,
        },
        {
            "type": "child",
            "parentID": 3,
            "ID": "2",
            "price": 42.81,
          }
      ]
    }
  },
  {
    "parentID": 1,
    "children": {
      "numFound": 2,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 1,
          "ID": "1",
          "price": 189.7
        },
        {
          "type": "child",
          "parentID": 1,
          "ID": "2",
          "price": 933.1
        }
      ]
    }
  },
  {
    "parentID": 2,
    "children": {
      "numFound": 2,
      "start": 0,
      "docs": [
        {
            "type": "child",
            "parentID": 2,
            "ID": "2",
            "price": 238.0
        },
        {
          "type": "child",
          "parentID": 2,
          "ID": "1",
          "price": 1180.0
        }
      ]
    }
  },
  {
    "parentID": 4,
    "children": {
      "numFound": 1,
      "start": 0,
      "docs": [
        {
          "type": "child",
          "parentID": 4,
          "ID": "1",
          "price": 1140.8,
        }
      ]
    }
  }

我尝试了下面提到的链接,它对我的问题不起作用。

如何在solr中按子属性对父文档进行排序

sort={!parent which=type:parent 分数=max v=’+type:child +{!func}price’} desc

solr solr7
1个回答
0
投票

您好,您找到解决方案了吗?我也面临着同样的问题。你能帮我一下吗?

© www.soinside.com 2019 - 2024. All rights reserved.