GetTerms() public method

Returns the set of terms in this phrase.
public GetTerms ( ) : Term[]
return Term[]
Esempio n. 1
0
        public override Query VisitPhraseQuery(PhraseQuery phraseq)
        {
            _dump.Append("PhraseQ(");

            var terms = phraseq.GetTerms();
            PhraseQuery newQuery = null;

            int index = 0;
            int count = terms.Length;
            while (index < count)
            {
                var visitedTerm = VisitTerm(terms[index]);
                if (newQuery != null)
                {
                    newQuery.Add(visitedTerm);
                }
                else if (visitedTerm != terms[index])
                {
                    newQuery = new PhraseQuery();
                    for (int i = 0; i < index; i++)
                        newQuery.Add(terms[i]);
                    newQuery.Add(visitedTerm);
                }
                index++;
                if (index < count)
                    _dump.Append(", ");
            }
            _dump.Append(", Slop:").Append(phraseq.GetSlop()).Append(BoostToString(phraseq)).Append(")");
            if (newQuery != null)
                return newQuery;
            return phraseq;
        }
Esempio n. 2
0
 /*
  * Check if PhraseQuery A and B have overlapped part.
  * 
  * ex1) A="a b", B="b c" => overlap; expandQueries={"a b c"}
  * ex2) A="b c", B="a b" => overlap; expandQueries={"a b c"}
  * ex3) A="a b", B="c d" => no overlap; expandQueries={}
  */
 private void CheckOverlap(Dictionary<Query, Query> expandQueries, PhraseQuery a, PhraseQuery b)
 {
     if (a.Slop != b.Slop) return;
     Term[] ats = a.GetTerms();
     Term[] bts = b.GetTerms();
     if (fieldMatch && !ats[0].Field.Equals(bts[0].Field)) return;
     CheckOverlap(expandQueries, ats, bts, a.Slop, a.Boost);
     CheckOverlap(expandQueries, bts, ats, b.Slop, b.Boost);
 }
 private static void VisitQuery(PhraseQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     writer.WriteLine("Slop: {0}", (object)query.Slop);
     foreach (Term term in query.GetTerms())
         AzureQueryLogger.VisitTerm(term, writer);
 }
 private SectionSearchQueryPlan TranslatePhraseQuery(PhraseQuery query)
 {
     Term[] terms = query.GetTerms();
     TermNode[] nodes = new TermNode[terms.Length];
     int[] positions = query.GetPositions();
     for (int i = 0; i < terms.Length; i++)
     {
         nodes[i] = new TermNode(terms[i], positions[i], _reader);
     }
     return new PhraseNode(nodes, _reader);
 }
        private ParameterizedSql BuildPhrase(PhraseQuery phraseQuery)
        {
            var termsAdded = 0;
            var field = "";
            var queryStringBuilder = new StringBuilder();

            foreach (var term in phraseQuery.GetTerms())
            {
                if (termsAdded == 0)
                {
                    field = term.Field;
                }
                else if (termsAdded > 0)
                {
                    queryStringBuilder.Append(" ");
                }

                queryStringBuilder.Append(term.Text);

                termsAdded++;
            }

            Query query;
            var queryString = queryStringBuilder.ToString();

            if (queryString.Contains("?") || queryString.Contains("*"))
            {
                query = new WildcardQuery(new Term(field, queryString));
            }
            else
            {
                query = new TermQuery(new Term(field, queryString));
            }

            return Build(query);
        }
Esempio n. 6
0
        public override Query VisitPhraseQuery(PhraseQuery phraseq)
        {
            var terms = phraseq.GetTerms();
            PhraseQuery newQuery = null;

            int index = 0;
            int count = terms.Length;
            while (index < count)
            {
                var visitedTerm = VisitTerm(terms[index]);
                if (newQuery != null)
                {
                    if (visitedTerm != null)
                        newQuery.Add(visitedTerm);
                }
                else if (visitedTerm != terms[index])
                {
                    newQuery = new PhraseQuery();
                    for (int i = 0; i < index; i++)
                        newQuery.Add(terms[i]);
                    if (visitedTerm != null)
                        newQuery.Add(visitedTerm);
                }
                index++;
            }
            if (newQuery != null)
            {
                if (newQuery.GetTerms().Length > 0)
                    return newQuery;
                return null;
            }
            return phraseq;
        }
Esempio n. 7
0
        public override Query VisitPhraseQuery(PhraseQuery phraseq)
        {
            var terms = phraseq.GetTerms();
            var field = terms[0].Field();

            _text.Append(field);
            _text.Append(":\"");

            var positions = new int[terms.Length];
            for (int i = 0; i < positions.Length; i++)
                positions[i] = i;

            var pieces = new string[terms.Length];
            for (int i = 0; i < terms.Length; i++)
            {
                int pos = ((System.Int32)positions[i]);
                System.String s = pieces[pos];
                if (s == null)
                    s = (terms[i]).Text();
                else
                    s += "|" + (terms[i]).Text();
                pieces[pos] = s;
            }
            for (int i = 0; i < pieces.Length; i++)
            {
                if (i > 0)
                    _text.Append(' ');
                System.String s = pieces[i];
                if (s == null)
                    _text.Append('?');
                else
                    _text.Append(s);
            }
            _text.Append("\"");

            var slop = phraseq.GetSlop();
            if (slop != 0)
            {
                _text.Append("~");
                _text.Append(slop);
            }

            _text.Append(BoostToString(phraseq.GetBoost()));

            return base.VisitPhraseQuery(phraseq);
        }
Esempio n. 8
0
 protected virtual PhraseQuery VisitPhraseQuery(PhraseQuery p)
 {
     var qry = new PhraseQuery();
     foreach (var t in p.GetTerms())
     {
         qry.Add(VisitTerm(t));
     }
     return qry;
 }