예제 #1
0
			public TermWeight(TermQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
				idfExp = similarity.IdfExplain(Enclosing_Instance.term, searcher);
				idf = idfExp.Idf;
			}
예제 #2
0
			public MatchAllDocsWeight(MatchAllDocsQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = searcher.Similarity;
			}
예제 #3
0
 public override Weight CreateWeight(Searcher searcher)
 {
     return(new BooleanWeight(this, searcher));
 }
예제 #4
0
			public ConstantWeight(ConstantScoreQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
			}
예제 #5
0
		/// <summary> Computes a score factor for a simple term and returns an explanation
		/// for that score factor.
		/// 
		/// <p/>
		/// The default implementation uses:
		/// 
        /// <code>
		/// idf(searcher.docFreq(term), searcher.MaxDoc);
        /// </code>
		/// 
		/// Note that <see cref="Searcher.MaxDoc" /> is used instead of
		/// <see cref="Lucene.Net.Index.IndexReader.NumDocs()" /> because it is
		/// proportional to <see cref="Searcher.DocFreq(Term)" /> , i.e., when one is
		/// inaccurate, so is the other, and in the same direction.
		/// 
		/// </summary>
		/// <param name="term">the term in question
		/// </param>
		/// <param name="searcher">the document collection being searched
		/// </param>
		/// <returns> an IDFExplain object that includes both an idf score factor 
		/// and an explanation for the term.
		/// </returns>
		/// <throws>  IOException </throws>
		public virtual Explanation.IDFExplanation IdfExplain(Term term, Searcher searcher)
		{
			int df = searcher.DocFreq(term);
			int max = searcher.MaxDoc;
			float idf2 = Idf(df, max);
			return new AnonymousClassIDFExplanation1(df, max, idf2, this);
		}
예제 #6
0
		/// <summary> Returns a Weight that applies the filter to the enclosed query's Weight.
		/// This is accomplished by overriding the Scorer returned by the Weight.
		/// </summary>
		public override Weight CreateWeight(Searcher searcher)
		{
			Weight weight = query.CreateWeight(searcher);
			Similarity similarity = query.GetSimilarity(searcher);
			return new AnonymousClassWeight(weight, similarity, this);
		}
예제 #7
0
 public override Weight CreateWeight(Searcher searcher)
 {
     return(new MatchAllDocsWeight(this, searcher));
 }
예제 #8
0
 public override Weight CreateWeight(Searcher searcher)
 {
     return(new ConstantScoreQuery.ConstantWeight(this, searcher));
 }
예제 #9
0
 public ConstantWeight(ConstantScoreQuery enclosingInstance, Searcher searcher)
 {
     InitBlock(enclosingInstance);
     this.similarity = Enclosing_Instance.GetSimilarity(searcher);
 }
예제 #10
0
		/// <summary> Expert: Constructs and initializes a Weight for a top-level query.</summary>
		public virtual Weight Weight(Searcher searcher)
		{
			Query query = searcher.Rewrite(this);
			Weight weight = query.CreateWeight(searcher);
		    float sum = weight.GetSumOfSquaredWeights();
            float norm = GetSimilarity(searcher).QueryNorm(sum);
            if (float.IsInfinity(norm) || float.IsNaN(norm))
                norm = 1.0f;
			weight.Normalize(norm);
			return weight;
		}
예제 #11
0
 public override Weight CreateWeight(Searcher searcher)
 {
     return(new TermWeight(this, searcher));
 }
예제 #12
0
		/// <summary> Expert: Constructs an appropriate Weight implementation for this query.
		/// 
		/// <p/>
		/// Only implemented by primitive queries, which re-write to themselves.
		/// </summary>
		public virtual Weight CreateWeight(Searcher searcher)
		{
			throw new System.NotSupportedException();
		}
예제 #13
0
		/// <summary>Expert: Returns the Similarity implementation to be used for this query.
		/// Subclasses may override this method to specify their own Similarity
		/// implementation, perhaps one that delegates through that of the Searcher.
		/// By default the Searcher's Similarity implementation is returned.
		/// </summary>
		public virtual Similarity GetSimilarity(Searcher searcher)
		{
			return searcher.Similarity;
		}
예제 #14
0
		public override Weight CreateWeight(Searcher searcher)
		{
			if (terms.Count == 1)
			{
				// optimize one-term case
				Term term = terms[0];
				Query termQuery = new TermQuery(term);
				termQuery.Boost = Boost;
				return termQuery.CreateWeight(searcher);
			}
			return new PhraseWeight(this, searcher);
		}
