// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); // register the client as a singleton services.Add(ServiceDescriptor.Singleton <IElasticClient>(NuSearchConfiguration.GetClient())); }
static void Main(string[] args) { Client = NuSearchConfiguration.GetClient(); DumpReader = new NugetDumpReader(@"C:\work\ElasticSearch\NugetDump"); CurrentIndexName = NuSearchConfiguration.CreateIndexName(); var packages = DumpReader.Dumps.Take(1).First().NugetPackages; foreach (var package in packages) { var result = Client.Index(package); if (!result.IsValid) { Console.WriteLine(result.DebugInformation); Console.Read(); Environment.Exit(1); } Console.WriteLine("Done."); } //CreateIndex(); IndexDumps(); //SwapAlias(); Console.Read(); }
public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.AddControllersWithViews(); services.AddSingleton <IElasticClient>(NuSearchConfiguration.GetClient()); }
static void Main(string[] args) { Client = NuSearchConfiguration.GetClient(); DumpReader = new NugetDumpReader(@"C:\nuget-data"); IndexDumps(); Console.Read(); }
static void Main(string[] args) { Client = NuSearchConfiguration.GetClient(); CurrentIndexName = NuSearchConfiguration.CreateIndexName(); DeleteIndexIfExists(); DumpReader = new NugetDumpReader(@"C:\Projects\test\elasticsearch-net-example\nuget-data-dec-2016"); CreateIndex(); IndexDumps(); SwapAlias(); Console.Read(); }
static void Main(string[] args) { Client = NuSearchConfiguration.GetClient(); var directory = args.Length > 0 && !string.IsNullOrEmpty(args[0]) ? args[0] : NuSearchConfiguration.PackagePath; DumpReader = new NugetDumpReader(directory); CurrentIndexName = NuSearchConfiguration.CreateIndexName(); CreateIndex(); IndexDumps(); SwapAlias(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
static void Main(string[] args) { Client = NuSearchConfiguration.GetClient(); string directory = args.Length > 0 && !string.IsNullOrEmpty(args[0]) ? args[0] : NuSearchConfiguration.PackagePath; DumpReader = new NugetDumpReader(directory); var command = new NestCommand(Client, DumpReader); command.DeleteIndexIfExists(); command.CreateIndex(); command.InsertDocuments(); Console.WriteLine("Press Enter to continue"); Console.Read(); }
public SearchModule() { Get["/"] = x => { var form = this.Bind <SearchForm>(); var model = new SearchViewModel(); // You'll be writing most of your code here var client = NuSearchConfiguration.GetClient(); var result = client.Search <Package>(s => s); model.Packages = result.Documents; model.Total = result.Total; model.Form = form; return(View[model]); }; }
// private static string CurrentIndexName{ get; set; } static void Main(string[] args) { Client = NuSearchConfiguration.GetClient(); var directory = args.Length > 0 && !string.IsNullOrEmpty(args[0]) ? args[0] : NuSearchConfiguration.PackagePath; DumpReader = new NugetDumpReader(directory); // CurrentIndexName = NuSearchConfiguration.CreateIndexName(); // No need to delete when doing SwapAlias... DeleteIndexIfExists(); CreateIndex(); IndexDumps(); // SwapAlias(); Console.WriteLine("Press ENTER to exit."); Console.Read(); }
public SuggestModule() { Post["/suggest"] = x => { var form = this.Bind <SearchForm>(); var client = NuSearchConfiguration.GetClient(); var result = client.Search <Package>(s => s .Index <Package>() .Source(sf => sf .Includes(f => f .Field(ff => ff.Id) .Field(ff => ff.DownloadCount) .Field(ff => ff.Summary) ) ) .Suggest(su => su .Completion("package-suggestions", c => c .Prefix(form.Query) .Field(p => p.Suggest) ) ) ); var suggestions = result.Suggest["package-suggestions"] .FirstOrDefault() .Options .Select(suggest => new { id = suggest.Source.Id, downloadCount = suggest.Source.DownloadCount, summary = !string.IsNullOrEmpty(suggest.Source.Summary) ? string.Concat(suggest.Source.Summary.Take(200)) : string.Empty }); return(Response.AsJson(suggestions)); }; }
public SearchModule() { Get["/"] = x => { var form = this.Bind <SearchForm>(); var model = new SearchViewModel(); var client = NuSearchConfiguration.GetClient(); var result = client.Search <Package>(s => s .From((form.Page - 1) * form.PageSize) .Size(form.PageSize) .Sort(sort => { if (form.Sort == SearchSort.Downloads) { return(sort.Descending(p => p.DownloadCount)); } else if (form.Sort == SearchSort.Recent) { return(sort.Field(sortField => sortField .NestedPath(p => p.Versions) .Field(p => p.Versions.First().LastUpdated) .Descending() )); } else { return(sort.Descending("_score")); } }) .Query(q => q .Match(m => m .Field(p => p.Id.Suffix("keyword")) .Boost(1000) .Query(form.Query) ) || q.FunctionScore(fs => fs .Functions(ff => ff .FieldValueFactor(fvf => fvf .Field(p => p.DownloadCount) .Factor(0.0001) ) ) .Query(query => query .MultiMatch(m => m .Fields(f => f .Field(p => p.Id, 1.2) .Field(p => p.Summary, 0.8) ) .Operator(Operator.And) .Query(form.Query) ) ) ) && +q .Nested(n => n .Path(p => p.Authors) .Query(nq => + nq .Term(p => p.Authors.First().Name.Suffix("raw"), form.Author) ) ) ) .Aggregations(a => a .Nested("authors", n => n .Path("authors") .Aggregations(aa => aa .Terms("author-names", ts => ts .Field(p => p.Authors.First().Name.Suffix("raw")) ) ) ) ) ); var authors = result.Aggs.Nested("authors") .Terms("author-names") .Buckets .ToDictionary(k => k.Key, v => v.DocCount); model.Authors = authors; model.Packages = result.Documents; model.Total = result.Total; model.TotalPages = (int)Math.Ceiling(result.Total / (double)form.PageSize); model.Form = form; return(View[model]); }; }