Exemplo n.º 1
0
        private static string GetSimpleQueryCore <T>(string query, Rule[] rules)
            where T : class
        {
            query = query?.Trim();
            if (query == null)
            {
                return(null);
            }
            else if (string.IsNullOrEmpty(query) || query == "*")
            {
                return("");
            }

            string regexPrefix   = @"(^|\s|[(])";
            string regexTemplate = "{0}(?<q>(-|\\w)*)\\s*";

            string modifiedQ = query; //FixInvalidQuery(query) ?? "";

            //check invalid query ( tag: missing value)

            for (int i = 0; i < rules.Length; i++)
            {
                string lookFor       = regexPrefix + rules[i].LookFor;
                string replaceWith   = rules[i].ReplaceWith;
                bool   doFullReplace = rules[i].FullReplace;



                MatchEvaluator evalMatch = (m) =>
                {
                    var s = m.Value;
                    if (string.IsNullOrEmpty(s))
                    {
                        return(string.Empty);
                    }
                    var newVal = replaceWith;
                    if (newVal.Contains("${q}"))
                    {
                        var capt    = m.Groups["q"].Captures;
                        var captVal = "";
                        foreach (Capture c in capt)
                        {
                            if (c.Value.Length > captVal.Length)
                            {
                                captVal = c.Value;
                            }
                        }

                        newVal = newVal.Replace("${q}", captVal);
                    }
                    if (s.StartsWith("("))
                    {
                        return(" (" + newVal);
                    }
                    else
                    {
                        return(" " + newVal);
                    }
                };

                //if (modifiedQ.ToLower().Contains(lookFor.ToLower()))
                if (Regex.IsMatch(modifiedQ, lookFor, regexQueryOption))
                {
                    Match  mFirst     = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                    string foundValue = mFirst.Groups["q"].Value;


                    if (doFullReplace &&
                        !string.IsNullOrEmpty(replaceWith) &&
                        (
                            lookFor.Contains("holding:")
                            //RS
                            || lookFor.Contains("holdingprijemce:") ||
                            lookFor.Contains("holdingplatce:")
                            //insolvence
                            || lookFor.Contains("holdingdluznik:") ||
                            lookFor.Contains("holdingveritel:") ||
                            lookFor.Contains("holdingspravce:")
                            //VZ
                            || lookFor.Contains("holdingdodavatel:") ||
                            lookFor.Contains("holdingzadavatel:")
                        )
                        )
                    {
                        //list of ICO connected to this holding
                        Match  m          = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string holdingIco = m.Groups["q"].Value;
                        HlidacStatu.Lib.Data.Relation.AktualnostType aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;
                        Data.Firma f = Data.Firmy.Get(holdingIco);
                        if (f != null && f.Valid)
                        {
                            var icos = new string[] { f.ICO }
                            .Union(
                                f.AktualniVazby(aktualnost)
                                .Select(s => s.To.Id)
                                )
                            .Distinct();
                            string icosQuery    = "";
                            var    icosPresLidi = f.AktualniVazby(aktualnost)
                                                  .Where(o => o.To.Type == Data.Graph.Node.NodeType.Person)
                                                  .Select(o => Data.Osoby.GetById.Get(Convert.ToInt32(o.To.Id)))
                                                  .Where(o => o != null)
                                                  .SelectMany(o => o.AktualniVazby(aktualnost))
                                                  .Select(v => v.To.Id)
                                                  .Distinct();
                            icos = icos.Union(icosPresLidi).Distinct();

                            var templ = $" ( {replaceWith}:{{0}} ) ";
                            if (replaceWith.Contains("${q}"))
                            {
                                templ = $" ( {replaceWith.Replace("${q}", "{0}")} )";
                            }

                            if (icos != null && icos.Count() > 0)
                            {
                                icosQuery = " ( " + icos
                                            .Select(t => string.Format(templ, t))
                                            .Aggregate((fi, s) => fi + " OR " + s) + " ) ";
                            }
                            else
                            {
                                icosQuery = string.Format(templ, "noOne"); //$" ( {icoprefix}:noOne ) ";
                            }
                            if (!string.IsNullOrEmpty(rules[i].AddLastCondition))
                            {
                                if (rules[i].AddLastCondition.Contains("${q}"))
                                {
                                    rules[i].AddLastCondition = rules[i].AddLastCondition.Replace("${q}", foundValue);
                                }

                                icosQuery = ModifyQueryOR(icosQuery, rules[i].AddLastCondition);

                                rules[i].AddLastCondition = null; //done, don't do it anywhere
                            }

                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " (" + icosQuery + ") ", regexQueryOption);
                        }
                    } //do regex replace
                    else if (doFullReplace &&
                             !string.IsNullOrEmpty(replaceWith) &&
                             (
                                 lookFor.Contains("osobaid:") ||
                                 lookFor.Contains("osobaiddluznik:") ||
                                 lookFor.Contains("osobaidveritel:") ||
                                 lookFor.Contains("osobaidspravce:") ||
                                 lookFor.Contains("osobaidzadavatel:") ||
                                 lookFor.Contains("osobaiddodavatel:")
                             )
                             )//(replaceWith.Contains("${ico}"))
                    {
                        //list of ICO connected to this person
                        Match      m         = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string     nameId    = m.Groups["q"].Value;
                        Data.Osoba p         = Data.Osoby.GetByNameId.Get(nameId);
                        string     icosQuery = "";

                        //string icoprefix = replaceWith;
                        var templ = $" ( {replaceWith}:{{0}} ) ";
                        if (replaceWith.Contains("${q}"))
                        {
                            templ = $" ( {replaceWith.Replace("${q}", "{0}")} )";
                        }



                        if (p != null)
                        {
                            var icos = p
                                       .AktualniVazby(Data.Relation.AktualnostType.Nedavny)
                                       .Where(w => !string.IsNullOrEmpty(w.To.Id))
                                       //.Where(w => Analysis.ACore.GetBasicStatisticForICO(w.To.Id).Summary.Pocet > 0)
                                       .Select(w => w.To.Id)
                                       .Distinct().ToArray();


                            if (icos != null && icos.Length > 0)
                            {
                                icosQuery = " ( " + icos
                                            .Select(t => string.Format(templ, t))
                                            .Aggregate((f, s) => f + " OR " + s) + " ) ";
                            }
                            else
                            {
                                icosQuery = string.Format(templ, "noOne"); //$" ( {icoprefix}:noOne ) ";
                            }
                            if (!string.IsNullOrEmpty(rules[i].AddLastCondition))
                            {
                                if (rules[i].AddLastCondition.Contains("${q}"))
                                {
                                    rules[i].AddLastCondition = rules[i].AddLastCondition.Replace("${q}", foundValue);
                                }

                                icosQuery = ModifyQueryOR(icosQuery, rules[i].AddLastCondition);

                                rules[i].AddLastCondition = null; //done, don't do it anywhere
                            }
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " (" + icosQuery + ") ", regexQueryOption);
                        }
                        else
                        {
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " (" + string.Format(templ, "noOne") + ") ", regexQueryOption);
                        }
                    }

                    //VZ
                    else if (doFullReplace && replaceWith.Contains("${oblast}"))
                    {
                        string cpv = "";
                        if (replaceWith.Contains("${oblast}"))
                        {
                            var oblastVal = ParseTools.GetRegexGroupValue(modifiedQ, @"oblast:(?<oblast>\w*)", "oblast");
                            var cpvs      = Lib.Data.VZ.VerejnaZakazka.Searching.CPVOblastToCPV(oblastVal);
                            if (cpvs != null)
                            {
                                var q_cpv = "cPV:(" + cpvs.Select(s => s + "*").Aggregate((f, s) => f + " OR " + s) + ")";
                                modifiedQ = Regex.Replace(modifiedQ, @"oblast:(?<oblast>\w*)", q_cpv, regexQueryOption);
                            }
                        }
                    }
                    //VZs
                    else if (doFullReplace && replaceWith.Contains("${cpv}"))
                    {
                        string cpv = "";
                        //Match m = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        //string cpv = "";
                        //if (m.Success)
                        //    cpv = m.Groups["q"].Value;
                        cpv     = ParseTools.GetRegexGroupValue(modifiedQ, @"cpv:(?<q>(-|,|\d)*)\s*", "q");
                        lookFor = @"cpv:(?<q>(-|,|\d)*)\s*";
                        if (!string.IsNullOrEmpty(cpv))
                        {
                            string[] cpvs  = cpv.Split(new char[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                            string   q_cpv = "";
                            if (cpvs.Length > 0)
                            {
                                q_cpv = "cPV:(" + cpvs.Select(s => s + "*").Aggregate((f, s) => f + " OR " + s) + ")";
                            }

                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " (" + q_cpv + ") ", regexQueryOption);
                        }
                        else
                        {
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " ", regexQueryOption);
                        }
                    }
                    //VZ
                    else if (doFullReplace && replaceWith.Contains("${form}"))
                    {
                        lookFor = @"form:(?<q>((F|CZ)\d{1,2}(,)?)*)\s*";
                        Match  m    = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string form = "";
                        if (m.Success)
                        {
                            form = m.Groups["q"].Value;
                        }
                        if (!string.IsNullOrEmpty(form))
                        {
                            string[] forms  = form.Split(new char[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                            string   q_form = "";
                            if (forms.Length > 0)
                            {
                                q_form = "formulare.druh:(" + forms.Select(s => s + "*").Aggregate((f, s) => f + " OR " + s) + ")";
                            }

                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " (" + q_form + ") ", regexQueryOption);
                        }
                        else
                        {
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, " ", regexQueryOption);
                        }
                    }

                    else if (replaceWith.Contains("${q}"))
                    {
                        modifiedQ = Regex.Replace(modifiedQ, string.Format(regexTemplate, lookFor), evalMatch, regexQueryOption);
                    } //do regex replace

                    else if (doFullReplace && lookFor.Contains("chyby:"))
                    {
                        string levelVal = ParseTools.GetRegexGroupValue(modifiedQ, @"chyby:(?<level>\w*)", "level")?.ToLower() ?? "";
                        string levelQ   = "";
                        if (levelVal == "fatal" || levelVal == "zasadni")
                        {
                            levelQ = Lib.Issues.Util.IssuesByLevelQuery(Lib.Issues.ImportanceLevel.Fatal);
                        }
                        else if (levelVal == "major" || levelVal == "vazne")
                        {
                            levelQ = Lib.Issues.Util.IssuesByLevelQuery(Lib.Issues.ImportanceLevel.Major);
                        }

                        if (!string.IsNullOrEmpty(levelQ))
                        {
                            modifiedQ = Regex.Replace(modifiedQ, @"chyby:(\w*)", levelQ, regexQueryOption);
                        }
                    }
                    else if (!string.IsNullOrEmpty(replaceWith))
                    {
                        modifiedQ = Regex.Replace(modifiedQ, lookFor, evalMatch, regexQueryOption);
                    }

                    if (!string.IsNullOrEmpty(rules[i].AddLastCondition))
                    {
                        if (rules[i].AddLastCondition.Contains("${q}"))
                        {
                            rules[i].AddLastCondition = rules[i].AddLastCondition.Replace("${q}", foundValue);
                        }

                        modifiedQ = ModifyQueryOR(modifiedQ, rules[i].AddLastCondition);
                    }
                }
            }

            return(modifiedQ);
        }