예제 #15
0
		public override Weight CreateWeight(Searcher searcher)
		{
			return new MatchAllDocsWeight(this, searcher);
		}
예제 #16
0
 /// <summary>Expert: Returns the Similarity implementation to be used for this query.
 /// Subclasses may override this method to specify their own Similarity
 /// implementation, perhaps one that delegates through that of the Searcher.
 /// By default the Searcher's Similarity implementation is returned.
 /// </summary>
 public virtual Similarity GetSimilarity(Searcher searcher)
 {
     return(searcher.Similarity);
 }
예제 #17
0
        }         // end of DisjunctionMaxWeight inner class

        /* Create the Weight used to score us */
        public override Weight CreateWeight(Searcher searcher)
        {
            return(new DisjunctionMaxWeight(this, searcher));
        }
예제 #18
0
 /// <summary> Expert: Constructs an appropriate Weight implementation for this query.
 ///
 /// <p/>
 /// Only implemented by primitive queries, which re-write to themselves.
 /// </summary>
 public virtual Weight CreateWeight(Searcher searcher)
 {
     throw new System.NotSupportedException();
 }
예제 #19
0
 public MatchAllDocsWeight(MatchAllDocsQuery enclosingInstance, Searcher searcher)
 {
     InitBlock(enclosingInstance);
     this.similarity = searcher.Similarity;
 }
예제 #20
0
			public MultiPhraseWeight(MultiPhraseQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
				
				// compute idf
			    int maxDoc = searcher.MaxDoc;
                foreach (Term[] terms in enclosingInstance.termArrays)
                {
                    foreach (Term term in terms)
                    {
                        idf += similarity.Idf(searcher.DocFreq(term), maxDoc);
                    }
                }
			}
예제 #21
0
		public override Weight CreateWeight(Searcher searcher)
		{
			return new ConstantScoreQuery.ConstantWeight(this, searcher);
		}
예제 #22
0
		public override Weight CreateWeight(Searcher searcher)
		{
			return new MultiPhraseWeight(this, searcher);
		}
예제 #23
0
 public override Weight CreateWeight(Searcher searcher)
 {
     return(new MultiPhraseWeight(this, searcher));
 }
예제 #24
0
        /// <summary> Computes a score factor for a phrase.
        ///
        /// <p/>
        /// The default implementation sums the idf factor for
        /// each term in the phrase.
        ///
        /// </summary>
        /// <param name="terms">the terms in the phrase
        /// </param>
        /// <param name="searcher">the document collection being searched
        /// </param>
        /// <returns> an IDFExplain object that includes both an idf
        /// score factor for the phrase and an explanation
        /// for each term.
        /// </returns>
        /// <throws>  IOException </throws>
        public virtual Explanation.IDFExplanation IdfExplain(ICollection <Term> terms, Searcher searcher)
        {
            int   max  = searcher.MaxDoc;
            float idf2 = 0.0f;

            System.Text.StringBuilder exp = new System.Text.StringBuilder();
            foreach (Term term in terms)
            {
                int df = searcher.DocFreq(term);
                idf2 += Idf(df, max);
                exp.Append(" ");
                exp.Append(term.Text);
                exp.Append("=");
                exp.Append(df);
            }
            float fIdf = idf2;

            return(new AnonymousClassIDFExplanation3(fIdf, exp, this));
        }
예제 #25
0
		/// <summary> Computes a score factor for a phrase.
		/// 
		/// <p/>
		/// The default implementation sums the idf factor for
		/// each term in the phrase.
		/// 
		/// </summary>
		/// <param name="terms">the terms in the phrase
		/// </param>
		/// <param name="searcher">the document collection being searched
		/// </param>
		/// <returns> an IDFExplain object that includes both an idf 
		/// score factor for the phrase and an explanation 
		/// for each term.
		/// </returns>
		/// <throws>  IOException </throws>
		public virtual Explanation.IDFExplanation IdfExplain(ICollection<Term> terms, Searcher searcher)
		{
			int max = searcher.MaxDoc;
			float idf2 = 0.0f;
			System.Text.StringBuilder exp = new System.Text.StringBuilder();
            foreach (Term term in terms)
			{
				int df = searcher.DocFreq(term);
				idf2 += Idf(df, max);
				exp.Append(" ");
				exp.Append(term.Text);
				exp.Append("=");
				exp.Append(df);
			}
			float fIdf = idf2;
			return new AnonymousClassIDFExplanation3(fIdf, exp, this);
		}
예제 #26
0
	    public override Weight CreateWeight(Searcher searcher)
		{
			return new TermWeight(this, searcher);
		}