向SOLR查询添加排序条件。首先按department_sortable排序,然后按productname_sortable排序。是按department_sortable排序,而不是按productname_sortable排序。
private List<SortField> getSortParameters() {
List<SortField> sortFields = new ArrayList<SortField>();
sortFields.add(generateSortField("department_sortable", SortDirection.ASC));
sortFields.add(generateSortField("productname_sortable", SortDirection.ASC));
return sortFields;
}
<field name="productname_sortable" type="text" indexed="true" stored="false" />
<field name="department_sortable" type="string" indexed="true" stored="false" multiValued="false"/>
<copyField source="productname" dest="productname_sortable"/>
<copyField source="department" dest="department_sortable"/>
答案 0 :(得分:0)
我认为,只有一个排序字段设置为solrQuery。您可以使用SolrQuery#addSortFieldMethod
添加多个排序字段solrQuery.addSortField( "department_sortable", org.apache.solr.client.solrj.SolrQuery.ORDER.asc );
solrQuery.addSortField( "productname_sortable",org.apache.solr.client.solrj.SolrQuery.ORDER.asc );
或
solrQuery.addOrUpdateSort( "department_sortable", org.apache.solr.client.solrj.SolrQuery.ORDER.asc );
相关帖子Sorting solr search results using multiple fields (solrj)
答案 1 :(得分:0)
试
`solrQuery.setSort(new SortClause("department_sortable", "asc"));
solrQuery.setSort(new SortClause("productname_sortable", "asc"));`
或
`solrQuery.setSort(new SortClause("department_sortable", "asc"));
solrQuery.addSortField(new SortClause("productname_sortable", "asc"));`
或
solrQuery.setSort(new SortClause("department_sortable", "asc"));
solrQuery.addSortField("productname_sortable", "asc");