Ejemplo n.º 1
0
        public FactBaseQuery Copy()
        {
            var result = new FactBaseQuery();

            result.DictFilterIndexes         = this.DictFilterIndexes.ToArray().ToList();
            result.NegativeDictFilterIndexes = this.NegativeDictFilterIndexes.ToArray().ToList();
            foreach (var childquery in ChildQueries)
            {
                result.AddChildQuery(childquery.Copy());
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static FactBaseQuery GetQuery(string filterstring, Dictionary <string, int> factparts)
        {
            var factstrings = filterstring.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            //TODO
            IList <int> idlist = new List <int>();
            var         keys   = new List <int>();
            var         qry    = new FactBaseQuery();

            foreach (var fs in factstrings)
            {
                var ors = fs.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                if (ors.Length == 1)
                {
                    var oritem     = ors.FirstOrDefault();
                    var isnegative = false;
                    if (oritem.StartsWith("!"))
                    {
                        isnegative = true;
                        oritem     = oritem.Substring(1);
                    }
                    oritem = oritem.Trim();
                    if (factparts.ContainsKey(oritem))
                    {
                        qry.AddIndex(factparts[oritem], isnegative);
                    }
                    else
                    {
                        var partkeys = factparts.Keys.Where(i => i.IndexOf(oritem, StringComparison.InvariantCultureIgnoreCase) > -1).ToList();
                        if (partkeys.Count > 0)
                        {
                            if (isnegative)
                            {
                                foreach (var partkey in partkeys)
                                {
                                    var partqry = new FactBaseQuery();
                                    qry.AddIndex(factparts[partkey], isnegative);
                                }
                            }
                            else
                            {
                                var qrypool = new FactPoolQuery();
                                foreach (var partkey in partkeys)
                                {
                                    var partqry = new FactBaseQuery();
                                    partqry.AddIndex(factparts[partkey], isnegative);
                                    qrypool.AddChildQuery(partqry);
                                }
                                qry.AddChildQuery(qrypool);
                            }
                        }
                        else
                        {
                            qry.DictFilterIndexes.Add(-1);
                        }
                    }
                }
                else
                {
                    var qrypool    = new FactPoolQuery();
                    var isnegative = false;

                    for (int i = 0; i < ors.Length; i++)
                    {
                        var oritem = ors[i];
                        if (oritem.StartsWith("!"))
                        {
                            isnegative = true;
                            oritem     = oritem.Substring(1);
                        }
                        oritem = oritem.Trim();
                        FactBaseQuery subquery = null;
                        if (factparts.ContainsKey(oritem))
                        {
                            subquery = new FactBaseQuery();
                            subquery.AddIndex(factparts[oritem], isnegative);
                        }
                        else
                        {
                            var partkeys = factparts.Keys.Where(k => k.IndexOf(oritem, StringComparison.InvariantCultureIgnoreCase) > -1).ToList();
                            if (partkeys.Count > 0 && !String.IsNullOrEmpty(oritem))
                            {
                                if (isnegative)
                                {
                                    subquery = new FactBaseQuery();

                                    foreach (var partkey in partkeys)
                                    {
                                        var partqry = new FactBaseQuery();
                                        subquery.AddIndex(factparts[partkey], isnegative);
                                    }
                                }
                                else
                                {
                                    subquery = new FactPoolQuery();
                                    foreach (var partkey in partkeys)
                                    {
                                        var partqry = new FactBaseQuery();
                                        partqry.AddIndex(factparts[partkey], isnegative);
                                        subquery.AddChildQuery(partqry);
                                    }
                                }
                            }
                            else
                            {
                                qry.DictFilterIndexes.Add(-1);
                            }
                        }
                        qrypool.AddChildQuery(subquery);
                    }
                    qry.AddChildQuery(qrypool);
                }
            }
            if (!qry.HasFilters())
            {
                return(null);
            }
            else
            {
                return(qry);
            }
        }