Esempio n. 1
0
			internal MatchAllScorer(MatchAllDocsQuery enclosingInstance, IndexReader reader, Similarity similarity, Weight w, byte[] norms):base(similarity)
			{
				InitBlock(enclosingInstance);
				this.termDocs = reader.TermDocs(null);
				score = w.GetValue();
				this.norms = norms;
			}
Esempio n. 2
0
		private float freq; //prhase frequency in current doc as computed by phraseFreq().
		
		internal PhraseScorer(Weight weight, TermPositions[] tps, int[] offsets, Similarity similarity, byte[] norms):base(similarity)
		{
			this.norms = norms;
			this.weight = weight;
			this.value_Renamed = weight.GetValue();
			
			// convert tps to a list of phrase positions.
			// note: phrase-position differs from term-position in that its position
			// reflects the phrase offset: pp.pos = tp.pos - offset.
			// this allows to easily identify a matching (exact) phrase 
			// when all PhrasePositions have exactly the same position.
			for (int i = 0; i < tps.Length; i++)
			{
				PhrasePositions pp = new PhrasePositions(tps[i], offsets[i]);
				if (last != null)
				{
					// add next to end of list
					last.next = pp;
				}
				else
				{
					first = pp;
				}
				last = pp;
			}
			
			pq = new PhraseQueue(tps.Length); // construct empty pq
			first.doc = - 1;
		}
Esempio n. 3
0
			public TermWeight(TermQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
				idfExp = similarity.IdfExplain(Enclosing_Instance.term, searcher);
				idf = idfExp.GetIdf();
			}
Esempio n. 4
0
		public SpanWeight(SpanQuery query, Searcher searcher)
		{
			this.similarity = query.GetSimilarity(searcher);
			this.query = query;
			terms = new System.Collections.Hashtable();
			query.ExtractTerms(terms);
			idfExp = similarity.idfExplain(new System.Collections.ArrayList(terms.Values), searcher);
			idf = idfExp.GetIdf();
		}
Esempio n. 5
0
		/// <summary> Construct a <code>TermScorer</code>.
		/// 
		/// </summary>
		/// <param name="weight">The weight of the <code>Term</code> in the query.
		/// </param>
		/// <param name="td">An iterator over the documents matching the <code>Term</code>.
		/// </param>
		/// <param name="similarity">The <code>Similarity</code> implementation to be used for score
		/// computations.
		/// </param>
		/// <param name="norms">The field norms of the document fields for the <code>Term</code>.
		/// </param>
		public /*internal*/ TermScorer(Weight weight, TermDocs td, Similarity similarity, byte[] norms):base(similarity)
		{
			this.weight = weight;
			this.termDocs = td;
			this.norms = norms;
			this.weightValue = weight.GetValue();
			
			for (int i = 0; i < SCORE_CACHE_SIZE; i++)
				scoreCache[i] = GetSimilarity().Tf(i) * weightValue;
		}
Esempio n. 6
0
		public ConjunctionScorer(Similarity similarity, Scorer[] scorers):base(similarity)
		{
			this.scorers = scorers;
			coord = similarity.Coord(scorers.Length, scorers.Length);
			
			for (int i = 0; i < scorers.Length; i++)
			{
				if (scorers[i].NextDoc() == NO_MORE_DOCS)
				{
					// If even one of the sub-scorers does not have any documents, this
					// scorer should not attempt to do any more work.
					lastDoc = NO_MORE_DOCS;
					return ;
				}
			}
			
			// Sort the array the first time...
			// We don't need to sort the array in any future calls because we know
			// it will already start off sorted (all scorers on same doc).
			
			// note that this comparator is not consistent with equals!
			System.Array.Sort(scorers, new AnonymousClassComparator(this));
			
			// NOTE: doNext() must be called before the re-sorting of the array later on.
			// The reason is this: assume there are 5 scorers, whose first docs are 1,
			// 2, 3, 5, 5 respectively. Sorting (above) leaves the array as is. Calling
			// doNext() here advances all the first scorers to 5 (or a larger doc ID
			// they all agree on). 
			// However, if we re-sort before doNext() is called, the order will be 5, 3,
			// 2, 1, 5 and then doNext() will stop immediately, since the first scorer's
			// docs equals the last one. So the invariant that after calling doNext() 
			// all scorers are on the same doc ID is broken.
			if (DoNext() == NO_MORE_DOCS)
			{
				// The scorers did not agree on any document.
				lastDoc = NO_MORE_DOCS;
				return ;
			}
			
			// If first-time skip distance is any predictor of
			// scorer sparseness, then we should always try to skip first on
			// those scorers.
			// Keep last scorer in it's last place (it will be the first
			// to be skipped on), but reverse all of the others so that
			// they will be skipped on in order of original high skip.
			int end = scorers.Length - 1;
			int max = end >> 1;
			for (int i = 0; i < max; i++)
			{
				Scorer tmp = scorers[i];
				int idx = end - i - 1;
				scorers[i] = scorers[idx];
				scorers[idx] = tmp;
			}
		}
