コード例 #1
0
		private int maxDocs = 200; // max to cache
		
		internal Hits(Searcher s, Query q, Filter f)
		{
			query = q;
			searcher = s;
			filter = f;
			GetMoreDocs(50); // retrieve 100 initially
		}
コード例 #2
0
		/// <summary> A search implementation which spans a new thread for each
		/// Searchable, waits for each search to complete and merge
		/// the results back together.
		/// </summary>
		public override TopDocs Search(Query query, Filter filter, int nDocs)
		{
			HitQueue hq = new HitQueue(nDocs);
			int totalHits = 0;
			MultiSearcherThread[] msta = new MultiSearcherThread[searchables.Length];
			for (int i = 0; i < searchables.Length; i++)
			{
				// search each searcher
				// Assume not too many searchables and cost of creating a thread is by far inferior to a search
				msta[i] = new MultiSearcherThread(searchables[i], query, filter, nDocs, hq, i, starts, "MultiSearcher thread #" + (i + 1));
				msta[i].Start();
			}
			
			for (int i = 0; i < searchables.Length; i++)
			{
				try
				{
					msta[i].Join();
				}
				catch (System.Threading.ThreadInterruptedException ie)
				{
					; // TODO: what should we do with this???
				}
				System.IO.IOException ioe = msta[i].GetIOException();
				if (ioe == null)
				{
					totalHits += msta[i].Hits();
				}
				else
				{
					// if one search produced an IOException, rethrow it
					throw ioe;
				}
			}
			
			ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
			for (int i = hq.Size() - 1; i >= 0; i--)
			// put docs in array
				scoreDocs[i] = (ScoreDoc) hq.Pop();
			
			return new TopDocs(totalHits, scoreDocs);
		}
コード例 #3
0
ファイル: QueryParser.cs プロジェクト: ngraziano/mono
		protected internal virtual void  AddClause(System.Collections.ArrayList clauses, int conj, int mods, Query q)
		{
			bool required, prohibited;
			
			// If this term is introduced by AND, make the preceding term required,
			// unless it's already prohibited
			if (clauses.Count > 0 && conj == CONJ_AND)
			{
				BooleanClause c = (BooleanClause) clauses[clauses.Count - 1];
				if (!c.prohibited)
					c.required = true;
			}
			
			if (clauses.Count > 0 && operator_Renamed == DEFAULT_OPERATOR_AND && conj == CONJ_OR)
			{
				// If this term is introduced by OR, make the preceding term optional,
				// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)
				// notice if the input is a OR b, first term is parsed as required; without
				// this modification a OR b would parsed as +a OR b
				BooleanClause c = (BooleanClause) clauses[clauses.Count - 1];
				if (!c.prohibited)
					c.required = false;
			}
			
			// We might have been passed a null query; the term might have been
			// filtered away by the analyzer.
			if (q == null)
				return ;
			
			if (operator_Renamed == DEFAULT_OPERATOR_OR)
			{
				// We set REQUIRED if we're introduced by AND or +; PROHIBITED if
				// introduced by NOT or -; make sure not to set both.
				prohibited = (mods == MOD_NOT);
				required = (mods == MOD_REQ);
				if (conj == CONJ_AND && !prohibited)
				{
					required = true;
				}
			}
			else
			{
				// We set PROHIBITED if we're introduced by NOT or -; We set REQUIRED
				// if not PROHIBITED and not introduced by OR
				prohibited = (mods == MOD_NOT);
				required = (!prohibited && conj != CONJ_OR);
			}
			clauses.Add(new BooleanClause(q, required, prohibited));
		}
コード例 #4
0
ファイル: PrefixQuery.cs プロジェクト: emtees/old-code
		public override Query Combine(Query[] queries)
		{
			return Query.MergeBooleanQueries(queries);
		}
コード例 #5
0
		public override Explanation Explain(Query query, int doc)
		{
			return query.Weight(this).Explain(reader, doc);
		}
コード例 #6
0
		// inherit javadoc
		public override void  Search(Query query, Filter filter, HitCollector results)
		{
			HitCollector collector = results;
			if (filter != null)
			{
				System.Collections.BitArray bits = filter.Bits(reader);
				collector = new AnonymousClassHitCollector2(bits, results, this);
			}
			
			Scorer scorer = query.Weight(this).Scorer(reader);
			if (scorer == null)
				return ;
			scorer.Score(collector);
		}
コード例 #7
0
		/// <summary>Expert: called when re-writing queries under MultiSearcher.
		/// 
		/// <p>Only implemented by derived queries, with no
		/// {@link #CreateWeight(Searcher)} implementatation.
		/// </summary>
		public virtual Query Combine(Query[] queries)
		{
			throw new System.NotSupportedException();
		}
