Ejemplo n.º 1
0
        public ContentResult PerRequest()
        {
            Stopwatch sw = Stopwatch.StartNew();
            var       searchConnectionConfiguration = new SearchConnectionConfiguration(_searchServiceModel);
            var       esClient = new ElasticClient(searchConnectionConfiguration.Settings);
            var       query    = Query <Models.Content> .Match(m => m.Field(f => f.ContentText).Query("therefore"));

            var searchResults = esClient.Search <Models.Content>(c => c
                                                                 .From(0)
                                                                 .Size(10)
                                                                 .Query(x => query)
                                                                 );

            sw.Stop();
            return(Content(sw.Elapsed.TotalMilliseconds.ToString()));
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            var elasticConfigSection = Configuration.GetSection("ElasticConfiguration");
            var elasticConfig        = new SearchServiceModel
            {
                Host      = elasticConfigSection.GetValue <string>("Host"),
                IndexName = elasticConfigSection.GetValue <string>("IndexName"),
                Port      = elasticConfigSection.GetValue <int>("Port")
            };

            services.Configure <SearchServiceModel>(elasticConfigSection);

            SearchConnectionConfiguration settings = new SearchConnectionConfiguration(elasticConfig);

            services.AddSingleton <SearchConnectionConfiguration>(settings);
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SearchConnectionConfiguration searchConnectionConfiguration)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            SearchClientConfiguration elastic = new SearchClientConfiguration(searchConnectionConfiguration);

            if (elastic.CreateIndex <Content>() == IndexStatus.Created)
            {
                elastic.AddBulkData <Content>(GetSampleContents());
            }

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}");
            });
        }
Ejemplo n.º 4
0
 public HomeController(IOptions <SearchServiceModel> elastic, SearchConnectionConfiguration settings)
 {
     _searchServiceModel            = elastic.Value;
     _searchConnectionConfiguration = settings;
 }