0

我有一个名为“类别”的逗号分隔字段值,我已使用定义为的自定义字段类型对其进行索引和存储:

<fieldType name="text_comma_delimited" class="solr.TextField">
      <analyzer>
        <tokenizer class="solr.PatternTokenizerFactory" pattern="," />
      </analyzer>
</fieldType>

我将字段定义为:

<field name="Categories" type="text_comma_delimited" indexed="true" stored="true" />

现在我想要按这些类别对产品进行分组,所以我使用了一个简单的分组查询,如下所示:

http://localhost:8089/solr/products/select?q=*:*&wt=json&indent=true&group=true&group.field=Categories&group.limit=-1&rows=-1&group.ngroups=true&group.facet=true

但是我得到的结果只是返回了 2 个组而不是 6 个。似乎它正在考虑产品和类别之间的一对一关系,因此一种产品只出现一次,而它应该是一对多的。一种产品可以出现在多个类别中。结果如下:

{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "fl":"Category,SKU",
      "group.ngroups":"true",
      "indent":"true",
      "start":"0",
      "q":"*:*",
      "group.limit":"-1",
      "group.field":"Category",
      "group":"true",
      "wt":"json",
      "group.facet":"true",
      "rows":"-1"}},
  "grouped":{
    "Specialties":{
      "matches":6,
      "ngroups":2,
      "groups":[{
          "groupValue":"Fiction",
          "doclist":{"numFound":3,"start":0,"docs":[
              {
                "SKU":"F5678",
                "Category":"Fiction,ABC,XYZ"},
              {
                "SKU":"F9876",
                "Category":"Fiction,ABC,PQR"},
              {
                "SKU":"F2365",
                "Category":"PQR,Fiction"},
              ]},
        {
          "groupValue":"Technical",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "SKU":"T9876",
                "Category":"CVB,Technical"}]
          }}]}}}

我尝试了分面,它清楚地显示了每个类别的正确计数与此 url:

http://localhost:8089/solr/products/select?q=*:*&wt=json&indent=true&facet=true&facet.field=Categories

结果给了我完美的列表和计数,但上面的分组响应只是缺少数据:

"facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "Categories":[
        "Fiction",3,
        "Mystery",1,
        "Sci-Fi",1,
        "Self Help",1,
        "Technical",1,
        "Philosophy",1
        ]},
    "facet_dates":{},
    "facet_ranges":{}}}

此外,solr 管理控制台的模式浏览器中的“加载术语信息”显示上述字段值和计数。只是组查询没有正确返回。还有什么可以尝试的吗?任何帮助表示赞赏。

4

0 回答 0