21 using System.Threading;
22 using System.Threading.Tasks;
24 using Lucene.Net.Support;
25 using Lucene.Net.Util;
27 using Term = Lucene.Net.Index.Term;
29 namespace Lucene.Net.Search
38 private class AnonymousClassCollector1:
Collector
40 public AnonymousClassCollector1(Lucene.Net.Search.Collector collector,
int start,
ParallelMultiSearcher enclosingInstance)
42 InitBlock(collector, start, enclosingInstance);
44 private void InitBlock(Lucene.Net.Search.Collector collector,
int start,
ParallelMultiSearcher enclosingInstance)
46 this.collector = collector;
48 this.enclosingInstance = enclosingInstance;
50 private Lucene.Net.
Search.Collector collector;
57 return enclosingInstance;
61 public override void SetScorer(
Scorer scorer)
63 collector.SetScorer(scorer);
65 public override void Collect(
int doc)
67 collector.Collect(doc);
69 public override void SetNextReader(
IndexReader reader,
int docBase)
71 collector.SetNextReader(reader, start + docBase);
74 public override bool AcceptsDocsOutOfOrder
76 get {
return collector.AcceptsDocsOutOfOrder; }
87 this.searchables = searchables;
88 this.starts = GetStarts();
95 public override int DocFreq(
Term term)
97 Task<int>[] tasks =
new Task<int>[searchables.Length];
98 for (
int i = 0; i < searchables.Length; i++)
101 tasks[i] = Task.Factory.StartNew(() => searchable.
DocFreq(term));
105 return tasks.Sum(task => task.Result);
115 object lockObj =
new object();
117 Task<TopDocs>[] tasks =
new Task<TopDocs>[searchables.Length];
119 for (
int i = 0; i < searchables.Length; i++)
123 Task.Factory.StartNew(() => MultiSearcherCallableNoSort(
ThreadLock.
MonitorLock, lockObj, searchables[cur], weight, filter,
124 nDocs, hq, cur, starts));
128 float maxScore =
float.NegativeInfinity;
132 foreach(
TopDocs topDocs
in tasks.Select(x => x.Result))
135 maxScore = Math.Max(maxScore, topDocs.
MaxScore);
139 for (
int i = hq.Size() - 1; i >= 0; i--)
140 scoreDocs[i] = hq.Pop();
142 return new TopDocs(totalHits, scoreDocs, maxScore);
151 if (sort == null)
throw new ArgumentNullException(
"sort");
154 object lockObj =
new object();
156 Task<TopFieldDocs>[] tasks =
new Task<TopFieldDocs>[searchables.Length];
157 for (
int i = 0; i < searchables.Length; i++)
161 Task<TopFieldDocs>.Factory.StartNew(
162 () => MultiSearcherCallableWithSort(
ThreadLock.
MonitorLock, lockObj, searchables[cur], weight, filter, nDocs, hq, sort, cur,
167 float maxScore =
float.NegativeInfinity;
170 foreach (
TopFieldDocs topFieldDocs
in tasks.Select(x => x.Result))
173 maxScore = Math.Max(maxScore, topFieldDocs.
MaxScore);
177 for (
int i = hq.Size() - 1; i >= 0; i--)
178 scoreDocs[i] = hq.Pop();
180 return new TopFieldDocs(totalHits, scoreDocs, hq.GetFields(), maxScore);
204 for (
int i = 0; i < searchables.Length; i++)
207 int start = starts[i];
209 Collector hc =
new AnonymousClassCollector1(collector, start,
this);
211 searchables[i].Search(weight, filter, hc);