コード例 #1
0
ファイル: QueryTranslator.cs プロジェクト: daszat/zetbox
 protected virtual BooleanQuery VisitBooleanQuery(BooleanQuery b)
 {
     var qry = new BooleanQuery(b.IsCoordDisabled());
     foreach (var c in b.GetClauses())
     {
         qry.Add(new BooleanClause(VisitQuery(c.Query), c.Occur));
     }
     return qry;
 }
コード例 #2
0
ファイル: Query.cs プロジェクト: restran/lucene-file-finder
        /// <summary>Expert: called when re-writing queries under MultiSearcher.
        ///
        /// Create a single query suitable for use by all subsearchers (in 1-1
        /// correspondence with queries). This is an optimization of the OR of
        /// all queries. We handle the common optimization cases of equal
        /// queries and overlapping clauses of boolean OR queries (as generated
        /// by MultiTermQuery.rewrite() and RangeQuery.rewrite()).
        /// Be careful overriding this method as queries[0] determines which
        /// method will be called and is not necessarily of the same type as
        /// the other queries.
        /// </summary>
        public virtual Query Combine(Query[] queries)
        {
            System.Collections.Hashtable uniques = new System.Collections.Hashtable();
            for (int i = 0; i < queries.Length; i++)
            {
                Query           query   = queries[i];
                BooleanClause[] clauses = null;
                // check if we can split the query into clauses
                bool splittable = (query is BooleanQuery);
                if (splittable)
                {
                    BooleanQuery bq = (BooleanQuery)query;
                    splittable = bq.IsCoordDisabled();
                    clauses    = bq.GetClauses();
                    for (int j = 0; splittable && j < clauses.Length; j++)
                    {
                        splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD);
                    }
                }
                if (splittable)
                {
                    for (int j = 0; j < clauses.Length; j++)
                    {
                        Query tmp = clauses[j].GetQuery();
                        if (uniques.Contains(tmp) == false)
                        {
                            uniques.Add(tmp, tmp);
                        }
                    }
                }
                else
                {
                    if (uniques.Contains(query) == false)
                    {
                        uniques.Add(query, query);
                    }
                }
            }
            // optimization: if we have just one query, just return it
            if (uniques.Count == 1)
            {
                System.Collections.IDictionaryEnumerator iter = uniques.GetEnumerator();
                iter.MoveNext();
                return(iter.Value as Query);
            }
            System.Collections.IDictionaryEnumerator it = uniques.GetEnumerator();
            BooleanQuery result = new BooleanQuery(true);

            while (it.MoveNext())
            {
                result.Add((Query)it.Value, BooleanClause.Occur.SHOULD);
            }
            return(result);
        }
コード例 #3
0
ファイル: LucQueryVisitor.cs プロジェクト: jhuntsman/FlexNet
        public virtual Query VisitBooleanQuery(BooleanQuery booleanq)
        {
            var clauses = booleanq.GetClauses();
            var visitedClauses = VisitBooleanClauses(clauses);
            BooleanQuery newQuery = null;
            if (visitedClauses != clauses)
            {
                newQuery = new BooleanQuery(booleanq.IsCoordDisabled());
                for (int i = 0; i < visitedClauses.Length; i++)
                    newQuery.Add(visitedClauses[i]);
            }
            return newQuery ?? booleanq;

        }
コード例 #4
0
ファイル: DumpVisitor.cs プロジェクト: jhuntsman/FlexNet
 public override Query VisitBooleanQuery(BooleanQuery booleanq)
 {
     _dump.Append("BoolQ(");
     var clauses = booleanq.GetClauses();
     var visitedClauses = VisitBooleanClauses(clauses);
     BooleanQuery newQuery = null;
     if (visitedClauses != clauses)
     {
         newQuery = new BooleanQuery(booleanq.IsCoordDisabled());
         for (int i = 0; i < visitedClauses.Length; i++)
             newQuery.Add(clauses[i]);
     }
     _dump.Append(")");
     return newQuery ?? booleanq;
 }