Exemplo n.º 2
0
        public static QueryContainer GetSimpleQuery(DataSet ds, string origQuery)
        {
            if (origQuery == null)
            {
                return(new QueryContainerDescriptor <object>().MatchNone());
            }

            var query = origQuery.Trim();

            if (string.IsNullOrEmpty(query) || query == "*")
            {
                return(new QueryContainerDescriptor <object>().MatchAll());
            }


            string regexPrefix   = @"(^|\s|[(])";
            string regexTemplate = "{0}(?<q>(-|\\w)*)\\s*";

            //fix field prefixes
            //ds: ->
            string[,] rules = new string[, ] {
                { regexPrefix + "ico:", "${ico}" },
                { @"osobaid:(?<q>((\w{1,} [-]{1} \w{1,})([-]{1} \d{1,3})?)) (\s|$){1,}", "${ico}" },
                { @"holding:(?<q>(\d{1,8})) (\s|$){1,}", "${ico}" },
            };


            string modifiedQ = query; // ES.SearchTools.FixInvalidQuery(query, queryShorcuts, queryOperators) ?? "";

            //check invalid query ( tag: missing value)



            for (int i = 0; i < rules.GetLength(0); i++)
            {
                string lookFor     = rules[i, 0];
                string replaceWith = rules[i, 1];

                MatchEvaluator evalMatch = (m) =>
                {
                    var s = m.Value;
                    if (string.IsNullOrEmpty(s))
                    {
                        return(string.Empty);
                    }
                    var newVal = replaceWith;
                    if (newVal.Contains("${q}"))
                    {
                        newVal = newVal.Replace("${q}", m.Groups["q"].Value);
                    }
                    if (s.StartsWith("("))
                    {
                        return(" (" + newVal);
                    }
                    else
                    {
                        return(" " + newVal);
                    }
                };

                //if (modifiedQ.ToLower().Contains(lookFor.ToLower()))
                if (Regex.IsMatch(modifiedQ, lookFor, regexQueryOption))
                {
                    if (replaceWith.Contains("${q}"))
                    {
                        modifiedQ = Regex.Replace(modifiedQ, string.Format(regexTemplate, lookFor), evalMatch, regexQueryOption);
                    } //do regex replace
                      //else if (replaceWith.Contains("${zahajeny}") && )
                      //{
                      //    modifiedQ = Regex.Replace(modifiedQ, lookFor, "stavVZ:<=100", regexQueryOption);
                      //} //do regex replace
                    else if (lookFor.Contains("holding:"))
                    {
                        //list of ICO connected to this person
                        Match  m          = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string holdingIco = m.Groups["q"].Value;
                        HlidacStatu.Lib.Data.Relation.AktualnostType aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;

                        var icoQuerypath = HlidacStatu.Lib.Data.External.DataSets.Search.GetSpecificQueriesForDataset(ds, "ICO", "{0}");
                        if (!string.IsNullOrEmpty(icoQuerypath))
                        {
                            Data.Firma f = Data.Firmy.Get(holdingIco);
                            if (f != null && f.Valid)
                            {
                                var icos = new string[] { f.ICO }
                                .Union(
                                    f.AktualniVazby(aktualnost)
                                    .Select(s => s.To.Id)
                                    )
                                .Distinct();
                                string icosQuery    = "";
                                var    icosPresLidi = f.AktualniVazby(aktualnost)
                                                      .Where(o => o.To.Type == Graph.Node.NodeType.Person)
                                                      .Select(o => Data.Osoby.GetById.Get(Convert.ToInt32(o.To.Id)))
                                                      .Where(o => o != null)
                                                      .SelectMany(o => o.AktualniVazby(aktualnost))
                                                      .Select(v => v.To.Id)
                                                      .Distinct();
                                icos = icos.Union(icosPresLidi).Distinct();


                                var icoquerypath = HlidacStatu.Lib.Data.External.DataSets.Search.GetSpecificQueriesForDataset(ds, "ICO", "{0}");

                                var templ = "(ico:{0})";
                                if (!string.IsNullOrEmpty(icoquerypath))
                                {
                                    templ = icoquerypath;
                                }

                                if (icos != null && icos.Count() > 0)
                                {
                                    icosQuery = "(" + icos
                                                .Select(t => string.Format(templ, t))
                                                .Aggregate((fi, s) => fi + " OR " + s) + ")";
                                }
                                else
                                {
                                    icosQuery = "(ico:noOne)";
                                }
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                            }
                        }
                    } //do regex replace
                    else if (lookFor.Contains("osobaid:"))
                    {
                        //list of ICO connected to this person
                        Match  m      = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string nameId = m.Groups["q"].Value;


                        var osobaidQuerypath = HlidacStatu.Lib.Data.External.DataSets.Search.GetSpecificQueriesForDataset(ds, "OsobaId", "{0}");
                        var icoQuerypath     = HlidacStatu.Lib.Data.External.DataSets.Search.GetSpecificQueriesForDataset(ds, "ICO", "{0}");
                        if (!string.IsNullOrEmpty(osobaidQuerypath) || !string.IsNullOrEmpty(icoQuerypath))
                        {
                            Data.Osoba p         = Data.Osoby.GetByNameId.Get(nameId);
                            string     icosQuery = "";
                            if (p != null)
                            {
                                var icos = p
                                           .AktualniVazby(Data.Relation.AktualnostType.Nedavny)
                                           .Where(w => !string.IsNullOrEmpty(w.To.Id))
                                           //.Where(w => Analysis.ACore.GetBasicStatisticForICO(w.To.Id).Summary.Pocet > 0)
                                           .Select(w => w.To.Id)
                                           .Distinct().ToArray();
                                if (icos != null && icos.Length > 0 && !string.IsNullOrEmpty(icoQuerypath))
                                {
                                    icosQuery = "(" + icos
                                                .Select(t => string.Format(icoQuerypath, t))
                                                .Aggregate((f, s) => f + " OR " + s) + ")";
                                }
                                if (!string.IsNullOrEmpty(osobaidQuerypath))
                                {
                                    if (icosQuery.Length > 0)
                                    {
                                        icosQuery = icosQuery + " OR ";
                                    }
                                    icosQuery = icosQuery + string.Format(osobaidQuerypath, nameId);
                                }
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery.Trim(), regexQueryOption).Trim();
                                if (modifiedQ == "")
                                {
                                    return(new QueryContainerDescriptor <object>().MatchNone());
                                }
                            }
                        }
                    }
                    else if (lookFor.Contains("ico:"))
                    {
                        //list of ICO connected to this person
                        var ico = HlidacStatu.Util.ParseTools.GetRegexGroupValue(modifiedQ, @"ico:(?<ico>\d*)", "ico");


                        //string ico = m.Groups[1].Value;
                        string icosQuery    = "";
                        var    icoQuerypath = HlidacStatu.Lib.Data.External.DataSets.Search.GetSpecificQueriesForDataset(ds, "ICO", "{0}");
                        if (!string.IsNullOrEmpty(icoQuerypath))
                        {
                            var templ = "(ico:{0})";
                            if (!string.IsNullOrEmpty(icoQuerypath))
                            {
                                templ = icoQuerypath;
                            }

                            icosQuery = string.Format(templ, ico).Trim();
                            modifiedQ = Regex.Replace(modifiedQ, @"ico:(?<ico>\d*)", icosQuery, regexQueryOption);
                        }
                    }
                    else
                    {
                        modifiedQ = Regex.Replace(modifiedQ, lookFor, evalMatch, regexQueryOption);
                    }
                }
            }


            QueryContainer qc = null;

            if (modifiedQ == null)
            {
                qc = new QueryContainerDescriptor <VZ.VerejnaZakazka>().MatchNone();
            }
            else if (string.IsNullOrEmpty(modifiedQ))
            {
                qc = new QueryContainerDescriptor <VZ.VerejnaZakazka>().MatchAll();
            }
            else
            {
                modifiedQ = modifiedQ.Replace(" | ", " OR ").Trim();
                qc        = new QueryContainerDescriptor <VZ.VerejnaZakazka>()
                            .QueryString(qs => qs
                                         .Query(modifiedQ)
                                         .DefaultOperator(Operator.And)
                                         );
            }

            return(qc);
        }
