将默认值添加到震动中的数组

发布于 2025-01-27 17:07:31 字数 2401 浏览 1 评论 0原文

我需要将请求转换为Solr微服务。在许多其他属性中,我还有一个从Solr返回的字段列表。我确实需要在那里添加几个默认字段。 IE具有以下输入:

{
  "jsonToTransform": {
    "authorizedCountries": [],
    "searchOptions": {
      "maxRecords": "10",
      "matchScore": "true",
      "matchIndicators": "true",
    },
    "searchAttrList": {
      "distanceUnit": "M",
      "phoneNumber": "369283729375",
      "distance": "8.5",
      "latitude": 44.71663,
      "longitude": 10.23196
    },
    "responseAttrList": ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url"]
  }
}

我需要获取此输出:

{
  "searchOptions" : {
    "maxRecords" : "10",
    "matchScore" : "true",
    "matchIndicators" : "true"
  },
  "searchAttrList" : {
    "distance" : "13.68",
    "point" : "44.71663,10.23196"
  },
  "solrOptions" : {
    "responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url","compatibilityIndex","privacyIndicator"],
    "countryCodeList" : [ ],
    "pnm_boost" : "1.0",
    "anm_boost" : "1.0",
    ...
  }
}

我几乎所有工作都有效,除了在 ResponselementsList 的末尾添加这两个字段。我有这个规格:

{
  "operation": "default",
  "spec": {
    "*": {
      "solrOptions": {
        "anm_boost": "1.0",
        "pnm_boost": "1.0",
        "responseElementsList": ["compatibilityIndex","privacyIndicator"]
      }
    }
  }
},
{
  "operation": "shift",
  "spec": {
    "*": {
      "solr*": {
        "*": "&1.&",
        "@(1,responseAttrList)": "&1.responseElementsList",
        "@(1,authorizedCountries)": "&1.countryCodeList",
        ...
      },
      "search*": "&",
      "searchOptions": {
        "*": "&1.&",
        ...
      }
    }
  }
}

但是,作为回应,我得到了:

"responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url",["compatibilityIndex","privacyIndicator"]],

我确实尝试了其他一些变体,但它们也没有产生所需的输出。 请告诉我我做错了什么。

I need to transform request to a SOLR microservice. Among many other attributes I have a list of fields to be returned from SOLR. I do need to add a couple of default fields there.
I.e. with the following input:

{
  "jsonToTransform": {
    "authorizedCountries": [],
    "searchOptions": {
      "maxRecords": "10",
      "matchScore": "true",
      "matchIndicators": "true",
    },
    "searchAttrList": {
      "distanceUnit": "M",
      "phoneNumber": "369283729375",
      "distance": "8.5",
      "latitude": 44.71663,
      "longitude": 10.23196
    },
    "responseAttrList": ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url"]
  }
}

I need to get this output:

{
  "searchOptions" : {
    "maxRecords" : "10",
    "matchScore" : "true",
    "matchIndicators" : "true"
  },
  "searchAttrList" : {
    "distance" : "13.68",
    "point" : "44.71663,10.23196"
  },
  "solrOptions" : {
    "responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url","compatibilityIndex","privacyIndicator"],
    "countryCodeList" : [ ],
    "pnm_boost" : "1.0",
    "anm_boost" : "1.0",
    ...
  }
}

I have almost everything working, except adding these two fields at the end of responseElementsList. I have this spec:

{
  "operation": "default",
  "spec": {
    "*": {
      "solrOptions": {
        "anm_boost": "1.0",
        "pnm_boost": "1.0",
        "responseElementsList": ["compatibilityIndex","privacyIndicator"]
      }
    }
  }
},
{
  "operation": "shift",
  "spec": {
    "*": {
      "solr*": {
        "*": "&1.&",
        "@(1,responseAttrList)": "&1.responseElementsList",
        "@(1,authorizedCountries)": "&1.countryCodeList",
        ...
      },
      "search*": "&",
      "searchOptions": {
        "*": "&1.&",
        ...
      }
    }
  }
}

But in response I am getting :

"responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url",["compatibilityIndex","privacyIndicator"]],

I did try some other variants but they did not produce desired output either.
Please do tell me what I am doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2025-02-03 17:07:31

您可以添加 ResponselementsList shift 转换,在其中步行为数组的索引,而不是整个

[
 ....,
  {
    "operation": "shift",
    "spec": {
      "*": {
        "solr*": {
          "*": "&1.&",
          "@(1,responseAttrList)": "&1.responseElementsList",
          "responseElementsList": {
            "*": {
              "@": "&3.&2"
            }
          }, 
          "@(1,authorizedCountries)": "&1.countryCodeList",
        ...
      },
      "search*": "&",
      "searchOptions": {
        "*": "&1.&",
        ...
      }
    }
   }
  }
  ...
]

数组>& 3 表示关键名称 “ solroptions” 以在共同对象下组合,并且& 2 代表 “ ResponselementsList” 键名。

You can add responseElementsList object to the shift transformation in which walk for the indices of the array, but not the whole array such as

[
 ....,
  {
    "operation": "shift",
    "spec": {
      "*": {
        "solr*": {
          "*": "&1.&",
          "@(1,responseAttrList)": "&1.responseElementsList",
          "responseElementsList": {
            "*": {
              "@": "&3.&2"
            }
          }, 
          "@(1,authorizedCountries)": "&1.countryCodeList",
        ...
      },
      "search*": "&",
      "searchOptions": {
        "*": "&1.&",
        ...
      }
    }
   }
  }
  ...
]

where &3 represents the key name "solrOptions" in order to combine under the common object, and &2 represents "responseElementsList" key name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文