コード例 #5
0
ファイル: Query.cs プロジェクト: vivekshimpi01/lucene.net
        /// <summary>Expert: called when re-writing queries under MultiSearcher.
        ///
        /// Create a single query suitable for use by all subsearchers (in 1-1
        /// correspondence with queries). This is an optimization of the OR of
        /// all queries. We handle the common optimization cases of equal
        /// queries and overlapping clauses of boolean OR queries (as generated
        /// by MultiTermQuery.rewrite()).
        /// Be careful overriding this method as queries[0] determines which
        /// method will be called and is not necessarily of the same type as
        /// the other queries.
        /// </summary>
        public virtual Query Combine(Query[] queries)
        {
            System.Collections.Hashtable uniques = new System.Collections.Hashtable();
            for (int i = 0; i < queries.Length; i++)
            {
                Query           query   = queries[i];
                BooleanClause[] clauses = null;
                // check if we can split the query into clauses
                bool splittable = (query is BooleanQuery);
                if (splittable)
                {
                    BooleanQuery bq = (BooleanQuery)query;
                    splittable = bq.IsCoordDisabled();
                    clauses    = bq.GetClauses();
                    for (int j = 0; splittable && j < clauses.Length; j++)
                    {
                        splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD);
                    }
                }
                if (splittable)
                {
                    for (int j = 0; j < clauses.Length; j++)
                    {
                        SupportClass.CollectionsHelper.AddIfNotContains(uniques, clauses[j].GetQuery());
                    }
                }
                else
                {
                    SupportClass.CollectionsHelper.AddIfNotContains(uniques, query);
                }
            }
            // optimization: if we have just one query, just return it
            if (uniques.Count == 1)
            {
                foreach (object key in uniques.Keys)
                {
                    return((Query)key);
                }
            }
            BooleanQuery result = new BooleanQuery(true);

            foreach (object key in uniques.Keys)
            {
                result.Add((Query)key, BooleanClause.Occur.SHOULD);
            }
            return(result);
        }
コード例 #6
0
ファイル: Query.cs プロジェクト: pchaozhong/FlexNet
        /// <summary>Expert: called when re-writing queries under MultiSearcher.
        ///
        /// Create a single query suitable for use by all subsearchers (in 1-1
        /// correspondence with queries). This is an optimization of the OR of
        /// all queries. We handle the common optimization cases of equal
        /// queries and overlapping clauses of boolean OR queries (as generated
        /// by MultiTermQuery.rewrite()).
        /// Be careful overriding this method as queries[0] determines which
        /// method will be called and is not necessarily of the same type as
        /// the other queries.
        /// </summary>
        public virtual Query Combine(params Query[] queries)
        {
            Support.Set <Query> uniques = new Support.Set <Query>();
            for (int i = 0; i < queries.Length; i++)
            {
                Query           query   = queries[i];
                BooleanClause[] clauses = null;
                // check if we can split the query into clauses
                bool splittable = (query is BooleanQuery);
                if (splittable)
                {
                    BooleanQuery bq = (BooleanQuery)query;
                    splittable = bq.IsCoordDisabled();
                    clauses    = bq.GetClauses();
                    for (int j = 0; splittable && j < clauses.Length; j++)
                    {
                        splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD);
                    }
                }
                if (splittable)
                {
                    for (int j = 0; j < clauses.Length; j++)
                    {
                        uniques.Add(clauses[j].GetQuery());
                    }
                }
                else
                {
                    uniques.Add(query);
                }
            }
            // optimization: if we have just one query, just return it
            if (uniques.Count == 1)
            {
                foreach (Query key in uniques)
                {
                    return((Query)key);
                }
            }
            BooleanQuery result = new BooleanQuery(true);

            foreach (Query key in uniques)
            {
                result.Add(key, BooleanClause.Occur.SHOULD);
            }
            return(result);
        }
コード例 #7
0
ファイル: Query.cs プロジェクト: ravendb/lucenenet
        /// <summary>Expert: called when re-writing queries under MultiSearcher.
        ///
        /// Create a single query suitable for use by all subsearchers (in 1-1
        /// correspondence with queries). This is an optimization of the OR of
        /// all queries. We handle the common optimization cases of equal
        /// queries and overlapping clauses of boolean OR queries (as generated
        /// by MultiTermQuery.rewrite()).
        /// Be careful overriding this method as queries[0] determines which
        /// method will be called and is not necessarily of the same type as
        /// the other queries.
        /// </summary>
        public virtual Query Combine(Query[] queries)
        {
            var uniques = new System.Collections.Generic.HashSet <Query>();

            for (int i = 0; i < queries.Length; i++)
            {
                Query           query   = queries[i];
                BooleanClause[] clauses = null;
                // check if we can split the query into clauses
                bool splittable = (query is BooleanQuery);
                if (splittable)
                {
                    BooleanQuery bq = (BooleanQuery)query;
                    splittable = bq.IsCoordDisabled();
                    clauses    = bq.GetClauses();
                    for (int j = 0; splittable && j < clauses.Length; j++)
                    {
                        splittable = (clauses[j].Occur == Occur.SHOULD);
                    }
                }
                if (splittable)
                {
                    for (int j = 0; j < clauses.Length; j++)
                    {
                        uniques.Add(clauses[j].Query);
                    }
                }
                else
                {
                    uniques.Add(query);
                }
            }
            // optimization: if we have just one query, just return it
            if (uniques.Count == 1)
            {
                return(uniques.First());
            }
            BooleanQuery result = new BooleanQuery(true);

            foreach (Query key in uniques)
            {
                result.Add(key, Occur.SHOULD);
            }
            return(result);
        }