protected override WatchDogProcessor.Result DoFinalSearch(string query, DateTime fromDate, DateTime toDate, string order = null) { query += " AND datumAktualizace:" + string.Format("[{0} TO {1}]", Searching.Tools.ToElasticDate(fromDate), Searching.Tools.ToElasticDate(toDate)); //AND platnyZaznam:1 var res = dotaceService.SimpleSearch(query, 0, 50, order == null ? (int)Searching.DotaceSearchResult.DotaceOrderResult.Relevance : Convert.ToInt32(order), false); return(new WatchDogProcessor.Result(res.ElasticResults.Hits.Select(m => (dynamic)m.Source), res.Total, query, fromDate, toDate, res.IsValid, typeof(Insolvence.Rizeni).Name)); }
private static MultiResult GeneralSearch(Elastic.Apm.Api.ITransaction apmtran, string query, int page = 1, int pageSize = 10, bool showBeta = false, string order = null) { MultiResult res = new MultiResult() { Query = query }; if (string.IsNullOrEmpty(query)) { return(res); } if (!Lib.Searching.Tools.ValidateQuery(query)) { res.Smlouvy = new Searching.SmlouvaSearchResult(); res.Smlouvy.Q = query; res.Smlouvy.IsValid = false; return(res); } var totalsw = new Devmasters.DT.StopWatchEx(); totalsw.Start(); ParallelOptions po = new ParallelOptions(); //po.MaxDegreeOfParallelism = 20; po.MaxDegreeOfParallelism = System.Diagnostics.Debugger.IsAttached ? 1 : po.MaxDegreeOfParallelism; Parallel.Invoke(po, () => { Elastic.Apm.Api.ISpan sp = null; try { apmtran.CaptureSpan("Smlouvy", "search", () => { res.Smlouvy = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch(query, 1, pageSize, order, anyAggregation: new Nest.AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Sum("sumKc", m => m.Field(f => f.CalculatedPriceWithVATinCZK)) ); }); } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Smlouvy query" + query, e); } finally { sp?.End(); } }, () => { try { Devmasters.DT.StopWatchEx sw = new Devmasters.DT.StopWatchEx(); sw.Start(); res.Firmy = Firma.Search.SimpleSearch(query, 0, 50); sw.Stop(); res.Firmy.ElapsedTime = sw.Elapsed; } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Firmy query" + query, e); } }, () => { try { res.VZ = VZ.VerejnaZakazka.Searching.SimpleSearch(query, null, 1, pageSize, order); } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Verejne zakazky query" + query, e); } }, () => { try { Devmasters.DT.StopWatchEx sw = new Devmasters.DT.StopWatchEx(); sw.Start(); res.Osoby = Osoba.Search.SimpleSearch(query, 1, 10, Osoba.Search.OrderResult.Relevance); sw.Stop(); res.Osoby.ElapsedTime = sw.Elapsed; } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Osoba query" + query, e); } }, () => { try { var iqu = new Searching.InsolvenceSearchResult { Q = query, PageSize = pageSize, Order = order }; res.Insolvence = iqu; //if (showBeta) res.Insolvence = Insolvence.Insolvence.SimpleSearch(new Searching.InsolvenceSearchResult { Q = query, PageSize = pageSize, Order = order }); } catch (System.Exception e) { Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e); } }, () => { try { var dotaceService = new Dotace.DotaceService(); var iqu = new Searching.DotaceSearchResult { Q = query, PageSize = pageSize, Order = order }; res.Dotace = dotaceService.SimpleSearch( new Searching.DotaceSearchResult { Q = query, PageSize = pageSize, Order = order }, anyAggregation: new Nest.AggregationContainerDescriptor <Lib.Data.Dotace.Dotace>().Sum("souhrn", s => s.Field(f => f.DotaceCelkem)) ); } catch (System.Exception e) { Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e); } }, () => { try { apmtran.CaptureSpan("Dataset GeneralSearch", "search", () => { res.Datasets = Lib.Data.Search.DatasetMultiResult.GeneralSearch(query, null, 1, 5); if (res.Datasets.Exceptions.Count > 0) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, res.Datasets.GetExceptions()); } }); } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, e); } finally { } } ); //TODO too slow, temporarily disabled totalsw.Stop(); res.TotalSearchTime = totalsw.Elapsed; return(res); }
private static MultiResult GeneralSearch(Elastic.Apm.Api.ITransaction apmtran, string query, int page = 1, int pageSize = 10, bool showBeta = false) { MultiResult res = new MultiResult() { Query = query }; if (string.IsNullOrEmpty(query)) { return(res); } if (!Lib.Searching.Tools.ValidateQuery(query)) { res.Smlouvy = new Searching.SmlouvaSearchResult(); res.Smlouvy.Q = query; res.Smlouvy.IsValid = false; return(res); } var totalsw = new Devmasters.Core.StopWatchEx(); totalsw.Start(); ParallelOptions po = new ParallelOptions(); //po.MaxDegreeOfParallelism = 20; po.MaxDegreeOfParallelism = System.Diagnostics.Debugger.IsAttached ? 1 : po.MaxDegreeOfParallelism; Parallel.Invoke(po, () => { Elastic.Apm.Api.ISpan sp = null; try { apmtran.CaptureSpan("Smlouvy", "search", () => { res.Smlouvy = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch(query, 1, 20, Smlouva.Search.OrderResult.Relevance, anyAggregation: new Nest.AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Sum("sumKc", m => m.Field(f => f.CalculatedPriceWithVATinCZK)) ); }); } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Smlouvy query" + query, e); } finally { sp?.End(); } }, () => { try { Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx(); sw.Start(); res.Firmy = new GeneralResult <string>(Firma.Search.FindAllIco(query, 50)); sw.Stop(); res.Firmy.ElapsedTime = sw.Elapsed; } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Firmy query" + query, e); } }, () => { try { res.VZ = VZ.VerejnaZakazka.Searching.SimpleSearch(query, null, 1, 5, (int)Lib.Searching.VerejnaZakazkaSearchData.VZOrderResult.Relevance); } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Verejne zakazky query" + query, e); } }, () => { try { Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx(); sw.Start(); if (!string.IsNullOrEmpty(query) && query.Length > 2) { res.Osoby = new GeneralResult <Osoba>( HlidacStatu.Lib.Data.Osoba.GetPolitikByNameFtx(query, 100) .OrderBy(m => m.Prijmeni) .ThenBy(m => m.Jmeno) ); } else { res.Osoby = new GeneralResult <Osoba>(new Osoba[] { }); } sw.Stop(); res.Osoby.ElapsedTime = sw.Elapsed; } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Osoba query" + query, e); } }, () => { try { var iqu = new Searching.InsolvenceSearchResult { Q = query, PageSize = 5 }; res.Insolvence = iqu; //if (showBeta) res.Insolvence = Insolvence.Insolvence.SimpleSearch(new Searching.InsolvenceSearchResult { Q = query, PageSize = 5 }); } catch (System.Exception e) { Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e); } }, () => { try { if (showBeta) { var dotaceService = new Dotace.DotaceService(); var iqu = new Searching.DotaceSearchResult { Q = query, PageSize = 5 }; res.Dotace = iqu; //if (showBeta) res.Dotace = dotaceService.SimpleSearch(new Searching.DotaceSearchResult { Q = query, PageSize = 5 }); } } catch (System.Exception e) { Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e); } }, () => { Elastic.Apm.Api.ISpan sp = null; try { apmtran.CaptureSpan("Dataset GeneralSearch", "search", () => { res.Datasets = Lib.Data.Search.DatasetMultiResult.GeneralSearch(query, null, 1, 5); if (res.Datasets.Exceptions.Count > 0) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, res.Datasets.GetExceptions()); } }); } catch (System.Exception e) { HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, e); } finally { } } ); //TODO too slow, temporarily disabled if (false && res.HasFirmy && (res.Osoby == null || res.Osoby.Total < 5)) { var sw = new Devmasters.Core.StopWatchEx(); sw.Start(); if (res.Osoby == null) { res.Osoby = new GeneralResult <Osoba>(new Osoba[] { }); } res.Osoby = new GeneralResult <Osoba>(res.Osoby.Result .Concat(Osoba.GetPolitikByQueryFromFirmy(query, (int)(10 - (res.Osoby?.Total ?? 0)), res.Firmy.Result) ) ); res.OsobaFtx = true; sw.Stop(); res.AddOsobyTime = sw.Elapsed; } totalsw.Stop(); res.TotalSearchTime = totalsw.Elapsed; return(res); }