solrj json.facet不会在响应中带来构面结果

时间:2019-07-05 15:57:32

标签: solrj solr-query-syntax solrclient

我正在尝试与solrj交流 我的代码如下。 我可以通过在浏览器中执行sol-rquery来获取数据

我试图在Java中的一次调用中检索所有字段

        List<SimpleOrderedMap<Object>>buckets = (List<SimpleOrderedMap<Object>>) namedList.findRecursive(FACETS, "category",
                BUCKETS);



http://mysolrserver/solr/art-002/select?q=*:*&json.facet={categories : {type : terms,field: ap,limit : 3}, cat2 : {type : terms,field: ti,limit : 3}}



 final String FACETS = "facets";
 final String BUCKETS = "buckets";
 List<FacetData> facetDataList = new ArrayList<>();

SolrQuery solrQuery = new 

SolrQuery(fql2lucenePipe.getLuceneQueryMap()。get(WcCollectionType.ART.toString()));

        SolrClient solrClient = solrTemplateFactory.getSolrTemplate().getSolrClient();

        JsonFacet jsonFacet = new JsonFacet();
        JsonFacetField jsonFacetField = new JsonFacetField();
        jsonFacetField.setField("ti");
        jsonFacetField.setLimit(4);
        jsonFacetField.setType("terms");

        jsonFacet.setJsonFacetField(jsonFacetField);
        jsonFacet.setFacetLable("ap");
        System.out.println(JsonUtils.toJson(jsonFacetField));
        solrQuery.add("json.facet", "{category:" + JsonUtils.toJson(jsonFacetField) + "}");

        QueryResponse queryResponse =
                solrTemplateFactory.getSolrTemplate().getSolrClient().query("wc_art",
                        solrQuery);
        queryResponse.getRe
        NamedList namedList  = queryResponse.getResponse();
        List<SimpleOrderedMap<Object>>buckets = (List<SimpleOrderedMap<Object>>) namedList.findRecursive(FACETS, "category",
                BUCKETS);
        if (buckets != null) {
            for (SimpleOrderedMap<Object> bucket : buckets) {
               // String manufacturerLevel = (String) bucket.get(BUCKET_VAL);
                // manufacturer's name and total of all prices for this manufacturer
               // // Notice "manu_level_price" that was specified in json.facet
                System.out.println( bucket);
            }
            // Total prices of all manufacturers
            // notice "total_price" that was specified in json.facet and "findRecursive" usage
        }

I can fetch facet only for one field at a time.
is there a way to fetch all facet fields in one call?


0 个答案:

没有答案