コード例 #8
0
ファイル: MultiSearcher.cs プロジェクト: emtees/old-code
		public override Query Rewrite(Query original)
		{
			Query[] queries = new Query[searchables.Length];
			for (int i = 0; i < searchables.Length; i++)
			{
				queries[i] = searchables[i].Rewrite(original);
			}
			return original.Combine(queries);
		}
コード例 #9
0
		public MultiSearcherThread(Monodoc.Lucene.Net.Search.Searchable searchable, Query query, Filter filter, int nDocs, FieldDocSortedHitQueue hq, Sort sort, int i, int[] starts, System.String name):base(name)
		{
			this.searchable = searchable;
			this.query = query;
			this.filter = filter;
			this.nDocs = nDocs;
			this.hq = hq;
			this.i = i;
			this.starts = starts;
			this.sort = sort;
		}
コード例 #10
0
ファイル: RemoteSearchable.cs プロジェクト: emtees/old-code
		public virtual Explanation Explain(Query query, int doc)
		{
			return local.Explain(query, doc);
		}
コード例 #11
0
ファイル: RemoteSearchable.cs プロジェクト: emtees/old-code
		public virtual Query Rewrite(Query original)
		{
			return local.Rewrite(original);
		}
コード例 #12
0
ファイル: RemoteSearchable.cs プロジェクト: emtees/old-code
		public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
		{
			return local.Search(query, filter, n, sort);
		}
コード例 #13
0
ファイル: RemoteSearchable.cs プロジェクト: emtees/old-code
		public virtual TopDocs Search(Query query, Filter filter, int n)
		{
			return local.Search(query, filter, n);
		}
コード例 #14
0
ファイル: RemoteSearchable.cs プロジェクト: emtees/old-code
		public virtual void  Search(Query query, Filter filter, HitCollector results)
		{
			local.Search(query, filter, results);
		}
コード例 #15
0
ファイル: MultiSearcher.cs プロジェクト: emtees/old-code
		public override TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
		{
			FieldDocSortedHitQueue hq = null;
			int totalHits = 0;
			
			for (int i = 0; i < searchables.Length; i++)
			{
				// search each searcher
				TopFieldDocs docs = searchables[i].Search(query, filter, n, sort);
				if (hq == null)
					hq = new FieldDocSortedHitQueue(docs.fields, n);
				totalHits += docs.totalHits; // update totalHits
				ScoreDoc[] scoreDocs = docs.scoreDocs;
				for (int j = 0; j < scoreDocs.Length; j++)
				{
					// merge scoreDocs into hq
					ScoreDoc scoreDoc = scoreDocs[j];
					scoreDoc.doc += starts[i]; // convert doc
					if (!hq.Insert(scoreDoc))
						break; // no more scores > minScore
				}
			}
			
			ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()];
			for (int i = hq.Size() - 1; i >= 0; i--)
			// put docs in array
				scoreDocs2[i] = (ScoreDoc) hq.Pop();
			
			return new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields());
		}
コード例 #16
0
ファイル: MultiSearcher.cs プロジェクト: emtees/old-code
		// inherit javadoc
		public override void  Search(Query query, Filter filter, HitCollector results)
		{
			for (int i = 0; i < searchables.Length; i++)
			{
				
				int start = starts[i];
				
				searchables[i].Search(query, filter, new AnonymousClassHitCollector(results, start, this));
			}
		}
コード例 #17
0
		/// <summary>Constructs a filter which only matches documents matching
		/// <code>query</code>.
		/// </summary>
		public QueryFilter(Query query)
		{
			this.query = query;
		}
コード例 #18
0
ファイル: MultiSearcher.cs プロジェクト: emtees/old-code
		public override Explanation Explain(Query query, int doc)
		{
			int i = SubSearcher(doc); // find searcher index
			return searchables[i].Explain(query, doc - starts[i]); // dispatch to searcher
		}
コード例 #19
0
ファイル: Searcher.cs プロジェクト: emtees/old-code
		/// <summary>Returns the documents matching <code>query</code>. </summary>
		public Hits Search(Query query)
		{
			return Search(query, (Filter) null);
		}
コード例 #20
0
		/// <summary>Expert: merges the clauses of a set of BooleanQuery's into a single
		/// BooleanQuery.
		/// 
		/// <p>A utility for use by {@link #Combine(Query[])} implementations.
		/// </summary>
		public static Query MergeBooleanQueries(Query[] queries)
		{
			System.Collections.Hashtable allClauses = new System.Collections.Hashtable();
			for (int i = 0; i < queries.Length; i++)
			{
				BooleanClause[] clauses = ((BooleanQuery) queries[i]).GetClauses();
				for (int j = 0; j < clauses.Length; j++)
				{
					allClauses.Add(clauses[j], clauses[j]);
				}
			}
			
            BooleanQuery result = new BooleanQuery();
            foreach (BooleanClause booleanClause in allClauses.Keys)
            {
                result.Add(booleanClause);
            }
            return result;
		}
