代码拉取完成,页面将自动刷新
同步操作将从 懒得勤快/Masuit.LuceneEFCore.SearchEngine 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using Masuit.LuceneEFCore.SearchEngine;
using Masuit.LuceneEFCore.SearchEngine.Extensions;
using Masuit.LuceneEFCore.SearchEngine.Interfaces;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace Test
{
class Program
{
static ServiceProvider provide = null;
static void Main(string[] args)
{
Ini();
var _searchEngine = provide.GetService<ISearchEngine<DataContext>>();
// search
{
var options = new SearchOptions("思杰", 1, 10, typeof(Post));
var result = _searchEngine.ScoredSearch<Post>(options);
}
// create index
{
_searchEngine.CreateIndex(); // create full
_searchEngine.CreateIndex(new List<string> { nameof(Post) });
}
// add index
{
_searchEngine.Context.Post.Add(new Post { });
_searchEngine.SaveChanges();
}
// delete index
{
//从数据库删除并更新索引库
Post p = _searchEngine.Context.Post.Find(1);
_searchEngine.Context.Post.Remove(p);
_searchEngine.SaveChanges();
}
// update index
{
//从数据库删除并更新索引库
Post p = _searchEngine.Context.Post.Find(1);
_searchEngine.Context.Post.Update(p);
_searchEngine.SaveChanges();
}
Console.WriteLine("Hello World!");
}
static void Ini()
{
RegService();
var context = provide.GetService<DataContext>();
var searchEngine = provide.GetService<ISearchEngine<DataContext>>();
// 写入测试数据
context.Post.AddRange(
JsonConvert.DeserializeObject<List<Post>>(
File.ReadAllText(AppContext.BaseDirectory + "Posts.json")));
context.SaveChanges();
// 创建索引
searchEngine.CreateIndex(new List<string>()
{
nameof(Post)
});
}
static void RegService()
{
IServiceCollection services = new ServiceCollection();
LuceneIndexerOptions luceneIndexerOptions = new LuceneIndexerOptions()
{
Path = "lucene"
};
services.AddDbContext<DataContext>(db => db.UseInMemoryDatabase("test"));
services.AddSearchEngine<DataContext>(luceneIndexerOptions);
provide = services.BuildServiceProvider();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。