Is there any workaround for sorting on multiValued field?

北城余情 提交于 2019-12-20 07:47:59

问题


Sorting can be done on the "score" of the document, or on any multiValued="false" indexed="true" field provided that field is either non-tokenized (ie: has no Analyzer) or uses an Analyzer that only produces a single Term (ie: uses the KeywordTokenizer)

docs:- http://wiki.apache.org/solr/CommonQueryParameters#sort

My original schema is (You can consider the following is a GROUP-BY) :-

  • products (id, unique)
    • users who make some comments(multiValued)
    • last_comment_date for each user (multiValued, one user can make multiple comments, but only the last comment date is captured)

If sorting on multiValued is allowed,
I can easily get list of the products commented by certain users,
then sort by last_activity_date.

However, it does not work.
The workaround I have currently is to reverse the schema to :-

  • user + product (as id, unique)
  • user (single value)
  • last_comment_date
  • products

Which mean I (sort of) manage to get list of the products commented by certain users,
order by last_comment_date,
of course it lead to duplication of products
as product will appear in each of the user's comment.

Any suggestion to simulate a group-by effect.

Between, I using solr 3.1.
Field collapsing does not apply.


回答1:


Sorting by a multi-valued field is not something that is just pending to do or can be patched.

It can't be possibly done because it simply doesn't make any sense.

The way to do this is to have a single-valued field (populated at index-time with the last date) per document, then sort on that. I.e. when indexing traverse the list of users with their last activity date, find the latest date, and assign it to the document's last-activity-date field.



来源:https://stackoverflow.com/questions/8492251/is-there-any-workaround-for-sorting-on-multivalued-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!