コード例 #1
0
        public List<CompanySelectionModel> PerformCustomerSearch(string query)
        {
            var e = new ElasticSearchManager(_elasticSearchUrl);
            var client = e.CreateEsClient();

            var kunder = client.Search<KundeIndexItem>(d => d.
                Query(q =>
                    q.Bool(b =>
                        b.Should(
                            sh => sh.MatchPhrasePrefix(pf =>
                                pf.Field(f => f.Navn1).Query(query).Slop(2).Boost(3)
                                ),
                            sh => sh.MatchPhrasePrefix(pf =>
                                pf.Field(f => f.Adresse1).Query(query).Slop(2).Boost(1)
                                )
                            ).
                            MinimumShouldMatch(1)
                        )
                ).Size(200)
                );

            var kunderResult = kunder.Documents.Select(k => new CompanySelectionModel()
            {
                Id = Guid.Parse(k.Id),
                Name = k.Navn1,
                Address = k.Adresse1
            }).ToList();

            return kunderResult;
        }
コード例 #2
0
        public KundeIndexItem Get(Guid kundeId)
        {
            var e = new ElasticSearchManager(_elasticSearchUrl);
            var client = e.CreateEsClient();

            var kundeRespone = client.Get<KundeIndexItem>(kundeId);

            return kundeRespone.Source;
        }
コード例 #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Task.Run(() =>
            {
                var indexer = new ElasticSearchManager(Properties.Settings.Default.ElasticSearchUrl);

                indexer.IndexCustomers();
            });
        }