Exemplo n.º 3
0
        public static QueryContainer GetSimpleQuery(string query)
        {
            query = query?.Trim();
            if (string.IsNullOrEmpty(query) || query == "*")
            {
                return(new QueryContainerDescriptor <Lib.Data.Smlouva>().MatchAll());
            }


            string regexPrefix   = @"(^|\s|[(])";
            string regexTemplate = "{0}(?<q>(-|\\w)*)\\s*";

            //fix field prefixes
            //ds: ->
            string[,] rules = new string[, ] {
                { @"osobaid:(?<q>((\w{1,} [-]{1} \w{1,})([-]{1} \d{1,3})?)) (\s|$){1,}", "${ico}" },
                { @"holding:(?<q>(\d{1,8})) (\s|$){1,}", "${ico}" },
                { "ds:", "(prijemce.datovaSchranka:${q} OR platce.datovaSchranka:${q}) " },
                { "dsprijemce:", "prijemce.datovaSchranka:" },
                { "dsplatce:", "platce.datovaSchranka:" },
                { regexPrefix + "ico:", "(prijemce.ico:${q} OR platce.ico:${q}) " },
                { regexPrefix + "icoprijemce:", "prijemce.ico:" },
                { regexPrefix + "icoplatce:", "platce.ico:" },
                { "jmenoprijemce:", "prijemce.nazev:" },
                { "jmenoplatce:", "platce.nazev:" },
                { regexPrefix + "id:", "id:" },
                { "idverze:", "id:" },
                { regexPrefix + "idsmlouvy:", "identifikator.idSmlouvy:" },
                { "predmet:", "predmet:" },
                { "cislosmlouvy:", "cisloSmlouvy:" },
                { regexPrefix + "mena:", "ciziMena.mena:" },
                { "cenasdph:", "hodnotaVcetneDph:" },
                { "cenabezdph:", "hodnotaBezDph:" },
                { "cena:", "calculatedPriceWithVATinCZK:" },
                { "zverejneno:\\[", "casZverejneni:[" },
                { "zverejneno:(?=[<>])", "casZverejneni:${q}" },
                { "zverejneno:(?=\\d)", "casZverejneni:[${q} TO ${q}||+1d]" },
                { "podepsano:\\[", "datumUzavreni:[" },
                { "podepsano:(?=[<>])", "datumUzavreni:${q}" },
                { "podepsano:(?=\\d)", "datumUzavreni:[${q} TO ${q}||+1d]" },
                { "schvalil:", "schvalil:" },
                { "textsmlouvy:", "prilohy.plainTextContent:" },
                { "chyby:", "${level}" },
            };

            string modifiedQ = query; //FixInvalidQuery(query) ?? "";

            //check invalid query ( tag: missing value)

            for (int i = 0; i < rules.GetLength(0); i++)
            {
                string lookFor     = rules[i, 0];
                string replaceWith = rules[i, 1];

                MatchEvaluator evalMatch = (m) =>
                {
                    var s = m.Value;
                    if (string.IsNullOrEmpty(s))
                    {
                        return(string.Empty);
                    }
                    var newVal = replaceWith;
                    if (newVal.Contains("${q}"))
                    {
                        newVal = newVal.Replace("${q}", m.Groups["q"].Value);
                    }
                    if (s.StartsWith("("))
                    {
                        return(" (" + newVal);
                    }
                    else
                    {
                        return(" " + newVal);
                    }
                };

                //if (modifiedQ.ToLower().Contains(lookFor.ToLower()))
                if (Regex.IsMatch(modifiedQ, lookFor, regexQueryOption))
                {
                    if (replaceWith.Contains("${q}"))
                    {
                        modifiedQ = Regex.Replace(modifiedQ, string.Format(regexTemplate, lookFor), evalMatch, regexQueryOption);
                    } //do regex replace
                    else if (lookFor.Contains("holding:"))
                    {
                        //list of ICO connected to this person
                        Match  m          = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string holdingIco = m.Groups["q"].Value;
                        HlidacStatu.Lib.Data.Relation.AktualnostType aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;
                        Data.Firma f = Data.Firmy.Get(holdingIco);
                        if (f != null && f.Valid)
                        {
                            var icos = new string[] { f.ICO }
                            .Union(
                                f.AktualniVazby(aktualnost)
                                .Select(s => s.To.Id)
                                )
                            .Distinct();
                            string icosQuery    = "";
                            var    icosPresLidi = f.AktualniVazby(aktualnost)
                                                  .Where(o => o.To.Type == Data.Graph.Node.NodeType.Person)
                                                  .Select(o => Data.Osoby.GetById.Get(Convert.ToInt32(o.To.Id)))
                                                  .Where(o => o != null)
                                                  .SelectMany(o => o.AktualniVazby(aktualnost))
                                                  .Select(v => v.To.Id)
                                                  .Distinct();
                            icos = icos.Union(icosPresLidi).Distinct();
                            var templ = "(ico:{0})";
                            if (icos != null && icos.Count() > 0)
                            {
                                icosQuery = "(" + icos
                                            .Select(t => string.Format(templ, t))
                                            .Aggregate((fi, s) => fi + " OR " + s) + ")";
                            }
                            else
                            {
                                icosQuery = "(ico:noOne)";
                            }
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                        }
                    } //do regex replace
                    else if (replaceWith.Contains("${ico}"))
                    {
                        //list of ICO connected to this person
                        Match      m         = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string     nameId    = m.Groups["q"].Value;
                        Data.Osoba p         = Data.Osoby.GetByNameId.Get(nameId);
                        string     icosQuery = "";
                        if (p != null)
                        {
                            var icos = p
                                       .AktualniVazby(Data.Relation.AktualnostType.Nedavny)
                                       .Where(w => !string.IsNullOrEmpty(w.To.Id))
                                       .Where(w => Analysis.ACore.GetBasicStatisticForICO(w.To.Id).Summary.Pocet > 0)
                                       .Select(w => w.To.Id)
                                       .Distinct().ToArray();
                            var templ = "(ico:{0})";
                            if (icos != null && icos.Length > 0)
                            {
                                icosQuery = "(" + icos
                                            .Select(t => string.Format(templ, t))
                                            .Aggregate((f, s) => f + " OR " + s) + ")";
                            }
                            else
                            {
                                icosQuery = "(ico:noOne)";
                            }
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                        }
                        else
                        {
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, "(ico:noOne)", regexQueryOption);
                        }
                    }
                    else if (replaceWith.Contains("${level}"))
                    {
                        string levelVal = ParseTools.GetRegexGroupValue(modifiedQ, @"chyby:(?<level>\w*)", "level")?.ToLower() ?? "";
                        string levelQ   = "";
                        if (levelVal == "fatal" || levelVal == "zasadni")
                        {
                            levelQ = Lib.Issues.Util.IssuesByLevelQuery(Lib.Issues.ImportanceLevel.Fatal);
                        }
                        else if (levelVal == "major" || levelVal == "vazne")
                        {
                            levelQ = Lib.Issues.Util.IssuesByLevelQuery(Lib.Issues.ImportanceLevel.Major);
                        }

                        if (!string.IsNullOrEmpty(levelQ))
                        {
                            modifiedQ = Regex.Replace(modifiedQ, @"chyby:(\w*)", levelQ, regexQueryOption);
                        }
                    }
                    else
                    {
                        modifiedQ = Regex.Replace(modifiedQ, lookFor, evalMatch, regexQueryOption);
                    }
                }
            }

            QueryContainer qc = null;

            if (modifiedQ == null)
            {
                qc = new QueryContainerDescriptor <Lib.Data.Smlouva>().MatchNone();
            }
            else if (string.IsNullOrEmpty(modifiedQ))
            {
                qc = new QueryContainerDescriptor <Lib.Data.Smlouva>().MatchAll();
            }
            else
            {
                modifiedQ = modifiedQ.Replace(" | ", " OR ").Trim();
                qc        = new QueryContainerDescriptor <Lib.Data.Smlouva>()
                            .QueryString(qs => qs
                                         .Query(modifiedQ)
                                         .DefaultOperator(Operator.And)
                                         );
            }

            return(qc);
        }
