Esempio n. 1
0
        internal FieldQuery(Query query, IndexReader reader, bool phraseHighlight, bool fieldMatch)
        {
            this.fieldMatch = fieldMatch;
            // LUCENENET NOTE: LinkedHashSet cares about insertion order
            ISet <Query> flatQueries = new JCG.LinkedHashSet <Query>();

            Flatten(query, reader, flatQueries);
            SaveTerms(flatQueries, reader);
            ICollection <Query> expandQueries = Expand(flatQueries);

            foreach (Query flatQuery in expandQueries)
            {
                QueryPhraseMap rootMap = GetRootMap(flatQuery);
                rootMap.Add(flatQuery /*, reader // LUCENENET: Never read */);
                if (!phraseHighlight && flatQuery is PhraseQuery pq)
                {
                    if (pq.GetTerms().Length > 1)
                    {
                        foreach (Term term in pq.GetTerms())
                        {
                            rootMap.AddTerm(term, flatQuery.Boost);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public void Add(Query query)
 {
     if (query is TermQuery)
     {
         AddTerm(((TermQuery)query).Term.Text, query.Boost);
     }
     else if (query is PrefixQuery)
     {
         AddTerm(((PrefixQuery)query).Prefix.Text + "*", query.Boost);
     }
     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.Slop, pq.Boost);
     }
     else
     {
         throw new ApplicationException("query \"" + query.ToString() + "\" must be flatten first.");
     }
 }
Esempio n. 3
0
        int termOrPhraseNumber; // used for colored tag support

        public FieldQuery(Query query, bool phraseHighlight, bool fieldMatch)
        {
            this.fieldMatch = fieldMatch;
            Dictionary <Query, Query> flatQueries = new Dictionary <Query, Query>();

            flatten(query, flatQueries);
            SaveTerms(flatQueries);
            Dictionary <Query, Query> expandQueries = expand(flatQueries);

            foreach (Query flatQuery in expandQueries.Keys)
            {
                QueryPhraseMap rootMap = getRootMap(flatQuery);
                rootMap.Add(flatQuery);
                if (!phraseHighlight && flatQuery is PhraseQuery)
                {
                    PhraseQuery pq = (PhraseQuery)flatQuery;
                    if (pq.GetTerms().Length > 1)
                    {
                        foreach (Term term in pq.GetTerms())
                        {
                            rootMap.AddTerm(term.Text, flatQuery.Boost);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 private QueryPhraseMap GetOrNewMap(IDictionary <string, QueryPhraseMap> subMap, string term)
 {
     if (!subMap.TryGetValue(term, out QueryPhraseMap map) || map == null)
     {
         map          = new QueryPhraseMap(fieldQuery);
         subMap[term] = map;
     }
     return(map);
 }
Esempio n. 5
0
        /// <returns>QueryPhraseMap</returns>
        public virtual QueryPhraseMap SearchPhrase(string fieldName, IList <TermInfo> phraseCandidate)
        {
            QueryPhraseMap root = GetRootMap(fieldName);

            if (root == null)
            {
                return(null);
            }
            return(root.SearchPhrase(phraseCandidate));
        }
Esempio n. 6
0
 public QueryPhraseMap SearchPhrase(List<TermInfo> phraseCandidate)
 {
     QueryPhraseMap currMap = this;
     foreach (TermInfo ti in phraseCandidate)
     {
         currMap = currMap.subMap[ti.GetText()];
         if (currMap == null) return null;
     }
     return currMap.IsValidTermOrPhrase(phraseCandidate) ? currMap : null;
 }
Esempio n. 7
0
 private QueryPhraseMap GetOrNewMap(HashMap<String, QueryPhraseMap> subMap, String term)
 {
     QueryPhraseMap map = subMap.Get(term);
     if (map == null)
     {
         map = new QueryPhraseMap(fieldQuery);
         subMap.Put(term,map);
     }
     return map;
 }
Esempio n. 8
0
        /// <returns>QueryPhraseMap</returns>
        public virtual QueryPhraseMap GetFieldTermMap(string fieldName, string term)
        {
            QueryPhraseMap rootMap = GetRootMap(fieldName);

            if (rootMap == null)
            {
                return(null);
            }
            rootMap.subMap.TryGetValue(term, out QueryPhraseMap result);
            return(result);
        }
Esempio n. 9
0
 public QueryPhraseMap RetrieveQueryFromSubMap(QueryPhraseMap rootMap, String term)
 {
     foreach (var kvp in rootMap.subMap)
     {
         if (StringUtils.TermStringMatch(kvp.Key, term))
         {
             return(kvp.Value);
         }
     }
     return(null);
 }
Esempio n. 10
0
        internal QueryPhraseMap GetRootMap(Query query)
        {
            string key = GetKey(query);

            if (!rootMaps.TryGetValue(key, out QueryPhraseMap map) || map == null)
            {
                map           = new QueryPhraseMap(this);
                rootMaps[key] = map;
            }
            return(map);
        }
Esempio n. 11
0
 public QueryPhraseMap getRootMap(Query query)
 {
     String key = GetKey(query);
     QueryPhraseMap map=rootMaps.Get(key);
     if (map == null)
     {
         map = new QueryPhraseMap(this);
         rootMaps.Put(key,map);
     }
     return map;
 }
Esempio n. 12
0
            public virtual QueryPhraseMap SearchPhrase(IList <TermInfo> phraseCandidate)
            {
                QueryPhraseMap currMap = this;

                foreach (TermInfo ti in phraseCandidate)
                {
                    currMap.subMap.TryGetValue(ti.Text, out currMap);

                    if (currMap == null)
                    {
                        return(null);
                    }
                }
                return(currMap.IsValidTermOrPhrase(phraseCandidate) ? currMap : null);
            }
Esempio n. 13
0
 internal void Add(Query query /*, IndexReader reader // LUCENENET: Never read */)
 {
     if (query is TermQuery termQuery)
     {
         AddTerm(termQuery.Term, query.Boost);
     }
     else if (query is PhraseQuery pq)
     {
         Term[] terms = pq.GetTerms();
         IDictionary <string, QueryPhraseMap> map = subMap;
         QueryPhraseMap qpm = null;
         foreach (Term term in terms)
         {
             qpm = GetOrNewMap(map, term.Text);
             map = qpm.subMap;
         }
         qpm.MarkTerminal(pq.Slop, pq.Boost);
     }
     else
     {
         throw RuntimeException.Create("query \"" + query.ToString() + "\" must be flatten first.");
     }
 }
Esempio n. 14
0
 internal void Add(Query query, IndexReader reader)
 {
     if (query is TermQuery)
     {
         AddTerm(((TermQuery)query).Term, query.Boost);
     }
     else if (query is PhraseQuery)
     {
         PhraseQuery pq    = (PhraseQuery)query;
         Term[]      terms = pq.GetTerms();
         IDictionary <string, QueryPhraseMap> map = subMap;
         QueryPhraseMap qpm = null;
         foreach (Term term in terms)
         {
             qpm = GetOrNewMap(map, term.Text());
             map = qpm.subMap;
         }
         qpm.MarkTerminal(pq.Slop, pq.Boost);
     }
     else
     {
         throw new Exception("query \"" + query.ToString() + "\" must be flatten first.");
     }
 }
Esempio n. 15
0
 public QueryPhraseMap getRootMap(Query query)
 {
     String key = GetKey(query);
     QueryPhraseMap map = rootMaps.Get(key);
     if (map == null)
     {
         map = new QueryPhraseMap(this);
         rootMaps.Put(key, map);
     }
     return map;
 }
Esempio n. 16
0
 /**
  * 
  * @param fieldName
  * @param phraseCandidate
  * @return QueryPhraseMap
  */
 public QueryPhraseMap SearchPhrase(String fieldName, List<TermInfo> phraseCandidate)
 {
     QueryPhraseMap root = GetRootMap(fieldName);
     if (root == null) return null;
     return root.SearchPhrase(phraseCandidate);
 }
Esempio n. 17
0
            internal void AddTerm(Term term, float boost)
            {
                QueryPhraseMap map = GetOrNewMap(subMap, term.Text);

                map.MarkTerminal(boost);
            }
Esempio n. 18
0
        /*
         *
         * <param name="fieldName"></param>
         * <param name="term"></param>
         * <returns>QueryPhraseMap</returns>
         */
        public QueryPhraseMap GetFieldTermMap(String fieldName, String term)
        {
            QueryPhraseMap rootMap = GetRootMap(fieldName);

            return(rootMap == null ? null : RetrieveQueryFromSubMap(rootMap, term));
        }
Esempio n. 19
0
            public void AddTerm(String termText, float boost)
            {
                QueryPhraseMap map = GetOrNewMap(subMap, termText);

                map.MarkTerminal(boost);
            }
Esempio n. 20
0
 /**
  * 
  * @param fieldName
  * @param term
  * @return QueryPhraseMap
  */
 public QueryPhraseMap GetFieldTermMap(String fieldName, String term)
 {
     QueryPhraseMap rootMap = GetRootMap(fieldName);
     return rootMap == null ? null : rootMap.subMap.Get(term);
 }
Esempio n. 21
0
 private QueryPhraseMap GetOrNewMap(HashMap<String, QueryPhraseMap> subMap, String term)
 {
     QueryPhraseMap map = subMap.Get(term);
     if (map == null)
     {
         map = new QueryPhraseMap(fieldQuery);
         subMap.Put(term, map);
     }
     return map;
 }
Esempio n. 22
0
 public QueryPhraseMap RetrieveQueryFromSubMap(QueryPhraseMap rootMap, String term)
 {
     foreach (var kvp in rootMap.subMap)
     {
         if (StringUtils.TermStringMatch(kvp.Key, term))
             return kvp.Value;
     }
     return null;
 }