Example #1
0
		/// <summary> Constructs a new query which applies a filter to the results of the original query.
		/// Filter.getDocIdSet() will be called every time this query is used in a search.
		/// </summary>
		/// <param name="query"> Query to be filtered, cannot be <c>null</c>.
		/// </param>
		/// <param name="filter">Filter to apply to query results, cannot be <c>null</c>.
		/// </param>
		public FilteredQuery(Query query, Filter filter)
		{
			this.query = query;
			this.filter = filter;
		}
Example #2
0
		/// <summary>Search implementation with arbitrary sorting.  Finds
		/// the top <c>n</c> hits for <c>query</c>, applying
		/// <c>filter</c> if non-null, and sorting the hits by the criteria in
		/// <c>sort</c>.
		/// 
		/// <p/>NOTE: this does not compute scores by default; use
		/// <see cref="IndexSearcher.SetDefaultFieldSortScoring(bool,bool)" /> to enable scoring.
		/// 
		/// </summary>
		/// <throws>  BooleanQuery.TooManyClauses </throws>
		public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
		{
			return Search(CreateWeight(query), filter, n, sort);
		}
Example #3
0
		/// <summary>Lower-level search API.
		/// 
		/// <p/><see cref="Collector.Collect(int)" /> is called for every matching
		/// document.
		/// <br/>Collector-based access to remote indexes is discouraged.
		/// 
		/// <p/>Applications should only use this if they need <i>all</i> of the
		/// matching documents.  The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />)
		/// is usually more efficient, as it skips
		/// non-high-scoring hits.
		/// 
		/// </summary>
		/// <param name="query">to match documents
		/// </param>
		/// <param name="filter">if non-null, used to permit documents to be collected.
		/// </param>
		/// <param name="results">to receive hits
		/// </param>
		/// <throws>  BooleanQuery.TooManyClauses </throws>
		public virtual void  Search(Query query, Filter filter, Collector results)
		{
			Search(CreateWeight(query), filter, results);
		}
Example #4
0
		public abstract TopDocs Search(Weight weight, Filter filter, int n);
Example #5
0
		public abstract TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);
		/// <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);
		}
Example #7
0
			public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
			{
				throw new System.NotSupportedException();
			}
Example #8
0
		public override void  Search(Weight weight, Filter filter, Collector collector)
		{
			
			if (filter == null)
			{
				for (int i = 0; i < subReaders.Length; i++)
				{
					// search each subreader
					collector.SetNextReader(subReaders[i], docStarts[i]);
					Scorer scorer = weight.Scorer(subReaders[i], !collector.AcceptsDocsOutOfOrder, true);
					if (scorer != null)
					{
						scorer.Score(collector);
					}
				}
			}
			else
			{
				for (int i = 0; i < subReaders.Length; i++)
				{
					// search each subreader
					collector.SetNextReader(subReaders[i], docStarts[i]);
					SearchWithFilter(subReaders[i], weight, filter, collector);
				}
			}
		}
Example #9
0
		private void  SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector)
		{
			
			System.Diagnostics.Debug.Assert(filter != null);
			
			Scorer scorer = weight.Scorer(reader, true, false);
			if (scorer == null)
			{
				return ;
			}
			
			int docID = scorer.DocID();
			System.Diagnostics.Debug.Assert(docID == - 1 || docID == DocIdSetIterator.NO_MORE_DOCS);
			
			// CHECKME: use ConjunctionScorer here?
			DocIdSet filterDocIdSet = filter.GetDocIdSet(reader);
			if (filterDocIdSet == null)
			{
				// this means the filter does not accept any documents.
				return ;
			}
			
			DocIdSetIterator filterIter = filterDocIdSet.Iterator();
			if (filterIter == null)
			{
				// this means the filter does not accept any documents.
				return ;
			}
			int filterDoc = filterIter.NextDoc();
			int scorerDoc = scorer.Advance(filterDoc);
			
			collector.SetScorer(scorer);
			while (true)
			{
				if (scorerDoc == filterDoc)
				{
					// Check if scorer has exhausted, only before collecting.
					if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS)
					{
						break;
					}
					collector.Collect(scorerDoc);
					filterDoc = filterIter.NextDoc();
					scorerDoc = scorer.Advance(filterDoc);
				}
				else if (scorerDoc > filterDoc)
				{
					filterDoc = filterIter.Advance(scorerDoc);
				}
				else
				{
					scorerDoc = scorer.Advance(filterDoc);
				}
			}
		}
