Beispiel #1
0
        public static Osoba GetOrCreateNew(string titulPred, string jmeno, string prijmeni, string titulPo,
                                           DateTime?narozeni, StatusOsobyEnum status, string user)
        {
            var p = new Data.Osoba();

            p.TitulPred = NormalizeTitul(titulPred, true);
            p.TitulPo   = NormalizeTitul(titulPo, false);
            p.Jmeno     = NormalizeJmeno(jmeno);
            p.Prijmeni  = NormalizePrijmeni(prijmeni);

            if (narozeni.HasValue == false)
            {
                p.Status = (int)status;
                p.Save();
                Audit.Add(Audit.Operations.Create, user, p, null);
                return(p);
            }
            var exiO = Osoba.GetByName(p.Jmeno, p.Prijmeni, narozeni.Value);


            if (exiO == null)
            {
                p.Status   = (int)status;
                p.Narozeni = narozeni;
                p.Save();
                Audit.Add(Audit.Operations.Create, user, p, null);
                return(p);
            }
            else
            {
                bool changed = false;
                if (exiO.TitulPred != p.TitulPred)
                {
                    changed        = true;
                    exiO.TitulPred = p.TitulPred;
                }
                if (exiO.TitulPo != p.TitulPo)
                {
                    changed      = true;
                    exiO.TitulPo = p.TitulPo;
                }
                if (exiO.Status < (int)status)
                {
                    changed     = true;
                    exiO.Status = (int)status;
                }
                if (changed)
                {
                    exiO.Save();
                    Audit.Add(Audit.Operations.Update, user, exiO, Osoba.Get(exiO.InternalId));
                }
                return(exiO);
            }
        }
        public OsobaStatistic(Data.Osoba o, Data.Relation.AktualnostType aktualnost, bool refresh = false)
        {
            this.Item       = o.NameId;
            this._osoba     = o;
            this.Aktualnost = aktualnost;

            osq = new OsobaStatisticQuery()
            {
                NameId = this.Item, Aktualnost = this.Aktualnost
            };

            if (refresh)
            {
                osobaStatcache.Delete(osq);
            }

            this.InitData();
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
        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);
        }
Beispiel #7
0
        protected override RuleResult processQueryPart(SplittingQuery.Part part)
        {
            if (part == null)
            {
                return(null);
            }


            if (
                (
                    (!string.IsNullOrWhiteSpace(_specificPrefix) && part.Prefix.Equals(_specificPrefix, StringComparison.InvariantCultureIgnoreCase))
                    ||
                    (part.Prefix.Equals("osobaid:", StringComparison.InvariantCultureIgnoreCase) ||
                     part.Prefix.Equals("osobaidprijemce:", StringComparison.InvariantCultureIgnoreCase) ||
                     part.Prefix.Equals("osobaidplatce:", StringComparison.InvariantCultureIgnoreCase)

                     || part.Prefix.Equals("osobaidveritel:", StringComparison.InvariantCultureIgnoreCase) ||
                     part.Prefix.Equals("osobaidveritel:", StringComparison.InvariantCultureIgnoreCase)

                     || part.Prefix.Equals("osobaidspravce:", StringComparison.InvariantCultureIgnoreCase) ||
                     part.Prefix.Equals("osobaidzadavatel:", StringComparison.InvariantCultureIgnoreCase) ||
                     part.Prefix.Equals("osobaiddodavatel:", StringComparison.InvariantCultureIgnoreCase)
                    )
                ) &&
                (Regex.IsMatch(part.Value, @"(?<q>((\w{1,} [-]{1} \w{1,})([-]{1} \d{1,3})?))", HlidacStatu.Util.Consts.DefaultRegexQueryOption))
                )
            {
                if (!string.IsNullOrWhiteSpace(this.ReplaceWith))
                {
                    //list of ICO connected to this person
                    string nameId = part.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 ) ";
                        }
                        bool lastCondAdded = false;
                        if (!string.IsNullOrEmpty(this.AddLastCondition))
                        {
                            if (this.AddLastCondition.Contains("${q}"))
                            {
                                icosQuery = Tools.ModifyQueryOR(icosQuery, this.AddLastCondition.Replace("${q}", part.Value));
                            }
                            else
                            {
                                icosQuery = Tools.ModifyQueryOR(icosQuery, this.AddLastCondition);
                            }
                            lastCondAdded = true;
                            //this.AddLastCondition = null; //done, don't do it anywhere
                        }
                        return(new RuleResult(SplittingQuery.SplitQuery($"{icosQuery}"), this.NextStep, lastCondAdded));
                    }
                } // if (!string.IsNullOrWhiteSpace(this.ReplaceWith))
                else if (!string.IsNullOrWhiteSpace(this.AddLastCondition))
                {
                    if (this.AddLastCondition.Contains("${q}"))
                    {
                        var q = this.AddLastCondition.Replace("${q}", part.Value);
                        return(new RuleResult(SplittingQuery.SplitQuery(q), this.NextStep, true));
                    }
                    else
                    {
                        var q = this.AddLastCondition;
                        return(new RuleResult(SplittingQuery.SplitQuery(q), this.NextStep, true));
                    }
                }
            }
            return(null);
        }