Exemplo n.º 4
0
        public static QueryContainer GetSimpleQuery(InsolvenceSearchResult searchdata)
        {
            var query = searchdata.Q;


            string regexPrefix   = @"(^|\s|[(])";
            string regexTemplate = "{0}(?<q>(-|\\w)*)\\s*";

            //fix field prefixes
            //ds: ->
            string[,] rules = new string[, ] {
                { @"osobaid:(?<q>((\w{1,} [-]{1} \w{1,})([-]{1} \d{1,3})?)) (\s|$){1,}", "${ico}" },
                { @"holding:(?<q>(\d{1,8})) (\s|$){1,}", "${ico}" },
                { regexPrefix + "ico:", "(dluznici.iCO:${q} OR veritele.iCO:${q} OR spravci.iCO:${q}) " },
                { regexPrefix + "icodluznik:", "dluznici.iCO:" },
                { regexPrefix + "icoveritel:", "veritele.iCO:" },
                { regexPrefix + "icospravce:", "spravci.iCO:" },
                { regexPrefix + "jmeno:", "(dluznici.plneJmeno:${q} OR veritele.plneJmeno:${q} OR spravci.plneJmeno:${q})" },
                { regexPrefix + "jmenodluznik:", "dluznici.plneJmeno:" },
                { regexPrefix + "jmenoveritel:", "veritele.plneJmeno:" },
                { regexPrefix + "jmenospravce:", "spravci.plneJmeno:" },
                { regexPrefix + "spisovaznacka:", "spisovaZnacka:" },
                { regexPrefix + "id:", "spisovaZnacka:" },
                { "zmeneno:\\[", "posledniZmena:[" },
                { "zmeneno:(?=[<>])", "posledniZmena:${q}" },
                { "zmeneno:(?=\\d)", "posledniZmena:[${q} TO ${q}||+1d]" },
                { "zahajeno:\\[", "datumZalozeni:[" },
                { "zahajeno:(?=[<>])", "datumZalozeni:${q}" },
                { "zahajeno:(?=\\d)", "datumZalozeni:[${q} TO ${q}||+1d]" },
                { regexPrefix + "stav:", "stav:" },
                { regexPrefix + "text:", "dokumenty.plainText:" },
                { regexPrefix + "typdokumentu:", "dokumenty.popis:" },
                { regexPrefix + "dokumenttyp:", "dokumenty.popis:" },
                { regexPrefix + "oddil:", "dokumenty.oddil:" },
            };

            string modifiedQ = query; // ES.SearchTools.FixInvalidQuery(query, queryShorcuts, queryOperators) ?? "";

            //check invalid query ( tag: missing value)


            for (int i = 0; i < rules.GetLength(0); i++)
            {
                string lookFor     = rules[i, 0];
                string replaceWith = rules[i, 1];

                MatchEvaluator evalMatch = (m) =>
                {
                    var s = m.Value;
                    if (string.IsNullOrEmpty(s))
                    {
                        return(string.Empty);
                    }
                    var newVal = replaceWith;
                    if (newVal.Contains("${q}"))
                    {
                        newVal = newVal.Replace("${q}", m.Groups["q"].Value);
                    }
                    if (s.StartsWith("("))
                    {
                        return(" (" + newVal);
                    }
                    else
                    {
                        return(" " + newVal);
                    }
                };

                //if (modifiedQ.ToLower().Contains(lookFor.ToLower()))
                if (Regex.IsMatch(modifiedQ, lookFor, regexQueryOption))
                {
                    if (replaceWith.Contains("${q}"))
                    {
                        modifiedQ = Regex.Replace(modifiedQ, string.Format(regexTemplate, lookFor), evalMatch, regexQueryOption);
                    }
                    else if (lookFor.Contains("holding:"))
                    {
                        //list of ICO connected to this person
                        Match  m          = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string holdingIco = m.Groups["q"].Value;
                        HlidacStatu.Lib.Data.Relation.AktualnostType aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;
                        Data.Firma f = Data.Firmy.Get(holdingIco);
                        if (f != null && f.Valid)
                        {
                            var icos = new string[] { f.ICO }
                            .Union(f.AktualniVazby(aktualnost)
                                   .Select(s => s.To.Id)
                                   )
                            .Distinct();
                            string icosQuery    = "";
                            var    icosPresLidi = f.AktualniVazby(aktualnost)
                                                  .Where(o => o.To.Type == Graph.Node.NodeType.Person)
                                                  .Select(o => Data.Osoby.GetById.Get(Convert.ToInt32(o.To.Id)))
                                                  .Where(o => o != null)
                                                  .SelectMany(o => o.AktualniVazby(aktualnost))
                                                  .Select(v => v.To.Id)
                                                  .Distinct();
                            icos = icos.Union(icosPresLidi).Distinct();

                            var templ = "(ico:{0})";
                            if (icos != null && icos.Count() > 0)
                            {
                                icosQuery = "(" + icos
                                            .Select(t => string.Format(templ, t))
                                            .Aggregate((fi, s) => fi + " OR " + s) + ")";
                            }
                            else
                            {
                                icosQuery = "(ico:noOne)";
                            }
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                        }
                    } //do regex replace
                    else if (replaceWith.Contains("${ico}"))
                    {
                        //list of ICO connected to this person
                        Match      m         = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                        string     nameId    = m.Groups["q"].Value;
                        Data.Osoba p         = Data.Osoby.GetByNameId.Get(nameId);
                        string     icosQuery = "";
                        if (p != null)
                        {
                            var icos = p
                                       .AktualniVazby(Data.Relation.AktualnostType.Nedavny)
                                       .Where(w => !string.IsNullOrEmpty(w.To.Id))
                                       .Where(w => Analysis.ACore.GetBasicStatisticForICO(w.To.Id).Summary.Pocet > 0)
                                       .Select(w => w.To.Id)
                                       .Distinct().ToArray();
                            var templ = "(ico:{0})";
                            if (icos != null && icos.Length > 0)
                            {
                                icosQuery = "(" + icos
                                            .Select(t => string.Format(templ, t))
                                            .Aggregate((f, s) => f + " OR " + s) + ")";
                            }
                            else
                            {
                                icosQuery = "(ico:noOne)";
                            }
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                        }
                        else
                        {
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, "(ico:noOne)", regexQueryOption);
                        }
                    }
                    else
                    {
                        modifiedQ = Regex.Replace(modifiedQ, lookFor, evalMatch, regexQueryOption);
                    }
                }
            }



            QueryContainer qc = null;

            if (modifiedQ == null)
            {
                qc = new QueryContainerDescriptor <Rizeni>().MatchNone();
            }
            else if (string.IsNullOrEmpty(modifiedQ))
            {
                qc = new QueryContainerDescriptor <Rizeni>().MatchAll();
            }
            else
            {
                modifiedQ = modifiedQ.Replace(" | ", " OR ").Trim();
                qc        = new QueryContainerDescriptor <Rizeni>()
                            .QueryString(qs => qs
                                         .Query(modifiedQ)
                                         .DefaultOperator(Operator.And)
                                         );
            }

            return(qc);
        }
