Ejemplo n.º 1
0
        //fieldname MUST be interned prior to this call
        private static void  GetTerms(Query query, System.Collections.Hashtable terms, bool prohibited, System.String fieldName)
        {
            try
            {
                if (query is BooleanQuery)
                {
                    GetTermsFromBooleanQuery((BooleanQuery)query, terms, prohibited, fieldName);
                }
                else if (query is FilteredQuery)
                {
                    GetTermsFromFilteredQuery((FilteredQuery)query, terms, prohibited, fieldName);
                }
                else
                {
                    System.Collections.Hashtable nonWeightedTerms = new System.Collections.Hashtable();
                    query.ExtractTerms(nonWeightedTerms);

                    System.Collections.IDictionaryEnumerator iter = nonWeightedTerms.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        Term term = (Term)iter.Value;
                        if ((fieldName == null) || (term.Field() == fieldName))
                        {
                            WeightedTerm temp = new  WeightedTerm(query.GetBoost(), term.Text());
                            terms.Add(temp, temp);
                        }
                    }
                }
            }
            catch (System.NotSupportedException ignore)
            {
                //this is non-fatal for our purposes
            }
        }
Ejemplo n.º 2
0
		public QueryScorer(WeightedTerm[] weightedTerms)
		{
			termsToFind = new System.Collections.Hashtable();
			for (int i = 0; i < weightedTerms.Length; i++)
			{
				WeightedTerm existingTerm = (WeightedTerm) termsToFind[weightedTerms[i].term];
				if ((existingTerm == null) || (existingTerm.weight < weightedTerms[i].weight))
				{
					//if a term is defined more than once, always use the highest scoring weight
					termsToFind[weightedTerms[i].term] = weightedTerms[i];
					maxTermWeight = System.Math.Max(maxTermWeight, weightedTerms[i].GetWeight());
				}
			}
		}
Ejemplo n.º 3
0
 public QueryScorer(WeightedTerm[] weightedTerms)
 {
     termsToFind = new System.Collections.Hashtable();
     for (int i = 0; i < weightedTerms.Length; i++)
     {
         WeightedTerm existingTerm = (WeightedTerm)termsToFind[weightedTerms[i].term];
         if ((existingTerm == null) || (existingTerm.weight < weightedTerms[i].weight))
         {
             //if a term is defined more than once, always use the highest scoring weight
             termsToFind[weightedTerms[i].term] = weightedTerms[i];
             maxTermWeight = System.Math.Max(maxTermWeight, weightedTerms[i].GetWeight());
         }
     }
 }
        /// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
        ///
        /// </summary>
        /// <param name="query">     Query to extract term texts from
        /// </param>
        /// <param name="prohibited"><code>true</code> to extract "prohibited" terms, too
        /// </param>
        /// <param name="fieldName"> The fieldName used to filter query terms
        /// </param>
        /// <returns> an array of the terms used in a query, plus their weights.
        /// </returns>
        public static WeightedTerm[] GetTerms(Query query, bool prohibited, System.String fieldName)
        {
            System.Collections.Hashtable terms = new System.Collections.Hashtable();
            if (fieldName != null)
            {
                fieldName = String.Intern(fieldName);
            }
            GetTerms(query, terms, prohibited, fieldName);

            WeightedTerm[] result = new WeightedTerm[terms.Count];
            int            i      = 0;

            foreach (System.Object item in terms.Values)
            {
                result[i++] = (WeightedTerm)item;
            }
            return(result);
        }
Ejemplo n.º 5
0
        /* (non-Javadoc)
         * @see Lucene.Net.Highlight.FragmentScorer#scoreToken(org.apache.lucene.analysis.Token)
         */
        public virtual float GetTokenScore(Token token)
        {
            System.String termText = token.TermText();

            WeightedTerm queryTerm = (WeightedTerm)termsToFind[termText];

            if (queryTerm == null)
            {
                //not a query term - return
                return(0);
            }
            //found a query term - is it unique in this doc?
            if (!uniqueTermsInFragment.Contains(termText))
            {
                totalScore += queryTerm.GetWeight();
                uniqueTermsInFragment.Add(termText, termText);
            }
            return(queryTerm.GetWeight());
        }
		/// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
		/// 
		/// </summary>
		/// <param name="query">     Query to extract term texts from
		/// </param>
		/// <param name="prohibited"><code>true</code> to extract "prohibited" terms, too
		/// </param>
		/// <param name="fieldName"> The fieldName used to filter query terms
		/// </param>
		/// <returns> an array of the terms used in a query, plus their weights.
		/// </returns>
		public static WeightedTerm[] GetTerms(Query query, bool prohibited, System.String fieldName)
		{
			System.Collections.Hashtable terms = new System.Collections.Hashtable();
			if (fieldName != null)
			{
				fieldName = String.Intern(fieldName);
			}
			GetTerms(query, terms, prohibited, fieldName);

            WeightedTerm[] result = new WeightedTerm[terms.Count];
            int i = 0;
            foreach (System.Object item in terms.Values)
            {
                result[i++] = (WeightedTerm) item;
            }
            return (result);
		}
		//fieldname MUST be interned prior to this call
		private static void  GetTerms(Query query, System.Collections.Hashtable terms, bool prohibited, System.String fieldName)
		{
			try
			{
				if (query is BooleanQuery)
					GetTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
				else if (query is FilteredQuery)
					GetTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
				else
				{
					System.Collections.Hashtable nonWeightedTerms = new System.Collections.Hashtable();
					query.ExtractTerms(nonWeightedTerms);

                    System.Collections.IDictionaryEnumerator iter =  nonWeightedTerms.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        Term term = (Term)iter.Value;
                        if ((fieldName == null) || (term.Field() == fieldName))
                        {
                            WeightedTerm temp = new  WeightedTerm(query.GetBoost(), term.Text());
                            terms.Add(temp, temp);
                        }
                    }
				}
			}
			catch (System.NotSupportedException ignore)
			{
				//this is non-fatal for our purposes
			}
		}