SOLR排序不起作用

时间:2015-12-22 22:25:44

标签: sorting solr

向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"/>

2 个答案:

答案 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");