views:

20

answers:

1

How do I sort my results in a random order. my code looks something like this at the moment:

Dim searcher As IndexSearcher = New IndexSearcher(dir, True)
Dim collector As TopScoreDocCollector = TopScoreDocCollector.create(100, True)
searcher.Search(query, collector)
Dim hits() As ScoreDoc = collector.TopDocs.scoreDocs

For Each sDoc As ScoreDoc In hits
    'get doc and return
Next
A: 

Since this is an IEnumerable, you can use standard linq to randomize it. You can find an example here:

public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source)
{
   Random rnd = new Random();
   return source.OrderBy<T, int>((item) => rnd.Next());
}

If you want to do this inside of Lucene itself, you can make your own sorter (although note that you will no longer be randomizing the top 100 results, but rather randomizing all results).

Xodarap