public void CreateIndex() { //_searchEngine.CreateIndex();//扫描所有数据表,创建符合条件的库的索引 _searchEngine.CreateIndex(new List <string>() { nameof(Post) }); //创建指定的数据表的索引 }
/// <summary> /// 重建Lucene索引库 /// </summary> public void CreateLuceneIndex() { _searchEngine.CreateIndex(new List <string>() { nameof(DataContext.Post), }); var list = _searchEngine.Context.Post.Where(i => i.Status != Status.Pended).ToList(); _searchEngine.LuceneIndexer.Delete(list); }
/// <summary> /// 重建Lucene索引库 /// </summary> public void CreateLuceneIndex() { _searchEngine.LuceneIndexer.DeleteAll(); _searchEngine.CreateIndex(new List <string>() { nameof(DataContext.Post), }); var list = _postService.GetQuery(i => i.Status != Status.Published).ToList(); _searchEngine.LuceneIndexer.Delete(list); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataContext db, ISearchEngine <DataContext> searchEngine) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } db.Post.AddRange(JsonConvert.DeserializeObject <List <Post> >(File.ReadAllText(AppContext.BaseDirectory + "Posts.json"))); searchEngine.CreateIndex(new List <string>() { nameof(Post) }); app.UseSwagger().UseSwaggerUI(c => { c.SwaggerEndpoint($"/swagger/v1/swagger.json", "懒得勤快的博客,搜索引擎测试"); }); //配置swagger app.UseMvcWithDefaultRoute(); }
public async Task <IActionResult> Init() { var pageModel = await _articleService.GetArticles(1, 10000, a => a.State == ArticleState.Published, "id desc", true); //articles = articles.Where(a => a.State == ArticleState.Published).ToList(); //_luceneService.AddOrUpdateIndex<ArticleDto>(pageModel.Data, // a => { a.ArticleContentHtml=a.ArticleContentHtml?.NoHTML(); }, // a=>a.Id,a=>a.CreateDate,a=>a.LastModifyDate,a=>a.Summary,a=>a.Title,a=>a.ArticleContentHtml); _searchEngine.CreateIndex <ArticleDto, int>( pageModel.Data.ToArray(), a => a.Id, new LuceneIndexBehavior <ArticleDto>() .Include(new Expression <Func <ArticleDto, object> >[] { a => a.Id, a => a.CreateDate, a => a.CreateDate, a => a.LastModifyDate, a => a.Summary, a => a.Title, a => a.ArticleContentHtml }) .ForMember(a => a.ArticleContentHtml, html => html == null ? null : html.NoHTML(), null) .ForMember(a => a.Id, null, id => true)); return(Ok("ok")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataContext db, ISearchEngine <DataContext> searchEngine) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } new JiebaSegmenter().AddWord("会声会影"); //添加自定义词库 new JiebaSegmenter().AddWord("思杰马克丁"); //添加自定义词库 new JiebaSegmenter().AddWord("TeamViewer"); //添加自定义词库 db.Post.AddRange(JsonConvert.DeserializeObject <List <Post> >(File.ReadAllText(AppContext.BaseDirectory + "Posts.json"))); searchEngine.CreateIndex(new List <string>() { nameof(Post) }); app.UseSwagger().UseSwaggerUI(c => { c.SwaggerEndpoint($"/swagger/v1/swagger.json", "懒得勤快的博客,搜索引擎测试"); }); //配置swagger app.UseRouting().UseEndpoints(endpoints => { endpoints.MapControllers(); // 属性路由 endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); // 默认路由 }); }