public virtual AutoCompletionList CreateAutoCompletionList(IEnumerable<BaseIndexEntry> allPrefixEntries, int defaultMinCutOff = 1)
{
// Min query log frequency to allow (heuristic optimisation)
int minCutOff = defaultMinCutOff; // Absolute min cut-off - now 1, rather than 2
if (allPrefixEntries.Count() > 500)
minCutOff = 4;
if (allPrefixEntries.Count() > 1000)
minCutOff = 5;
if (allPrefixEntries.Count() > 3000)
minCutOff = 6;
if (allPrefixEntries.Count() > 6000)
minCutOff = 7;
if (allPrefixEntries.Count() > 10000)
minCutOff = 8;
if (allPrefixEntries.Count() > 15000)
minCutOff = 9;
if (allPrefixEntries.Count() > 20000)
minCutOff = 10;
if (allPrefixEntries.Count() > 26000)
minCutOff = 11;
object listLock = new object();
List<AutoCompletion> autoCompletions = new List<AutoCompletion>();
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = 4;
// Make parallel
Parallel.ForEach(allPrefixEntries, po, indexEntry =>
{
if (indexEntry.QueryLogFrequency > minCutOff)
{
AutoCompletion ac = new AutoCompletion(indexEntry.Query);
ac.RankingWeight = indexEntry.RankingWeight;
ac.IsWikiWeighted = indexEntry.IsWikiWeighted;
lock (listLock)
autoCompletions.Add(ac);
}
});
return new AutoCompletionList(autoCompletions);
}