Esempio n. 1
0
        public static MultiResult GeneralSearch(string query, int page = 1, int pageSize = 10)
        {
            MultiResult res = new MultiResult()
            {
                Query = query
            };

            if (string.IsNullOrEmpty(query))
            {
                return(res);
            }


            ParallelOptions po = new ParallelOptions();

            po.MaxDegreeOfParallelism = System.Diagnostics.Debugger.IsAttached ? 1 : po.MaxDegreeOfParallelism;

            Parallel.Invoke(po,
                            () =>
            {
                try
                {
                    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);
                }
            },
                            () =>
            {
                try
                {
                    res.Smlouvy = HlidacStatu.Lib.ES.SearchTools.SimpleSearch(query, 1, 20, ES.SearchTools.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);
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx();
                    sw.Start();

                    res.Firmy = new GeneralResult <string>(Firma.Search.FindAllIco(query, 1000));
                    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, 20, (int)ES.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
                {
                    Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx();
                    sw.Start();
                    var buRes = HlidacStatu.Lib.Data.TransparentniUcty.BankovniUcty.SearchPolozkyRaw(query, null, 20);
                    if (buRes != null && buRes.IsValid)
                    {
                        res.Transakce = new GeneralResult <TransparentniUcty.BankovniPolozka>(
                            buRes.Total,
                            buRes.Hits.Select(m => m.Source),
                            buRes.IsValid
                            );
                    }
                    else
                    {
                        res.Transakce = new GeneralResult <TransparentniUcty.BankovniPolozka>(new TransparentniUcty.BankovniPolozka[] { });
                    }
                    sw.Stop();
                    res.Transakce.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for bankovni ucty query" + query, e);
                }
            }
                            );

            if (res.HasFirmy && (res.Osoby == null || res.Osoby.Total < 5))
            {
                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;
            }



            return(res);
        }
Esempio n. 2
0
        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);
        }