Esempio n. 7
0
		/// <summary> Creates a new instance of DisjunctionMaxScorer
		/// 
		/// </summary>
		/// <param name="tieBreakerMultiplier">Multiplier applied to non-maximum-scoring subqueries for a
		/// document as they are summed into the result.
		/// </param>
		/// <param name="similarity">-- not used since our definition involves neither coord nor terms
		/// directly
		/// </param>
		/// <param name="subScorers">The sub scorers this Scorer should iterate on
		/// </param>
		/// <param name="numScorers">The actual number of scorers to iterate on. Note that the array's
		/// length may be larger than the actual number of scorers.
		/// </param>
		public DisjunctionMaxScorer(float tieBreakerMultiplier, Similarity similarity, Scorer[] subScorers, int numScorers):base(similarity)
		{
			
			this.tieBreakerMultiplier = tieBreakerMultiplier;
			// The passed subScorers array includes only scorers which have documents
			// (DisjunctionMaxQuery takes care of that), and their nextDoc() was already
			// called.
			this.subScorers = subScorers;
			this.numScorers = numScorers;
			
			Heapify();
		}
Esempio n. 8
0
			private void  InitBlock(int df, int max, float idf, Similarity enclosingInstance)
			{
				this.df = df;
				this.max = max;
				this.idf = idf;
				this.enclosingInstance = enclosingInstance;
			}
Esempio n. 9
0
			public ConstantWeight(ConstantScoreQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
			}
Esempio n. 10
0
			public ConstantScorer(ConstantScoreQuery enclosingInstance, Similarity similarity, IndexReader reader, Weight w):base(similarity)
			{
				InitBlock(enclosingInstance);
				theScore = w.GetValue();
				DocIdSet docIdSet = Enclosing_Instance.filter.GetDocIdSet(reader);
				if (docIdSet == null)
				{
					docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.Iterator();
				}
				else
				{
					DocIdSetIterator iter = docIdSet.Iterator();
					if (iter == null)
					{
						docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.Iterator();
					}
					else
					{
						docIdSetIterator = iter;
					}
				}
			}
Esempio n. 11
0
			public BooleanWeight(BooleanQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
				weights = new System.Collections.ArrayList(Enclosing_Instance.clauses.Count);
				for (int i = 0; i < Enclosing_Instance.clauses.Count; i++)
				{
					BooleanClause c = (BooleanClause) Enclosing_Instance.clauses[i];
					weights.Add(c.GetQuery().CreateWeight(searcher));
				}
			}
Esempio n. 12
0
			public AnonymousClassIDFExplanation2(float idf, Similarity enclosingInstance)
			{
				InitBlock(idf, enclosingInstance);
			}
Esempio n. 13
0
			public AnonymousClassIDFExplanation1(int df, int max, float idf, Similarity enclosingInstance)
			{
				InitBlock(df, max, idf, enclosingInstance);
			}
