/// <summary> A search implementation allowing sorting which spans a new thread for each /// Searchable, waits for each search to complete and merges /// the results back together. /// </summary> public override TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort) { if (sort == null) { throw new ArgumentNullException("sort"); } FieldDocSortedHitQueue hq = new FieldDocSortedHitQueue(nDocs); object lockObj = new object(); Task <TopFieldDocs>[] tasks = new Task <TopFieldDocs> [searchables.Length]; for (int i = 0; i < searchables.Length; i++) // search each searchable { int cur = i; tasks[i] = Task <TopFieldDocs> .Factory.StartNew( () => MultiSearcherCallableWithSort(ThreadLock.MonitorLock, lockObj, searchables[cur], weight, filter, nDocs, hq, sort, cur, starts)); } int totalHits = 0; float maxScore = float.NegativeInfinity; Task.WaitAll(tasks); foreach (TopFieldDocs topFieldDocs in tasks.Select(x => x.Result)) { totalHits += topFieldDocs.TotalHits; maxScore = Math.Max(maxScore, topFieldDocs.MaxScore); } ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) { scoreDocs[i] = hq.Pop(); } return(new TopFieldDocs(totalHits, scoreDocs, hq.GetFields(), maxScore)); }
/// <summary> A search implementation allowing sorting which spans a new thread for each /// Searchable, waits for each search to complete and merges /// the results back together. /// </summary> public override TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort) { if (sort == null) throw new ArgumentNullException("sort"); FieldDocSortedHitQueue hq = new FieldDocSortedHitQueue(nDocs); object lockObj = new object(); Task<TopFieldDocs>[] tasks = new Task<TopFieldDocs>[searchables.Length]; for (int i = 0; i < searchables.Length; i++) // search each searchable { int cur = i; tasks[i] = Task<TopFieldDocs>.Factory.StartNew( () => MultiSearcherCallableWithSort(ThreadLock.MonitorLock, lockObj, searchables[cur], weight, filter, nDocs, hq, sort, cur, starts)); } int totalHits = 0; float maxScore = float.NegativeInfinity; Task.WaitAll(tasks); foreach (TopFieldDocs topFieldDocs in tasks.Select(x => x.Result)) { totalHits += topFieldDocs.TotalHits; maxScore = Math.Max(maxScore, topFieldDocs.MaxScore); } ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) scoreDocs[i] = hq.Pop(); return new TopFieldDocs(totalHits, scoreDocs, hq.GetFields(), maxScore); }
/// <summary> A search implementation which executes each /// <see cref="Searchable"/> in its own thread and waits for each search to complete /// and merge the results back together. /// </summary> public override TopDocs Search(Weight weight, Filter filter, int nDocs) { HitQueue hq = new HitQueue(nDocs, false); object lockObj = new object(); Task<TopDocs>[] tasks = new Task<TopDocs>[searchables.Length]; //search each searchable for (int i = 0; i < searchables.Length; i++) { int cur = i; tasks[i] = Task.Factory.StartNew(() => MultiSearcherCallableNoSort(ThreadLock.MonitorLock, lockObj, searchables[cur], weight, filter, nDocs, hq, cur, starts)); } int totalHits = 0; float maxScore = float.NegativeInfinity; Task.WaitAll(tasks); foreach(TopDocs topDocs in tasks.Select(x => x.Result)) { totalHits += topDocs.TotalHits; maxScore = Math.Max(maxScore, topDocs.MaxScore); } ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs[i] = hq.Pop(); return new TopDocs(totalHits, scoreDocs, maxScore); }
/// <summary></summary> public TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore) { this.TotalHits = totalHits; this.ScoreDocs = scoreDocs; this.MaxScore = maxScore; }
/// <summary>Constructs a TopDocs with a default maxScore=Float.NaN. </summary> internal TopDocs(int totalHits, ScoreDoc[] scoreDocs):this(totalHits, scoreDocs, float.NaN) { }
public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort) { var hq = new FieldDocSortedHitQueue(n); int totalHits = 0; float maxScore = System.Single.NegativeInfinity; var lockObj = new object(); for (int i = 0; i < searchables.Length; i++) { // search each searcher // use NullLock, we don't care about synchronization for these TopFieldDocs docs = MultiSearcherCallableWithSort(ThreadLock.NullLock, lockObj, searchables[i], weight, filter, n, hq, sort, i, starts); totalHits += docs.TotalHits; maxScore = System.Math.Max(maxScore, docs.MaxScore); } ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs2[i] = hq.Pop(); return new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields(), maxScore); }
public override TopDocs Search(Weight weight, Filter filter, int nDocs) { HitQueue hq = new HitQueue(nDocs, false); int totalHits = 0; var lockObj = new object(); for (int i = 0; i < searchables.Length; i++) { // search each searcher // use NullLock, we don't care about synchronization for these TopDocs docs = MultiSearcherCallableNoSort(ThreadLock.NullLock, lockObj, searchables[i], weight, filter, nDocs, hq, i, starts); totalHits += docs.TotalHits; // update totalHits } ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array scoreDocs2[i] = hq.Pop(); float maxScore = (totalHits == 0)?System.Single.NegativeInfinity:scoreDocs2[0].Score; return new TopDocs(totalHits, scoreDocs2, maxScore); }
/// <summary>Creates one of these objects.</summary> /// <param name="totalHits"> Total number of hits for the query. /// </param> /// <param name="scoreDocs"> The top hits for the query. /// </param> /// <param name="fields"> The sort criteria used to find the top hits. /// </param> /// <param name="maxScore"> The maximum score encountered. /// </param> public TopFieldDocs(int totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore):base(totalHits, scoreDocs, maxScore) { this.fields = fields; }