Exemplo n.º 5
0
        protected override RuleResult processQueryPart(SplittingQuery.Part part)
        {
            if (part == null)
            {
                return(null);
            }

            if (
                (!string.IsNullOrWhiteSpace(_specificPrefix) && part.Prefix.Equals(_specificPrefix, StringComparison.InvariantCultureIgnoreCase))
                ||
                (string.IsNullOrWhiteSpace(_specificPrefix) &&
                 (part.Prefix.Equals("holding:", StringComparison.InvariantCultureIgnoreCase)
                  //RS
                  || part.Prefix.Equals("holdingprijemce:", StringComparison.InvariantCultureIgnoreCase) ||
                  part.Prefix.Equals("holdingplatce:", StringComparison.InvariantCultureIgnoreCase)
                  //insolvence
                  || part.Prefix.Equals("holdingdluznik:", StringComparison.InvariantCultureIgnoreCase) ||
                  part.Prefix.Equals("holdingveritel:", StringComparison.InvariantCultureIgnoreCase) ||
                  part.Prefix.Equals("holdingspravce:", StringComparison.InvariantCultureIgnoreCase)
                  //VZ
                  || part.Prefix.Equals("holdingdodavatel:", StringComparison.InvariantCultureIgnoreCase) ||
                  part.Prefix.Equals("holdingzadavatel:", StringComparison.InvariantCultureIgnoreCase)
                 )
                )
                )
            {
                //list of ICO connected to this holding
                string holdingIco = part.Value;
                HlidacStatu.Lib.Data.Relation.AktualnostType aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;
                Data.Firma f = Data.Firmy.Get(holdingIco);
                if (f != null && f.Valid)
                {
                    var icos = new string[] { f.ICO }
                    .Union(
                        f.AktualniVazby(aktualnost)
                        .Select(s => s.To.Id)
                        )
                    .Distinct();

                    string icosQuery    = "";
                    var    icosPresLidi = f.AktualniVazby(aktualnost)
                                          .Where(o => o.To.Type == Data.Graph.Node.NodeType.Person)
                                          .Select(o => Data.Osoby.GetById.Get(Convert.ToInt32(o.To.Id)))
                                          .Where(o => o != null)
                                          .SelectMany(o => o.AktualniVazby(aktualnost))
                                          .Select(v => v.To.Id)
                                          .Distinct();
                    icos = icos.Union(icosPresLidi).Distinct();

                    var templ = $" ( {this.ReplaceWith}{{0}} ) ";
                    if (this.ReplaceWith.Contains("${q}"))
                    {
                        templ = $" ( {this.ReplaceWith.Replace("${q}", "{0}")} )";
                    }

                    if (icos != null && icos.Count() > 0)
                    {
                        icosQuery = " ( " + icos
                                    .Select(t => string.Format(templ, t))
                                    .Aggregate((fi, s) => fi + " OR " + s) + " ) ";
                    }
                    else
                    {
                        icosQuery = string.Format(templ, "noOne"); //$" ( {icoprefix}:noOne ) ";
                    }

                    return(new RuleResult(SplittingQuery.SplitQuery($"{icosQuery}"), this.NextStep));
                }
            }

            return(null);
        }
