Вопрос

I'm trying to understand if it's possible to use RandomSortField in conjunction with another field to sort search results with solr. Let me explain better: I have a SearchQuerySet (I'm using haystack) that is already ordered by a field N but the client want to randomize the search results maintaining the order of the field N, so that the results are randomized inside the "groups" defined by the field N. Before doing everything I would like to now if someone had the same problem and if it's doable using solr (and haystack).

Это было полезно?

Решение

See this. After adding these to your schema.xml:

<types>
  ...
  <fieldType name="random" class="solr.RandomSortField" />
  ... 
 </types>
 <fields>
  ...
  <dynamicField name="random*" type="random" indexed="true" stored="false"/>
  ...
 </fields>

you can do:

sort=fieldN asc,random_XYZ asc

Keep changing XYZ for different ordering within each group of fieldN.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top