How to arrange groups by account in solr

I am wondering how to arrange groups as a result of Solr. I want to order numFound groups. I saw how to arrange the groups according to the result here , but it did not seem to affect the examples I was looking at, and not quite what I wanted.

In xml, you can see the number in the group as numFound , and that is exactly what I want to sort the groups, so that, 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 advice appreciated! Thanks!

+6
source share
4 answers

Sorting on numFound is not possible because numFound is not a field in Solr.
Check the discussion , noting that it is not supported, and I did not find JIRA open for this problem.

0
source

This is an old question, but maybe with two requests.

First query: return the field you are grouping as a set of facets for your navigation state. You can limit the number of records returned here to 0: you just need faces. The number of facets you return must be the size of your page.

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

Second query: must be for records, so no faces are required. The query must be an OR query for facet field values ​​returned from the first query. (group_id: 23 OR group_id: 143 OR group_id: 5, etc.) and are grouped by the identifier that you use to group.

Sort: reorder the records from query 2 to match the order of query 1.

This will be done, provided I'm not sure how scalable the OR request will be. If you are looking at paginate, remember that you can compensate for the edges: use this as a mechanism, rather than biasing records.

+1
source

Impossible, since the last time I studied this.

0
source

you can sort using fields

consider an example:

If you have 5 FACETS and COUNT associated with it. Then you can sort using COUNTS for each field.

It may be applicable to normal / non-facets fields.

 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; }} 

Your calling method should look like this

 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; } 

In the same URL, they mentioned something like.

sort β†’ ex: For example, sorting = popularity desc will sort the groups according to the highest popularity doc

group.sort β†’ you can apply your field here.

Hope this helps.

0
source

Source: https://habr.com/ru/post/948655/


All Articles