[
https://issues.apache.org/jira/browse/SOLR-264?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ryan McKinley updated SOLR-264:
-------------------------------
Attachment: SOLR-264-RandomSortOrder.patch
Implements a 'ScoreDocComparator' that returns a random number.
I don't know if this is a fair distribution, but the results look ok.
This is the meat:
static final ScoreDocComparator RANDOM = new ScoreDocComparator() {
final Random rand = new Random();
public int compare (ScoreDoc i, ScoreDoc j) {
return sortValue(i).compareTo( sortValue(j) );
}
public Comparable sortValue (ScoreDoc i) {
return new Float(rand.nextFloat());
}
public int sortType() {
return SortField.CUSTOM;
}
};
- - - - -
One thing that is wierd is that it seems to need a valid field name. Solr sets
up sorting with a field cache, so I just pick any field name (by default the
unique key) and use that. Any reason this is a bad idea?
- - - -
Old discussion on this topic:
http://www.nabble.com/random-order-tf3198916.html#a8881481
> Support 'random' sort order
> ---------------------------
>
> Key: SOLR-264
> URL: https://issues.apache.org/jira/browse/SOLR-264
> Project: Solr
> Issue Type: New Feature
> Reporter: Ryan McKinley
> Priority: Minor
> Attachments: SOLR-264-RandomSortOrder.patch
>
>
> Support querying for random documents:
> http://localhost:8983/solr/select/?q=*:*&fl=sku&sort=random%20desc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.