如何通过内部字段对Apache Solr结果进行排序?

时间:2015-04-13 14:02:20

标签: solr

SolrQuery query = new SolrQuery();
query.set("defType", "dismax"); //setting dismax query parser
query.set("q.alt", "(HotelId:" + this.id + ") AND (AuthorName:" + relatedName + ")");
QueryResponse response = REVIEW_CONNECTOR.query(query);
SolrDocumentList results = response.getResults();

输出结果为:

   name": "Copthorne Orchid Hotel Singapore",
    "website": "/ShowUserReviews-g294265-d301677-Reviews-Copthorne_Orchid_Hotel_Singapore-Singapore.html",
    "adddress": "<address><span rel=\"v:address\"><span dir=\"ltr\"><span class=\"street-address\" property=\"v:street-address\">214 Dunearn Road</span>, <span class=\"locality\"><span property=\"v:locality\">Singapore</span> <span property=\"v:postal-code\">299526</span></span>, <span class=\"country-name\" property=\"v:country-name\">Singapore</span> </span></span></address>",
    "imageurl": "http://media-cdn.tripadvisor.com/media/ProviderThumbnails/dirs/30/0f/300ffee8abdabde3741feaeee20ccfc03large.jpg",
    "price": "$88 - $192*",
    "id": 301677,
    "reviews": [
        {
            "title": "“Nice but time for a facelift”",
            "reviewId": "UR126371102",
            "hotelId": 301677,
            "author": "SamGibbs",
            "content": "Whilst i enjoyed my stay at the Orchard there was no doubt that elements of the hotels presentation are in need of upgrading. On the whole aspects of the decor and furnishing are showing age and a well worn look. The room was spacious and comfortable and all the amenities worked. The staff also were friendly and efficient. The breakfast buffet was very reasonable and offered plenty of variety and flavour. The coffee however tasted like dishwater....make sure you order fresh coffee. All in all i would say that the Orchard is a convenient hotel given its locality in Singapore but does not compete if you are looking for a more discerning upmarket experience in accommodation.",
            "overall": 3
        }
    ]

}

如何按整体评分排序?

1 个答案:

答案 0 :(得分:0)

您正在寻找CommonParams.SORT

import org.apache.solr.common.params.CommonParams;
// ...
SolrQuery query = new SolrQuery();
query.set(CommonParams.SORT, "overall desc");
// ... 

一般情况下,您应该对所有CommonParams参数使用SolrQuery