8

I'm wondering how to order groups in a Solr result. I want to order the groups by numFound. I saw how to order the groups by score here, but that didn't seem to actually make a difference in the examples I looked at, and isn't exactly what I wanted.

In the xml you can see the number per group as numFound and that is what I want to sort the groups by, so for example I could see the largest group at the top.

<arr name="groups">
<lst>
<str name="groupValue">top secret</str>
<result name="doclist" numFound="12" start="0">
...

Any tips appreciated! Thanks!

4

4 回答 4

2

这是一个老问题,但可以通过两个查询。

第一个查询:将您分组的字段作为导航状态的一组方面带回。您可以在此处将返回的记录数限制为 0:您只需要方面。您返回的方面的数量应该是您的页面的大小。

group_id:
     23 (6)
    143:(3)
      5:(2)

第二个查询:应该是记录,所以不需要分面。查询应该是从第一个查询返回的构面字段值的 OR 查询。(group_id:23 OR group_id:143 OR group_id:5 等等)并按您用于分组的 id 分组。

排序:重新排序查询 2 中的记录以匹配查询 1 中的顺序。

就可以了,条件是我不确定 OR 查询的可扩展性。如果您要分页,请记住您可以偏移构面:使用它作为机制而不是偏移记录。

于 2017-02-10T09:52:10.217 回答
1

自从我上次调查以来,这是不可能的。

于 2013-07-04T05:01:02.667 回答
1

由于 numFound 不是 Solr 中的字段,因此无法对 numFound 进行排序。
检查提到它不受支持 的讨论,我也没有找到针对该问题的 JIRA。

于 2013-07-04T05:03:04.323 回答
0

您可以使用字段进行排序

考虑一个例子:

如果您有 5 个 FACETS 和 COUNT 与之关联。然后您可以使用每个字段的 COUNTS 进行排序。

它可以适用于普通/非分面字段。

public class FacetBean implements Category,Serializable {



private String facetName; //getter , setters
private long facetCount; // getter , setters


public FacetBean(String facetName, long count,) {

    this.facetName = facetName;
    this.count = count;
}}

你的调用方法应该是这样的

private List<FacetBean> getFacetFieldsbyCount(QueryResponse queryResponse) 
{
    List<FacetField> flds = queryResponse.getFacetFields();
    List<FacetBean> facetList = new ArrayList<FacetBean>();
    FacetBean facet = null;
    if (flds != null) {
        for (FacetField fld : flds) {
            facet = new FacetBean();
            facet.setFacetName(fld.getName());

            List<Count> counts = fld.getValues();

            if (counts != null) {

                for (Count count : counts) {
                    facet.setFacetCount(count.getCount());
                }
            }
            facetList.add(facet);
        }
    }

    Collections.sort(facetList,new Comparator<FacetBean>() {

        public int compare(FacetBean obj1, FacetBean obj2) {

            if(obj1.getFacetCount() > obj2.getFacetCount()) {
                return (int)obj1.getFacetCount();
            } else {
                return (int)obj2.getFacetCount();
            }
        }
    });

    return facetList;
}

在同一个URL他们提到了类似的东西。

sort -->ex :例如,sort=popularity desc将导致根据最高流行度的文档对组进行排序

group.sort -> 你可以在这里申请你的领域。

希望能帮助到你。

于 2013-07-05T08:45:38.267 回答