Пример #1
0
 private static void GetTermsFromTermQuery(TermQuery query, HashSetSupport terms, string fieldName)
 {
     if ((fieldName == null) || (query.GetTerm().Field() == (string)(object)fieldName))
     {
         terms.Add(new WeightedTerm(query.GetBoost(), query.GetTerm().Text()));
     }
 }
Пример #2
0
        private static void GetTermsFromSpanNearQuery(SpanNearQuery query, HashSetSupport terms, string fieldName)
        {
            ICollection queryTerms = query.GetTerms();

            for (IEnumerator iterator = queryTerms.GetEnumerator(); iterator.MoveNext(); )
            {
                // break it out for debugging.
                Term term = (Term) iterator.Current;

                string text = term.Text();
                if ((fieldName == null) || (term.Field() == (string)(object)fieldName))
                {
                    terms.Add(new WeightedTerm(query.GetBoost(), text));
                }
            }
        }
Пример #3
0
        private static void GetTermsFromPhraseQuery(PhraseQuery query, HashSetSupport terms, string fieldName)
        {
            Term[] queryTerms = query.GetTerms();
            int i;

            for (i = 0; i < queryTerms.Length; i++)
            {
                if ((fieldName == null) || (queryTerms[i].Field() == (string)(object)fieldName))
                {
                    terms.Add(new WeightedTerm(query.GetBoost(), queryTerms[i].Text()));
                }
            }
        }
Пример #4
0
        private static void GetTermsFromBooleanQuery(BooleanQuery query, HashSetSupport terms, bool prohibited, string fieldName)
        {
            BooleanClause[] queryClauses = query.GetClauses();
            int i;

            for (i = 0; i < queryClauses.Length; i++)
            {
                if (prohibited || !queryClauses[i].prohibited)
                    GetTerms(queryClauses[i].query, terms, prohibited, fieldName);
            }
        }
Пример #5
0
 private static void GetTerms(Query query, HashSetSupport terms, bool prohibited, string fieldName)
 {
     if (query is BooleanQuery)
         GetTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
     else if (query is PhraseQuery)
         GetTermsFromPhraseQuery((PhraseQuery) query, terms, fieldName);
     else if (query is TermQuery)
         GetTermsFromTermQuery((TermQuery) query, terms, fieldName);
     else if (query is SpanNearQuery)
         GetTermsFromSpanNearQuery((SpanNearQuery) query, terms, fieldName);
 }
Пример #6
0
 /// <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, string fieldName)
 {
     HashSetSupport terms = new HashSetSupport();
     if (fieldName != null)
     {
         fieldName = String.Intern(fieldName);
     }
     GetTerms(query, terms, prohibited, fieldName);
     //return (WeightedTerm[]) ICollectionSupport.ToArray(terms, new WeightedTerm[0]);
     return (WeightedTerm[]) terms.ToArray(typeof(WeightedTerm));
 }