Beispiel #8
0
            public Osoba Save(string user)
            {
                Osoba o = null;
                var   t = this;

                DateTime?narozeni = Devmasters.DT.Util.ToDateTime(t.Narozeni, "yyyy-MM-dd");

                //find existing
                if (this.Id > 0)
                {
                    o = Osoby.GetById.Get(this.Id);
                }
                else if (narozeni.HasValue == false)
                {
                    return(null);
                }
                if (o == null)
                {
                    o = Osoba.Searching.GetByName(t.Jmeno, t.Prijmeni, narozeni.Value);
                }
                if (o == null)
                {
                    o = Osoba.Searching.GetByNameAscii(t.Jmeno, t.Prijmeni, narozeni.Value);
                }

                if (o == null)
                {
                    o = new Data.Osoba();
                }

                o.Pohlavi  = (t.Gender == gender.Žena) ? "f" : "m";
                o.Jmeno    = t.Jmeno;
                o.Narozeni = narozeni.Value;
                o.Umrti    = Devmasters.DT.Util.ToDateTime(t.Umrti, "yyyy-MM-dd");
                o.Prijmeni = t.Prijmeni;
                o.Status   = (int)t.Status;
                o.NameId   = t.NameId;
                o.Save();

                foreach (var e in t.Event)
                {
                    OsobaEvent ev = new OsobaEvent();
                    ev.pk         = e.pk;
                    ev.Organizace = e.Organizace;
                    ev.AddInfoNum = e.AddInfoNum;
                    ev.DatumOd    = Devmasters.DT.Util.ToDateTime(e.DatumOd, "yyyy-MM-dd");
                    ev.DatumDo    = Devmasters.DT.Util.ToDateTime(e.DatumDo, "yyyy-MM-dd");
                    ev.Note       = e.Note;
                    ev.Title      = e.Title;
                    ev.Type       = (int)e.Typ;
                    ev.AddInfo    = e.AddInfo;
                    ev.Zdroj      = e.Zdroj;
                    ev.OsobaId    = o.InternalId;
                    o.AddOrUpdateEvent(ev, user);
                }

                foreach (var v in t.Vazbyfirmy)
                {
                    if (!string.IsNullOrEmpty(v.VazbaKOsoba))
                    {
                        var os = Osoby.GetByNameId.Get(v.VazbaKOsoba);
                        if (os != null)
                        {
                            OsobaVazby.AddOrUpdate(o.InternalId, os.InternalId, (int)v.TypVazby, v.Popis, 0, Devmasters.DT.Util.ToDateTime(v.DatumOd, "yyyy-MM-dd"), Devmasters.DT.Util.ToDateTime(v.DatumDo, "yyyy-MM-dd"), v.Zdroj);
                        }
                    }
                    else
                    {
                        OsobaVazby.AddOrUpdate(o.InternalId, v.VazbaKIco, (int)v.TypVazby, v.Popis, 0, Devmasters.DT.Util.ToDateTime(v.DatumOd, "yyyy-MM-dd"), Devmasters.DT.Util.ToDateTime(v.DatumDo, "yyyy-MM-dd"), v.Zdroj);
                    }
                }
                return(o);
            }
            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);
            }