public ZabHost(string hostId, string host, string url, string description, string[] mainGroup = null) { this.hostid = hostId; this.host = host; this.url = url; this.urad = Devmasters.Core.TextUtil.NormalizeToBlockText(ParseTools.GetRegexGroupValue(description, @"Urad:\s?(?<txt>[^\x0a\x0d]*)", "txt")); this.popis = Devmasters.Core.TextUtil.ShortenHTML(ParseTools.GetRegexGroupValue(description, @"Popis:\s?(?<txt>[^\x0a\x0d]*)", "txt"), 10000, new string[] { "a", "b" }); this.publicname = Devmasters.Core.TextUtil.NormalizeToBlockText(ParseTools.GetRegexGroupValue(description, @"Nazev:\s?(?<txt>[^\x0a\x0d]*)", "txt")); string sgroup = Devmasters.Core.TextUtil.NormalizeToBlockText(ParseTools.GetRegexGroupValue(description, @"Poznamka:\s?(?<txt>[^\x0a\x0d]*)", "txt")); this.customUrl = Devmasters.Core.TextUtil.NormalizeToBlockText(ParseTools.GetRegexGroupValue(description, @"URL:\s?(?<txt>[^\x0a\x0d]*)", "txt")); this.groups.Clear(); if (!string.IsNullOrEmpty(sgroup)) { var agroups = sgroup.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); this.groups.AddRange(agroups); } if (mainGroup != null && mainGroup.Length > 0) { this.groups.AddRange(mainGroup); } if (string.IsNullOrEmpty(publicname)) { publicname = this.host; } _hash = Devmasters.Core.CryptoLib.Hash.ComputeHashToHex(hostid + "xxttxx" + hostid); }
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); }
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(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); }