Esempio n. 14
0
		/// <summary>Set the default Similarity implementation used by indexing and search
		/// code.
		/// 
		/// </summary>
		/// <seealso cref="Searcher.SetSimilarity(Similarity)">
		/// </seealso>
		/// <seealso cref="Mono.Lucene.Net.Index.IndexWriter.SetSimilarity(Similarity)">
		/// </seealso>
		public static void  SetDefault(Similarity similarity)
		{
			Similarity.defaultImpl = similarity;
		}
Esempio n. 15
0
		internal SloppyPhraseScorer(Weight weight, TermPositions[] tps, int[] offsets, Similarity similarity, int slop, byte[] norms):base(weight, tps, offsets, similarity, norms)
		{
			this.slop = slop;
		}
Esempio n. 16
0
			private void  InitBlock(float idf, Similarity enclosingInstance)
			{
				this.idf = idf;
				this.enclosingInstance = enclosingInstance;
			}
Esempio n. 17
0
			public AnonymousClassIDFExplanation3(float fIdf, System.Text.StringBuilder exp, Similarity enclosingInstance)
			{
				InitBlock(fIdf, exp, enclosingInstance);
			}
Esempio n. 18
0
		/// <summary>Expert: Set the Similarity implementation used by this Searcher.
		/// 
		/// </summary>
		/// <seealso cref="Similarity.SetDefault(Similarity)">
		/// </seealso>
		public virtual void  SetSimilarity(Similarity similarity)
		{
			this.similarity = similarity;
		}
Esempio n. 19
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                ComplexExplanation result = new ComplexExplanation();

                result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");

                Explanation idfExpl = new Explanation(idf, "idf(" + GetQuery() + ")");

                // explain query weight
                Explanation queryExpl = new Explanation();

                queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

                Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");

                if (Enclosing_Instance.GetBoost() != 1.0f)
                {
                    queryExpl.AddDetail(boostExpl);
                }

                queryExpl.AddDetail(idfExpl);

                Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

                result.AddDetail(queryExpl);

                // explain field weight
                ComplexExplanation fieldExpl = new ComplexExplanation();

                fieldExpl.SetDescription("fieldWeight(" + GetQuery() + " in " + doc + "), product of:");

                Scorer scorer = Scorer(reader, true, false);

                if (scorer == null)
                {
                    return(new Explanation(0.0f, "no matching docs"));
                }
                Explanation tfExpl = scorer.Explain(doc);

                fieldExpl.AddDetail(tfExpl);
                fieldExpl.AddDetail(idfExpl);

                Explanation fieldNormExpl = new Explanation();

                byte[] fieldNorms = reader.Norms(Enclosing_Instance.field);
                float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 1.0f;

                fieldNormExpl.SetValue(fieldNorm);
                fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.SetMatch(tfExpl.IsMatch());
                fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

                result.AddDetail(fieldExpl);
                System.Boolean?tempAux = fieldExpl.GetMatch();
                result.SetMatch(tempAux);

                // combine them
                result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

                if (queryExpl.GetValue() == 1.0f)
                {
                    return(fieldExpl);
                }

                return(result);
            }
Esempio n. 20
0
		internal ExactPhraseScorer(Weight weight, TermPositions[] tps, int[] offsets, Similarity similarity, byte[] norms):base(weight, tps, offsets, similarity, norms)
		{
		}
Esempio n. 21
0
		public ConjunctionScorer(Similarity similarity, System.Collections.ICollection scorers):this(similarity, (Scorer[]) new System.Collections.ArrayList(scorers).ToArray(typeof(Scorer)))
		{
		}
