예제 #1
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.GetSlop() != b.GetSlop()) return;
     Term[] ats = a.GetTerms();
     Term[] bts = b.GetTerms();
     if (fieldMatch && !ats[0].Field().Equals(bts[0].Field())) return;
     CheckOverlap(expandQueries, ats, bts, a.GetSlop(), a.GetBoost());
     CheckOverlap(expandQueries, bts, ats, b.GetSlop(), b.GetBoost());
 }
예제 #2
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 (var i = 0; i < positions.Length; i++)
                positions[i] = i;

            var pieces = new string[terms.Length];
            for (var i = 0; i < terms.Length; i++)
            {
                var pos = positions[i];
                var s = pieces[pos];
                if (s == null)
                    s = (terms[i]).Text();
                else
                    s += "|" + (terms[i]).Text();
                pieces[pos] = s;
            }
            for (var i = 0; i < pieces.Length; i++)
            {
                if (i > 0)
                    _text.Append(' ');
                var 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);
        }
예제 #3
0
 public void Add(Query query)
 {
     if (query is TermQuery)
     {
         AddTerm(((TermQuery)query).GetTerm(), query.GetBoost());
     }
     else if (query is PhraseQuery)
     {
         PhraseQuery pq = (PhraseQuery)query;
         Term[] terms = pq.GetTerms();
         HashMap<String, QueryPhraseMap> map = subMap;
         QueryPhraseMap qpm = null;
         foreach (Term term in terms)
         {
             qpm = GetOrNewMap(map, term.Text());
             map = qpm.subMap;
         }
         qpm.MarkTerminal(pq.GetSlop(), pq.GetBoost());
     }
     else
         throw new ApplicationException("query \"" + query.ToString() + "\" must be flatten first.");
 }
예제 #4
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));
        }