public Lib.Data.Firma Subject() { if (_subj == null) { _subj = Data.Firmy.Get(this.Item); } return(_subj); }
public static Firma FromIco(string ico) { var resp = Manager.RawSearchIco(ico); if (resp == null) { return(Firma.LoadError); } if (resp.Items .Where(m => m.GetType() == typeof(TPodnikatelSeznam)) .Count() > 0) { TPodnikatelSeznam xf = resp.Items .Where(m => m.GetType() == typeof(TPodnikatelSeznam)) .First() as TPodnikatelSeznam; Firma f = new Data.Firma(); f.Jmeno = xf.ObchodniJmenoSeznam.Value; f.ICO = ico; var detail = Manager.RawSearchDetail(xf.PodnikatelID); if (detail == null) { f.Source = "RZP"; f.Popis = "Živnostník"; return(f); } TPodnikatelVypis vypis = detail.Items .Where(m => m.GetType() == typeof(TPodnikatelVypis)) .First() as TPodnikatelVypis; if (vypis.PodnikatelDetail?.SeznamZivnosti?.Zivnost?.Count() > 0) { f.Datum_Zapisu_OR = vypis.PodnikatelDetail.SeznamZivnosti.Zivnost .Where(m => !string.IsNullOrEmpty(m.Vznik.Value)) .Select(m => DateTime.ParseExact(m.Vznik.Value, "dd.MM.yyyy", HlidacStatu.Util.Consts.czCulture)) .Min(); f.Source = "RZP"; f.Popis = "Živnostník"; } f.RefreshDS(); f.Save(); return(f); } else { return(Firma.NotFound); } }
private static Firma FromDataRow(DataRow dr, bool skipDS_Nace = false) { Firma f = new Data.Firma(); f.ICO = (string)dr["ico"]; f.DIC = (string)PersistLib.IsNull(dr["dic"], string.Empty); f.Datum_Zapisu_OR = (DateTime?)PersistLib.IsNull(dr["datum_zapisu_or"], null); f.Stav_subjektu = Convert.ToInt32(PersistLib.IsNull(dr["Stav_subjektu"], 1)); f.Status = Convert.ToInt32(PersistLib.IsNull(dr["Status"], 1)); f.Jmeno = (string)PersistLib.IsNull(dr["jmeno"], string.Empty); f.JmenoAscii = (string)PersistLib.IsNull(dr["jmenoascii"], string.Empty); f.Kod_PF = (int?)PersistLib.IsNull(dr["Kod_PF"], null); f.VersionUpdate = (int)dr["VersionUpdate"]; //f.VazbyRaw = (string)PersistLib.IsNull(dr["vazbyRaw"], (string)"[]"); f.IsInRS = (short?)PersistLib.IsNull(dr["IsInRS"], null); f.KrajId = (string)PersistLib.IsNull(dr["krajid"], string.Empty); f.OkresId = (string)PersistLib.IsNull(dr["okresid"], string.Empty); f.Typ = (int?)PersistLib.IsNull(dr["Typ"], null); if (skipDS_Nace == false) { using (PersistLib p = new PersistLib()) { f.DatovaSchranka = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, "select DatovaSchranka from firma_DS where ico=@ico", new IDataParameter[] { new System.Data.SqlClient.SqlParameter("ico", f.ICO) }).Tables[0] .AsEnumerable() .Select(m => m[0].ToString()) .ToArray(); f.NACE = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, "select NACE from firma_Nace where ico=@ico", new IDataParameter[] { new System.Data.SqlClient.SqlParameter("ico", f.ICO) }).Tables[0] .AsEnumerable() .Select(m => m[0].ToString()) .ToArray(); } } return(f); }
public static Firma FromIco(string ico) { Firma f = new Data.Firma(); using (PersistLib p = new PersistLib()) { string sql = @"select * from Firma where ico = @ico"; var res = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sql, new IDataParameter[] { new System.Data.SqlClient.SqlParameter("ico", ico) }); if (res.Tables[0].Rows.Count > 0) { return(FromDataRow(res.Tables[0].Rows[0])); } else { return(Firma.NotFound); } } }
public static Firma FromDS(string ds) { Firma f = new Data.Firma(); using (PersistLib p = new PersistLib()) { string sql = @"select firma.* from Firma_ds fds inner join firma on firma.ico = fds.ico where DatovaSchranka = @ds"; var res = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sql, new IDataParameter[] { new System.Data.SqlClient.SqlParameter("ds", ds) }); if (res.Tables[0].Rows.Count > 0) { return(FromDataRow(res.Tables[0].Rows[0])); } else { return(Firma.NotFound); } } }
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(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); }
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); }
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); }
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); }