瀏覽代碼

搜索优化

懒得勤快 4 年之前
父節點
當前提交
96d7bf718d

+ 10 - 1
src/Masuit.MyBlogs.Core/Infrastructure/Services/PostService.cs

@@ -1,4 +1,5 @@
 using CacheManager.Core;
+using Lucene.Net.Search;
 using Masuit.LuceneEFCore.SearchEngine;
 using Masuit.LuceneEFCore.SearchEngine.Interfaces;
 using Masuit.MyBlogs.Core.Common;
@@ -120,7 +121,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services
 
                 if (p.Content.Length > 200 && !handled)
                 {
-                    p.Content = p.Content.Substring(0, 200);
+                    p.Content = p.Content[..200];
                 }
             }
         }
@@ -148,6 +149,14 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services
                 searchOptions.Score = 0.2f;
             }
 
+            searchOptions.OrderBy = new List<SortField>()
+            {
+                SortField.FIELD_DOC,
+                SortField.FIELD_SCORE
+            };
+            searchOptions.SetBoosts(nameof(Post.Keyword), 2000);
+            searchOptions.SetBoosts(nameof(Post.Content), 2000);
+            searchOptions.SetBoosts(nameof(Post.Title), 1000);
             return searchOptions;
         }
 

+ 1 - 1
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -47,7 +47,7 @@
         <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="5.0.5" />
         <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.5" />
         <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="5.0.1" />
-        <PackageReference Include="Microsoft.Graph" Version="3.30.0" />
+        <PackageReference Include="Microsoft.Graph" Version="3.31.0" />
         <PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.6" />
         <PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.2.22" />
         <PackageReference Include="OpenXmlPowerTools-NetStandard" Version="4.4.21" />

+ 1 - 0
src/Masuit.MyBlogs.Core/Models/Entity/Post.cs

@@ -58,6 +58,7 @@ namespace Masuit.MyBlogs.Core.Models.Entity
         /// <summary>
         /// ÐÞ¸Äʱ¼ä
         /// </summary>
+        [LuceneIndex]
         public DateTime ModifyDate { get; set; }
 
         /// <summary>

+ 1 - 1
src/Masuit.MyBlogs.Core/Properties/launchSettings.json

@@ -18,7 +18,7 @@
     "Masuit.MyBlogs.Core": {
       "commandName": "Project",
       "environmentVariables": {
-        "ASPNETCORE_ENVIRONMENT": ""
+        "ASPNETCORE_ENVIRONMENT": "Development"
       },
       "applicationUrl": "http://localhost:5000"
     }