Solr 多值问题

发布于 2024-09-15 18:34:58 字数 1517 浏览 2 评论 0原文

考虑以下是我从 solr 获得的 json 响应,如果我使用 multivalued = true字段。

  {
    "id":["1","2","3"],
    "TS":["2010-06-28 00:00:00.0","2010-06-28 00:00:00.0","2010-06-28 00:00:00.0"],
    "Type":["VIDEO","IMAGE","VIDEO"]
    }

but i need the response like this

    {
    "0":["1","2010-06-28 00:00:00.0","VIDEO"],
    "1":["2","2010-06-28 00:00:00.0","IMAGE"],
    "2":["3","2010-06-28 00:00:00.0","VIDEO"]
    }

How can i get this.Any help would be appreciated. Thanks in advance.
<前><代码> **更新:** 实际上,在第一级,这不是问题。当我们要去的时候

超过一级则只有 问题出现了。现在我把 整个响应都在这里 清楚。

{
 "responseHeader":{
  "status":0,
  "QTime":0,
  "params":{
    "facet":"true",
    "indent":"on",
    "start":"0",
    "q":"laptop",
    "wt":["json",
     "json"],
    "rows":"200"}},
 "response":{"numFound":1,"start":0,"docs":[


    {
     "createdBy":"0",
     "id":194,
     "status":"ACTIVE",
     "text":"Can i buy Sony laptop?",
     "ansTS":["2010-07-01 00:00:00.0","2010-08-06 15:11:55.0","2010-08-11 15:28:13.0","2010-08-11 15:30:49.0","2010-08-12 01:45:48.0","2010-08-12 01:46:18.0"],
     "mediaType":["VIDEO","VIDEO","VIDEO"],
     "ansId":["59","76","77","78","80","81"],
     "mediaId":[24,25,26],

       ]},
    ]
 },
 "facet_counts":{
  "facet_queries":{},
  "facet_fields":{
    "catName":[]},
  "facet_dates":{}}}

查看 mediaId 、 mediatype 、ansTS 数组。它是一对多的关系。但它们是按列名称分组的。提前致谢。

Consider The following is the json response i'm getting from the solr if i use multivalued = true for the fields.

  {
    "id":["1","2","3"],
    "TS":["2010-06-28 00:00:00.0","2010-06-28 00:00:00.0","2010-06-28 00:00:00.0"],
    "Type":["VIDEO","IMAGE","VIDEO"]
    }

but i need the response like this

    {
    "0":["1","2010-06-28 00:00:00.0","VIDEO"],
    "1":["2","2010-06-28 00:00:00.0","IMAGE"],
    "2":["3","2010-06-28 00:00:00.0","VIDEO"]
    }

How can i get this.Any help would be appreciated. Thanks in advance.
 **Update :**
    Actually at the first level its not a problem. When we are going

more than one level then only the
problem arises. right now i'm putting
the entire response here to make it
clear.

{
 "responseHeader":{
  "status":0,
  "QTime":0,
  "params":{
    "facet":"true",
    "indent":"on",
    "start":"0",
    "q":"laptop",
    "wt":["json",
     "json"],
    "rows":"200"}},
 "response":{"numFound":1,"start":0,"docs":[


    {
     "createdBy":"0",
     "id":194,
     "status":"ACTIVE",
     "text":"Can i buy Sony laptop?",
     "ansTS":["2010-07-01 00:00:00.0","2010-08-06 15:11:55.0","2010-08-11 15:28:13.0","2010-08-11 15:30:49.0","2010-08-12 01:45:48.0","2010-08-12 01:46:18.0"],
     "mediaType":["VIDEO","VIDEO","VIDEO"],
     "ansId":["59","76","77","78","80","81"],
     "mediaId":[24,25,26],

       ]},
    ]
 },
 "facet_counts":{
  "facet_queries":{},
  "facet_fields":{
    "catName":[]},
  "facet_dates":{}}}

look at the mediaId , mediatype ,ansTS arrays. Its one to many relationship.But they are grouped by column names.Thanks in advance.

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

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

发布评论

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

评论(3

半衾梦 2024-09-22 18:34:58

您提到您将从浏览器中使用此 JSON。因此,您可以使用 jQuery 或任何其他 javascript 库将原始 Solr JSON 响应转换为您需要的结构。

You mentioned that you will consume this JSON from a browser. So you can use jQuery or any other javascript library to convert the raw Solr JSON response into the structure that you need.

记忆で 2024-09-22 18:34:58

如果第一个片段是您收到的实际 solr 响应,那么您的 feeder(连接器/爬虫/等)中可能存在错误。看起来您只有一个索引文档(与您的查询匹配),其中包含您期望从 3 个文档中获得的所有值。

假设您有 3 个文档,与您的预期输出类似,那么实际的 solr wt=json 结果将包含:

[{ 
"id":"1", 
"TS":"2010-06-28 00:00:00.0", 
"Type":"VIDEO"
},

{
"id":"2",
"TS":"2010-06-28 00:00:00.0",
"Type":"IMAGE"
},
{
"id":"3",
"TS":"2010-06-28 00:00:00.0",
"Type":"VIDEO"
}]

如果这个假设是正确的,那么我建议检查您的索引逻辑。

If the first snippet is the actual solr response you're getting, then chances are you have a bug in your feeder (connector/crawler/etc). It looks like you only have one indexed document (that matches your query), which has all the values that you expect from 3 documents.

Assuming you have 3 documents, analogous with your expected output, then the actual solr wt=json result would contain:

[{ 
"id":"1", 
"TS":"2010-06-28 00:00:00.0", 
"Type":"VIDEO"
},

{
"id":"2",
"TS":"2010-06-28 00:00:00.0",
"Type":"IMAGE"
},
{
"id":"3",
"TS":"2010-06-28 00:00:00.0",
"Type":"VIDEO"
}]

If this assumption is correct, then I would suggest looking over your indexing logic.

娇妻 2024-09-22 18:34:58

此输出由 Solr 的 JSONResponseWriter 生成。其输出无法通过配置更改。但是您可以做的是创建您自己的 JSONResponseWriter 版本来生成您想要的输出。您可以通过在 solrconfig.xml 中添加 queryResponseWriter 标记来注册新的 ResponseWriter。

This output is produced by Solr's JSONResponseWriter. Its output can't be altered via configuration. But what you can do is create your own version of JSONResponseWriter to produce your desired output. You can registered your new ResponseWriter by adding a queryResponseWriter tag in solrconfig.xml.

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