瀏覽代碼

封装多方式搜索(整体、分词、单字)方法,优化封装方法

Lyyyi 16 小時之前
父節點
當前提交
8cf422a0c5

+ 6 - 10
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -1271,19 +1271,15 @@ namespace OASystem.API.Controllers
 
                     foreach (var item in result.Items)
                     {
-                        data.Add(new { 
-                            Data = new
-                            {
-                                item.Data.TeamName,
-                                item.Data.ClientUnit,
-                                item.Data.ClientName
-                            },
-                            MatchScore = item.MatchScore,
-                            MatchFields = item.MatchFields
+                        data.Add(new
+                        {
+                            item.Data.TeamName,
+                            item.Data.ClientUnit,
+                            item.Data.ClientName
                         });
                     }
                     
-                    return Ok(JsonView(true, "搜索成功!", data, data.Count));
+                    return Ok(JsonView(true, result.Message, data, data.Count));
                 }
 
                 return Ok(JsonView(true, result.Message));

+ 13 - 2
OASystem/OASystem.Api/OAMethodLib/GenericSearch/DynamicSearchService.cs

@@ -61,6 +61,7 @@ namespace OASystem.API.OAMethodLib.GenericSearch
 
                 return new SearchResult<T>
                 {
+                    Message = $"搜索成功!耗时:{stopwatch.ElapsedMilliseconds}ms",
                     Items = scoredItems,
                     TotalCount = totalCount,
                     Keyword = request.Keyword,
@@ -326,6 +327,7 @@ namespace OASystem.API.OAMethodLib.GenericSearch
             if (!string.IsNullOrWhiteSpace(request.Keyword))
             {
                 var searchAnalysis = AnalyzeSearchPattern(request.Keyword);
+                var keywordConditions = new List<string>(); // 专门存放关键字相关条件
 
                 // 符号分割的关键字条件
                 foreach (var segment in searchAnalysis.SymbolSegments)
@@ -339,7 +341,8 @@ namespace OASystem.API.OAMethodLib.GenericSearch
                             parameters.Add(new SugarParameter(paramName, $"%{cleanSegment}%"));
                             return $"{field} LIKE {paramName}";
                         });
-                        whereConditions.Add($"({string.Join(" OR ", fieldConditions)})");
+                        // 每个片段内部使用 OR 连接不同字段
+                        keywordConditions.Add($"({string.Join(" OR ", fieldConditions)})");
                     }
                 }
 
@@ -353,8 +356,16 @@ namespace OASystem.API.OAMethodLib.GenericSearch
                         parameters.Add(new SugarParameter(paramName, $"%{charStr}%"));
                         return $"{field} LIKE {paramName}";
                     });
-                    whereConditions.Add($"({string.Join(" OR ", fieldConditions)})");
+                    // 每个单字内部使用 OR 连接不同字段
+                    keywordConditions.Add($"({string.Join(" OR ", fieldConditions)})");
                 }
+
+                // 所有关键字条件使用 OR 连接
+                if (keywordConditions.Any())
+                {
+                    whereConditions.Add($"({string.Join(" OR ", keywordConditions)})");
+                }
+
             }
 
             // 构建过滤条件