Example #10
0
		public override TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort)
		{
			return Search(weight, filter, nDocs, sort, true);
		}
Example #11
0
		/// <summary> Just like <see cref="Search(Weight, Filter, int, Sort)" />, but you choose
		/// whether or not the fields in the returned <see cref="FieldDoc" /> instances
		/// should be set by specifying fillFields.
		/// <p/>
		/// NOTE: this does not compute scores by default. If you need scores, create
		/// a <see cref="TopFieldCollector" /> instance by calling
		/// <see cref="TopFieldCollector.Create" /> and then pass that to
		/// <see cref="Search(Weight, Filter, Collector)" />.
		/// <p/>
		/// </summary>
		public virtual TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort, bool fillFields)
		{
            nDocs = Math.Min(nDocs, reader.MaxDoc);

			TopFieldCollector collector2 = TopFieldCollector.Create(sort, nDocs, fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.GetScoresDocsOutOfOrder());
			Search(weight, filter, collector2);
			return (TopFieldDocs) collector2.TopDocs();
		}
Example #12
0
		// inherit javadoc
		public override TopDocs Search(Weight weight, Filter filter, int nDocs)
		{
			
			if (nDocs <= 0)
			{
				throw new System.ArgumentException("nDocs must be > 0");
			}
            nDocs = Math.Min(nDocs, reader.MaxDoc);

			TopScoreDocCollector collector = TopScoreDocCollector.Create(nDocs, !weight.GetScoresDocsOutOfOrder());
			Search(weight, filter, collector);
			return collector.TopDocs();
		}
Example #13
0
		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);
		}
Example #14
0
	    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);
		}
		public ConstantScoreQuery(Filter filter)
		{
			this.internalFilter = filter;
		}
Example #16
0
		/// <summary>Finds the top <c>n</c>
		/// hits for <c>query</c>, applying <c>filter</c> if non-null.
		/// 
		/// </summary>
		/// <throws>  BooleanQuery.TooManyClauses </throws>
		public virtual TopDocs Search(Query query, Filter filter, int n)
		{
			return Search(CreateWeight(query), filter, n);
		}
		/// <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);
		}
Example #18
0
		public abstract void  Search(Weight weight, Filter filter, Collector results);
		/// <summary>Lower-level search API.
		/// 
		/// <p/><see cref="Collector.Collect(int)" /> is called for every matching document.
		/// 
		/// <p/>Applications should only use this if they need <i>all</i> of the
		/// matching documents.  The high-level search API (<see cref="Searcher.Search(Query, int)" />)
		/// is usually more efficient, as it skips
		/// non-high-scoring hits.
		/// <p/>This method cannot be parallelized, because <see cref="Collector"/>
		/// supports no concurrent access.
		/// </summary>
		/// <param name="weight">to match documents
		/// </param>
		/// <param name="filter">if non-null, a bitset used to eliminate some documents
		/// </param>
		/// <param name="collector">to receive hits
		/// 
		/// TODO: parallelize this one too
		/// </param>
		public override void  Search(Weight weight, Filter filter, Collector collector)
		{
			for (int i = 0; i < searchables.Length; i++)
			{
				
				int start = starts[i];
				
				Collector hc = new AnonymousClassCollector1(collector, start, this);
				
				searchables[i].Search(weight, filter, hc);
			}
		}
Example #20
0
			public override void  Search(Weight weight, Filter filter, Collector results)
			{
				throw new System.NotSupportedException();
			}