14

我的 solr 架构中有以下两个字段:

<field name="brand_id"     type="string" indexed="true" stored="true" />
<field name="category_id"  type="string" indexed="true" stored="true" />

当我提出启用构面的请求时(brand_id 上的构面) http://example.com/solr/select?wt=json&facet=true&facet.mincount=1&facet.field=brand_id&q= * :*

分面输出以对象表示法返回:

"facet_counts": {
    "facet_queries": { }
    "facet_fields": {
         "brand_id": [
            {"1350492":14},
            {"1350578":12},
            {"1350600":11},
            {"1350617":8}
        ]
    }
}

但是,使用 'category_id' 作为构面字段重复相同的请求会返回一个数组表示法 http://example.com/solr/select?wt=json&facet=true&facet.mincount=1&facet.field=category_id&q= * :*

"facet_counts":{
    "facet_queries":{},
    "facet_fields":{
        "category_id":[
            "230",20,
            "259",13,
            "154",12,
            "249",11
        ]
    }
}

有没有办法强制对象符号格式?我正在使用 Solr 3.6

- 更新 -

使用 XML 格式返回正确的结果:

<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
    <lst name="brand_id">
        <int name="269115">136</int>
        <int name="269394">110</int>
    </lst>


    <lst name="category_id">
        <int name="1348814">228</int>
        <int name="1350591">218</int>
    </lst>
4

3 回答 3

10

正如 Bill Dueber 所提到的,您可以使用 json.nl 参数格式化 JSON 输出。检查此页面,https://wiki.apache.org/solr/SolJSON#JSON_specific_parameters

于 2013-05-11T10:07:51.043 回答
1

如果您使用 JSON 响应编写器,则可以将json.nl参数添加到查询字符串以格式化构面计数。

json.nl=arrmap将格式化为[{"facetValue1": facetCount1}, {"facetValue2": facetCount2}].

json.nl=map将格式化为{"facetValue1": facetCount1, "facetValue2": facetCount2}.

响应作者的文档,特别是 json.nl(nl = 命名列表)可以在这里找到:https ://cwiki.apache.org/confluence/display/solr/Response+Writers#ResponseWriters-JSON-SpecificParameters

于 2017-06-01T17:23:58.593 回答
0

不久前我也经历过类似的事情。

尝试将标签 multiValued=false 添加到字段的定义中。我记得为我修好了。

不过,您可能必须重新索引。

于 2013-06-06T10:23:09.737 回答