コード例 #21
0
ファイル: Searcher.cs プロジェクト: emtees/old-code
		/// <summary>Returns the documents matching <code>query</code> and
		/// <code>filter</code>. 
		/// </summary>
		public virtual Hits Search(Query query, Filter filter)
		{
			return new Hits(this, query, filter);
		}
コード例 #22
0
		// inherit javadoc
		public override TopFieldDocs Search(Query query, Filter filter, int nDocs, Sort sort)
		{
			Scorer scorer = query.Weight(this).Scorer(reader);
			if (scorer == null)
				return new TopFieldDocs(0, new ScoreDoc[0], sort.fields);
			
			System.Collections.BitArray bits = filter != null ? filter.Bits(reader) : null;
			FieldSortedHitQueue hq = new FieldSortedHitQueue(reader, sort.fields, nDocs);
			int[] totalHits = new int[1];
			scorer.Score(new AnonymousClassHitCollector1(bits, totalHits, hq, this));
			
			ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
			for (int i = hq.Size() - 1; i >= 0; i--)
			// put docs in array
				scoreDocs[i] = hq.FillFields((FieldDoc) hq.Pop());
			
			return new TopFieldDocs(totalHits[0], scoreDocs, hq.GetFields());
		}
コード例 #23
0
ファイル: Searcher.cs プロジェクト: emtees/old-code
		/// <summary>Returns documents matching <code>query</code> sorted by
		/// <code>sort</code>.
		/// </summary>
		public virtual Hits Search(Query query, Sort sort)
		{
			return new Hits(this, query, null, sort);
		}
コード例 #24
0
		public override Query Rewrite(Query original)
		{
			Query query = original;
			for (Query rewrittenQuery = query.Rewrite(reader); rewrittenQuery != query; rewrittenQuery = query.Rewrite(reader))
			{
				query = rewrittenQuery;
			}
			return query;
		}
コード例 #25
0
ファイル: Searcher.cs プロジェクト: emtees/old-code
		/// <summary>Returns documents matching <code>query</code> and <code>filter</code>,
		/// sorted by <code>sort</code>.
		/// </summary>
		public virtual Hits Search(Query query, Filter filter, Sort sort)
		{
			return new Hits(this, query, filter, sort);
		}
コード例 #26
0
		/// <summary> Constructs a new query which applies a filter to the results of the original query.
		/// Filter.bits() will be called every time this query is used in a search.
		/// </summary>
		/// <param name="query"> Query to be filtered, cannot be <code>null</code>.
		/// </param>
		/// <param name="filter">Filter to apply to query results, cannot be <code>null</code>.
		/// </param>
		public FilteredQuery(Query query, Filter filter)
		{
			this.query = query;
			this.filter = filter;
		}
コード例 #27
0
ファイル: Searcher.cs プロジェクト: emtees/old-code
		/// <summary>Lower-level search API.
		/// 
		/// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero
		/// scoring document.
		/// 
		/// <p>Applications should only use this if they need <i>all</i> of the
		/// matching documents.  The high-level search API ({@link
		/// Searcher#Search(Query)}) is usually more efficient, as it skips
		/// non-high-scoring hits.
		/// <p>Note: The <code>score</code> passed to this method is a raw score.
		/// In other words, the score will not necessarily be a float whose value is
		/// between 0 and 1.
		/// </summary>
		public virtual void  Search(Query query, HitCollector results)
		{
			Search(query, (Filter) null, results);
		}
コード例 #28
0
ファイル: BooleanQuery.cs プロジェクト: emtees/old-code
		/// <summary>Adds a clause to a boolean query.  Clauses may be:
		/// <ul>
		/// <li><code>required</code> which means that documents which <i>do not</i>
		/// match this sub-query will <i>not</i> match the boolean query;
		/// <li><code>prohibited</code> which means that documents which <i>do</i>
		/// match this sub-query will <i>not</i> match the boolean query; or
		/// <li>neither, in which case matched documents are neither prohibited from
		/// nor required to match the sub-query. However, a document must match at
		/// least 1 sub-query to match the boolean query.
		/// </ul>
		/// It is an error to specify a clause as both <code>required</code> and
		/// <code>prohibited</code>.
		/// 
		/// </summary>
		/// <seealso cref="#GetMaxClauseCount()">
		/// </seealso>
		public virtual void  Add(Query query, bool required, bool prohibited)
		{
			Add(new BooleanClause(query, required, prohibited));
		}
コード例 #29
0
ファイル: BooleanClause.cs プロジェクト: emtees/old-code
		/// <summary>Constructs a BooleanClause with query <code>q</code>, required
		/// <code>r</code> and prohibited <code>p</code>. 
		/// </summary>
		public BooleanClause(Query q, bool r, bool p)
		{
			query = q;
			required = r;
			prohibited = p;
		}