Exemplo n.º 6
0
            public static QueryContainer GetSimpleQuery(ES.VerejnaZakazkaSearchData searchdata)
            {
                var query = searchdata.Q?.Trim();
                //if (string.IsNullOrEmpty(query) || query == "*")
                //    return new QueryContainerDescriptor<VerejnaZakazka>().MatchAll();


                string regexPrefix   = @"(^|\s|[(])";
                string regexTemplate = "{0}(?<q>(-|\\w)*)\\s*";

                //fix field prefixes
                //ds: ->
                string[,] rules = new string[, ] {
                    { @"osobaid:(?<q>((\w{1,} [-]{1} \w{1,})([-]{1} \d{1,3})?)) (\s|$){1,}", "${ico}" },
                    { @"holding:(?<q>(\d{1,8})) (\s|$){1,}", "${ico}" },
                    { "cpv:", "${cpv}" },
                    { "oblast:", "${oblast}" },
                    { "form:", "${form}" },
                    { "zahajeny:1", "stavVZ:<=100" },
                    { regexPrefix + "ico:", "(zadavatel.iCO:${q} OR dodavatele.iCO:${q}) " },
                    { regexPrefix + "icododavatel:", "dodavatele.iCO:" },
                    { regexPrefix + "icoprijemce:", "dodavatele.iCO:" },
                    { regexPrefix + "icozadavatel:", "zadavatel.iCO:" },
                    { regexPrefix + "icoplatce:", "zadavatel.iCO:" },
                    { "jmenoprijemce:", "dodavatele.jmeno:" },
                    { "jmenoplatce:", "zadavatel.jmeno:" },
                    { regexPrefix + "id:", "id:" },
                    { "popis:", "(nazevZakazky:${q} OR popisZakazky:${q}) " },
                    { "cena:<=", "(konecnaHodnotaBezDPH:<=${q} OR odhadovanaHodnotaBezDPH:<=${q}) " },
                    { "cena:>=", "(konecnaHodnotaBezDPH:>=${q} OR odhadovanaHodnotaBezDPH:>=${q}) " },
                    { "cena:<", "(konecnaHodnotaBezDPH:<${q} OR odhadovanaHodnotaBezDPH:<${q}) " },
                    { "cena:>", "(konecnaHodnotaBezDPH:>${q} OR odhadovanaHodnotaBezDPH:>${q}) " },
                    { "cena:", "(konecnaHodnotaBezDPH:${q} OR odhadovanaHodnotaBezDPH:${q}) " },
                    { "zverejneno:\\[", "datumUverejneni:[" },
                    { "zverejneno:(?=[<>])", "datumUverejneni:${q}" },
                    { "zverejneno:(?=\\d)", "datumUverejneni:[${q} TO ${q}||+1d]" },
                    { "podepsano:\\[", "datumUzavreniSmlouvy:[" },
                    { "podepsano:(?=[<>])", "datumUzavreniSmlouvy:${q}" },
                    { "podepsano:(?=\\d)", "datumUzavreniSmlouvy:[${q} TO ${q}||+1d]" },
                    { "text:", "prilohy.plainTextContent:" },
                };


                string modifiedQ = query; // ES.SearchTools.FixInvalidQuery(query, queryShorcuts, queryOperators) ?? "";

                //check invalid query ( tag: missing value)


                if (searchdata.Zahajeny)
                {
                    modifiedQ = Lib.ES.SearchTools.ModifyQuery(modifiedQ, "zahajeny:1");
                }

                if (!string.IsNullOrWhiteSpace(searchdata.Oblast))
                {
                    var oblValue = NormalizeOblastValue(searchdata.Oblast);
                    if (!string.IsNullOrEmpty(oblValue))
                    {
                        modifiedQ = Lib.ES.SearchTools.ModifyQuery(modifiedQ, "oblast:" + oblValue);
                    }
                }


                for (int i = 0; i < rules.GetLength(0); i++)
                {
                    string lookFor     = rules[i, 0];
                    string replaceWith = rules[i, 1];

                    MatchEvaluator evalMatch = (m) =>
                    {
                        var s = m.Value;
                        if (string.IsNullOrEmpty(s))
                        {
                            return(string.Empty);
                        }
                        var newVal = replaceWith;
                        if (newVal.Contains("${q}"))
                        {
                            newVal = newVal.Replace("${q}", m.Groups["q"].Value);
                        }
                        if (s.StartsWith("("))
                        {
                            return(" (" + newVal);
                        }
                        else
                        {
                            return(" " + newVal);
                        }
                    };

                    //if (modifiedQ.ToLower().Contains(lookFor.ToLower()))
                    if (Regex.IsMatch(modifiedQ, lookFor, regexQueryOption))
                    {
                        if (replaceWith.Contains("${q}"))
                        {
                            modifiedQ = Regex.Replace(modifiedQ, string.Format(regexTemplate, lookFor), evalMatch, regexQueryOption);
                        } //do regex replace
                        //else if (replaceWith.Contains("${zahajeny}") && )
                        //{
                        //    modifiedQ = Regex.Replace(modifiedQ, lookFor, "stavVZ:<=100", regexQueryOption);
                        //} //do regex replace
                        else if (replaceWith.Contains("${oblast}"))
                        {
                            string cpv = "";
                            if (replaceWith.Contains("${oblast}"))
                            {
                                var oblastVal = ParseTools.GetRegexGroupValue(modifiedQ, @"oblast:(?<oblast>\w*)", "oblast");
                                var cpvs      = CPVOblastToCPV(oblastVal);
                                if (cpvs != null)
                                {
                                    var q_cpv = "cPV:(" + cpvs.Select(s => s + "*").Aggregate((f, s) => f + " OR " + s) + ")";
                                    modifiedQ = Regex.Replace(modifiedQ, @"oblast:(?<oblast>\w*)", q_cpv, regexQueryOption);
                                }
                            }
                        }
                        else if (replaceWith.Contains("${cpv}"))
                        {
                            string cpv = "";
                            //Match m = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                            //string cpv = "";
                            //if (m.Success)
                            //    cpv = m.Groups["q"].Value;
                            cpv     = ParseTools.GetRegexGroupValue(modifiedQ, @"cpv:(?<q>(-|,|\d)*)\s*", "q");
                            lookFor = @"cpv:(?<q>(-|,|\d)*)\s*";
                            if (!string.IsNullOrEmpty(cpv))
                            {
                                string[] cpvs  = cpv.Split(new char[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                                string   q_cpv = "";
                                if (cpvs.Length > 0)
                                {
                                    q_cpv = "cPV:(" + cpvs.Select(s => s + "*").Aggregate((f, s) => f + " OR " + s) + ")";
                                }

                                modifiedQ = Regex.Replace(modifiedQ, lookFor, q_cpv, regexQueryOption);
                            }
                            else
                            {
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, "", regexQueryOption);
                            }
                        }
                        else if (replaceWith.Contains("${form}"))
                        {
                            lookFor = @"form:(?<q>((F|CZ)\d{1,2}(,)?)*)\s*";
                            Match  m    = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                            string form = "";
                            if (m.Success)
                            {
                                form = m.Groups["q"].Value;
                            }
                            if (!string.IsNullOrEmpty(form))
                            {
                                string[] forms  = form.Split(new char[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                                string   q_form = "";
                                if (forms.Length > 0)
                                {
                                    q_form = "formulare.druh:(" + forms.Select(s => s + "*").Aggregate((f, s) => f + " OR " + s) + ")";
                                }

                                modifiedQ = Regex.Replace(modifiedQ, lookFor, q_form, regexQueryOption);
                            }
                            else
                            {
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, "", regexQueryOption);
                            }
                        }
                        else if (lookFor.Contains("holding:"))
                        {
                            //list of ICO connected to this person
                            Match  m          = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                            string holdingIco = m.Groups["q"].Value;
                            HlidacStatu.Lib.Data.Relation.AktualnostType aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;
                            Data.Firma f = Data.Firmy.Get(holdingIco);
                            if (f != null && f.Valid)
                            {
                                var icos = new string[] { f.ICO }
                                .Union(f.AktualniVazby(aktualnost)
                                       .Select(s => s.To.Id)
                                       )
                                .Distinct();
                                string icosQuery    = "";
                                var    icosPresLidi = f.AktualniVazby(aktualnost)
                                                      .Where(o => o.To.Type == Graph.Node.NodeType.Person)
                                                      .Select(o => Data.Osoby.GetById.Get(Convert.ToInt32(o.To.Id)))
                                                      .Where(o => o != null)
                                                      .SelectMany(o => o.AktualniVazby(aktualnost))
                                                      .Select(v => v.To.Id)
                                                      .Distinct();
                                icos = icos.Union(icosPresLidi).Distinct();

                                var templ = "(ico:{0})";
                                if (icos != null && icos.Count() > 0)
                                {
                                    icosQuery = "(" + icos
                                                .Select(t => string.Format(templ, t))
                                                .Aggregate((fi, s) => fi + " OR " + s) + ")";
                                }
                                else
                                {
                                    icosQuery = "(ico:noOne)";
                                }
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                            }
                        } //do regex replace
                        else if (replaceWith.Contains("${ico}"))
                        {
                            //list of ICO connected to this person
                            Match      m         = Regex.Match(modifiedQ, lookFor, regexQueryOption);
                            string     nameId    = m.Groups["q"].Value;
                            Data.Osoba p         = Data.Osoby.GetByNameId.Get(nameId);
                            string     icosQuery = "";
                            if (p != null)
                            {
                                var icos = p
                                           .AktualniVazby(Data.Relation.AktualnostType.Nedavny)
                                           .Where(w => !string.IsNullOrEmpty(w.To.Id))
                                           .Where(w => Analysis.ACore.GetBasicStatisticForICO(w.To.Id).Summary.Pocet > 0)
                                           .Select(w => w.To.Id)
                                           .Distinct().ToArray();
                                var templ = "(ico:{0})";
                                if (icos != null && icos.Length > 0)
                                {
                                    icosQuery = "(" + icos
                                                .Select(t => string.Format(templ, t))
                                                .Aggregate((f, s) => f + " OR " + s) + ")";
                                }
                                else
                                {
                                    icosQuery = "(ico:noOne)";
                                }
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, icosQuery, regexQueryOption);
                            }
                            else
                            {
                                modifiedQ = Regex.Replace(modifiedQ, lookFor, "(ico:noOne)", regexQueryOption);
                            }
                        }
                        else
                        {
                            modifiedQ = Regex.Replace(modifiedQ, lookFor, evalMatch, regexQueryOption);
                        }
                    }
                }


                QueryContainer qc = null;

                if (modifiedQ == null)
                {
                    qc = new QueryContainerDescriptor <VerejnaZakazka>().MatchNone();
                }
                else if (string.IsNullOrEmpty(modifiedQ))
                {
                    qc = new QueryContainerDescriptor <VerejnaZakazka>().MatchAll();
                }
                else
                {
                    modifiedQ = modifiedQ.Replace(" | ", " OR ").Trim();
                    qc        = new QueryContainerDescriptor <VerejnaZakazka>()
                                .QueryString(qs => qs
                                             .Query(modifiedQ)
                                             .DefaultOperator(Operator.And)
                                             );
                }

                return(qc);
            }