public static IEnumerable <FoundDocument <Post> > SearchPost(string term, int top) { var query = CreatePostQuery(term); var searchResult = LuceneExtensions.SearchIndex(query, top); foreach (var item in searchResult.Documents) { var IdInt32 = item.Document.GetField("IdInt32"); var IdString = item.Document.GetField("IdString"); var TitleString = item.Document.GetField("TitleString"); var TitleText = item.Document.GetField("TitleText"); var TitleFullTextSearchHighlight = item.Document.GetField("TitleFullTextSearchHighlight"); //var bodyField = item.Document.GetField("Post.Body"); var PublishDateTicksStored = item.Document.GetField("PublishDateTicksStored"); var PublishDateStringStored = item.Document.GetField("PublishDateStringStored"); var LikeCountStored = item.Document.GetField("LikeCountStored"); var LikeCountInt32 = item.Document.GetField("LikeCountInt32"); //var LikeCountSortedDocValues = item.Document.GetField("LikeCountSortedDocValues"); yield return(new FoundDocument <Post> { Score = item.Score, Document = new Post { IdInt32 = IdInt32.GetInt32Value() ?? throw null, IdString = Convert.ToInt32(IdString.GetStringValue()), TitleString = TitleString.GetStringValue(), TitleText = TitleText.GetStringValue(), TitleFullTextSearchHighlight = TitleFullTextSearchHighlight.GetStringValue(), PublishDateTicksStored = new DateTime(PublishDateTicksStored.GetInt64Value() ?? throw null), PublishDateStringStored = DateTime.Parse(PublishDateStringStored.GetStringValue()), LikeCountStored = LikeCountStored.GetInt32Value() ?? throw null, LikeCountInt32 = LikeCountInt32.GetInt32Value() ?? throw null, //LikeCountSortedDocValues = LikeCountSortedDocValues.GetInt32Value() ?? throw null, } });
public static void Test() { LuceneExtensions.DeleteAll(); var posts = new Post[] { new Post(101, "آموزش Entity Framework", "در این مقاله به آموزش Entity Framework می پردازیم", new DateTime(2021, 01, 01), 11), new Post(102, "آموزش ASP.NET MVC", "در این مقاله به آموزش ASP.NET MVC می پردازیم", new DateTime(2021, 01, 02), 12), new Post(103, "آموزش EF Core", "در این مقاله به آموزش EF Core می پردازیم", new DateTime(2021, 01, 03), 13), new Post(104, "آموزش ASP.NET Core", "در این مقاله به آموزش ASP.NET Core می پردازیم", new DateTime(2021, 01, 04), 14), new Post(105, "آموزش Domain Driven Design", "در این مقاله به آموزش Domain Driven Design می پردازیم", new DateTime(2021, 01, 05), 15), new Post(106, "آموزش Microservices", "در این مقاله به آموزش Microservices می پردازیم", new DateTime(2021, 01, 06), 16), new Post(107, "از به با برای C#", "در این مقاله به آموزش C# می پردازیم", new DateTime(2021, 01, 07), 17), new Post(108, "یکسان Title", "در این مقاله به بررسی Term می پردازیم", new DateTime(2021, 01, 08), 18), new Post(109, "یکسان Title", "در این مقاله به بررسی Match می پردازیم", new DateTime(2021, 01, 09), 19), }; IndexPosts(posts); #region TitleString { PostSearchField = "TitleString"; var resultx1 = SearchPost("آموزش ASP.NET MVC", 3).ToList(); var resultx2 = SearchPost("آموزش EF Core", 3).ToList(); var resultx3 = SearchPost("اموزش ASP.NET MVC", 3).ToList(); var resultx4 = SearchPost("اموزش EF Core", 3).ToList(); var result01 = SearchPost("Entity", 3).ToList(); var result02 = SearchPost("Framework", 3).ToList(); var result03 = SearchPost("Entity Framework", 3).ToList(); var result04 = SearchPost("ASP", 3).ToList(); var result05 = SearchPost("ASP.NET", 3).ToList(); var result06 = SearchPost("ASP.NET Core", 3).ToList(); var result07 = SearchPost("ASP.NET MVC", 3).ToList(); var result08 = SearchPost("MVC", 3).ToList(); var result09 = SearchPost("EF", 3).ToList(); var result10 = SearchPost("EF Core", 3).ToList(); var result11 = SearchPost("Domain", 3).ToList(); var result12 = SearchPost("Domain Driven Design", 3).ToList(); var result13 = SearchPost("Microservices", 3).ToList(); var result14 = SearchPost("آموزش", 3).ToList(); var result15 = SearchPost("Core", 3).ToList(); var result16 = SearchPost("Design", 3).ToList(); var result17 = SearchPost("Design Driven Domain", 3).ToList(); var result18 = SearchPost("چرت", 3).ToList(); var result19 = SearchPost("اموزش", 3).ToList(); var result20 = SearchPost("برای", 3).ToList(); var result21 = SearchPost("C#", 3).ToList(); var result22 = SearchPost("C", 3).ToList(); } #endregion #region TitleText { PostSearchField = "TitleText"; var resultx1 = SearchPost("آموزش ASP.NET MVC", 3).ToList(); var resultx2 = SearchPost("آموزش EF Core", 3).ToList(); var resultx3 = SearchPost("اموزش ASP.NET MVC", 3).ToList(); var resultx4 = SearchPost("اموزش EF Core", 3).ToList(); var result01 = SearchPost("Entity", 3).ToList(); var result02 = SearchPost("Framework", 3).ToList(); var result03 = SearchPost("Entity Framework", 3).ToList(); var result04 = SearchPost("ASP", 3).ToList(); var result05 = SearchPost("ASP.NET", 3).ToList(); var result06 = SearchPost("ASP.NET Core", 3).ToList(); var result07 = SearchPost("ASP.NET MVC", 3).ToList(); var result08 = SearchPost("MVC", 3).ToList(); var result09 = SearchPost("EF", 3).ToList(); var result10 = SearchPost("EF Core", 3).ToList(); var result11 = SearchPost("Domain", 3).ToList(); var result12 = SearchPost("Domain Driven Design", 3).ToList(); var result13 = SearchPost("Microservices", 3).ToList(); var result14 = SearchPost("آموزش", 3).ToList(); var result15 = SearchPost("Core", 3).ToList(); var result16 = SearchPost("Design", 3).ToList(); var result17 = SearchPost("Design Driven Domain", 3).ToList(); var result18 = SearchPost("چرت", 3).ToList(); var result19 = SearchPost("اموزش", 3).ToList(); var result20 = SearchPost("برای", 3).ToList(); var result21 = SearchPost("C#", 3).ToList(); var result22 = SearchPost("C", 3).ToList(); } #endregion #region TitleFullTextSearchHighlight { PostSearchField = "TitleFullTextSearchHighlight"; var result01 = SearchPost("Entity", 3).ToList(); var result02 = SearchPost("Framework", 3).ToList(); var result03 = SearchPost("Entity Framework", 3).ToList(); var result04 = SearchPost("ASP", 3).ToList(); var result05 = SearchPost("ASP.NET", 3).ToList(); var result06 = SearchPost("ASP.NET Core", 3).ToList(); var result07 = SearchPost("ASP.NET MVC", 3).ToList(); var result08 = SearchPost("MVC", 3).ToList(); var result09 = SearchPost("EF", 3).ToList(); var result10 = SearchPost("EF Core", 3).ToList(); var result11 = SearchPost("Domain", 3).ToList(); var result12 = SearchPost("Domain Driven Design", 3).ToList(); var result13 = SearchPost("Microservices", 3).ToList(); var result14 = SearchPost("آموزش", 3).ToList(); var result15 = SearchPost("Core", 3).ToList(); var result16 = SearchPost("Design", 3).ToList(); var result17 = SearchPost("Design Driven Domain", 3).ToList(); var result18 = SearchPost("چرت", 3).ToList(); var result19 = SearchPost("اموزش", 3).ToList(); var result20 = SearchPost("برای", 3).ToList(); var result21 = SearchPost("C#", 3).ToList(); var result22 = SearchPost("C", 3).ToList(); } #endregion }