Esempio n. 22
0
		public /*internal*/ BooleanScorer(Similarity similarity, int minNrShouldMatch, System.Collections.IList optionalScorers, System.Collections.IList prohibitedScorers):base(similarity)
		{
			InitBlock();
			this.minNrShouldMatch = minNrShouldMatch;
			
			if (optionalScorers != null && optionalScorers.Count > 0)
			{
				for (System.Collections.IEnumerator si = optionalScorers.GetEnumerator(); si.MoveNext(); )
				{
					Scorer scorer = (Scorer) si.Current;
					maxCoord++;
					if (scorer.NextDoc() != NO_MORE_DOCS)
					{
						scorers = new SubScorer(scorer, false, false, bucketTable.NewCollector(0), scorers);
					}
				}
			}
			
			if (prohibitedScorers != null && prohibitedScorers.Count > 0)
			{
				for (System.Collections.IEnumerator si = prohibitedScorers.GetEnumerator(); si.MoveNext(); )
				{
					Scorer scorer = (Scorer) si.Current;
					int mask = nextMask;
					nextMask = nextMask << 1;
					prohibitedMask |= mask; // update prohibited mask
					if (scorer.NextDoc() != NO_MORE_DOCS)
					{
						scorers = new SubScorer(scorer, false, true, bucketTable.NewCollector(mask), scorers);
					}
				}
			}
			
			coordFactors = new float[maxCoord];
			Similarity sim = GetSimilarity();
			for (int i = 0; i < maxCoord; i++)
			{
				coordFactors[i] = sim.Coord(i, maxCoord - 1);
			}
		}
Esempio n. 23
0
			public MultiPhraseWeight(MultiPhraseQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
				
				// compute idf
				System.Collections.IEnumerator i = Enclosing_Instance.termArrays.GetEnumerator();
				while (i.MoveNext())
				{
					Term[] terms = (Term[]) i.Current;
					for (int j = 0; j < terms.Length; j++)
					{
						idf += Enclosing_Instance.GetSimilarity(searcher).Idf(terms[j], searcher);
					}
				}
			}
Esempio n. 24
0
			private void  InitBlock(float fIdf, System.Text.StringBuilder exp, Similarity enclosingInstance)
			{
				this.fIdf = fIdf;
				this.exp = exp;
				this.enclosingInstance = enclosingInstance;
			}
Esempio n. 25
0
			// constructor
			internal ValueSourceScorer(ValueSourceQuery enclosingInstance, Similarity similarity, IndexReader reader, ValueSourceWeight w):base(similarity)
			{
				InitBlock(enclosingInstance);
				this.weight = w;
				this.qWeight = w.GetValue();
				// this is when/where the values are first created.
				vals = Enclosing_Instance.valSrc.GetValues(reader);
				termDocs = reader.TermDocs(null);
			}
Esempio n. 26
0
			public ValueSourceWeight(ValueSourceQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
			}
Esempio n. 27
0
			private int maxDoc; // document count
			
			public CachedDfSource(System.Collections.IDictionary dfMap, int maxDoc, Similarity similarity)
			{
				this.dfMap = dfMap;
				this.maxDoc = maxDoc;
				SetSimilarity(similarity);
			}
Esempio n. 28
0
		/// <summary>Construct a {@link Similarity} that delegates all methods to another.
		/// 
		/// </summary>
		/// <param name="delegee">the Similarity implementation to delegate to
		/// </param>
		public SimilarityDelegator(Similarity delegee)
		{
			this.delegee = delegee;
		}
Esempio n. 29
0
			protected internal System.Collections.ArrayList weights = new System.Collections.ArrayList(); // The Weight's for our subqueries, in 1-1 correspondence with disjuncts
			
			/* Construct the Weight for this Query searched by searcher.  Recursively construct subquery weights. */
			public DisjunctionMaxWeight(DisjunctionMaxQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = searcher.GetSimilarity();
				for (System.Collections.IEnumerator iter = Enclosing_Instance.disjuncts.GetEnumerator(); iter.MoveNext(); )
				{
					weights.Add(((Query) iter.Current).CreateWeight(searcher));
				}
			}
Esempio n. 30
0
			public MatchAllDocsWeight(MatchAllDocsQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = searcher.GetSimilarity();
			}
Esempio n. 31
0
		/// <summary>Constructs a Scorer.</summary>
		/// <param name="similarity">The <code>Similarity</code> implementation used by this scorer.
		/// </param>
		protected internal Scorer(Similarity similarity)
		{
			this.similarity = similarity;
		}
Esempio n. 32
0
 static TermScorer()
 {
     SIM_NORM_DECODER = Similarity.GetNormDecoder();
 }