MCPcopy
hub / github.com/fish2018/pansou / searchPlugins

Method searchPlugins

service/search_service.go:1232–1384  ·  view source on GitHub ↗

searchPlugins 搜索插件

(keyword string, plugins []string, forceRefresh bool, concurrency int, ext map[string]interface{})

Source from the content-addressed store, hash-verified

1230
1231// searchPlugins 搜索插件
1232func (s *SearchService) searchPlugins(keyword string, plugins []string, forceRefresh bool, concurrency int, ext map[string]interface{}) ([]model.SearchResult, error) {
1233 // 确保ext不为nil
1234 if ext == nil {
1235 ext = make(map[string]interface{})
1236 }
1237
1238 // 关键:将forceRefresh同步到插件ext["refresh"]
1239 if forceRefresh {
1240 ext["refresh"] = true
1241 }
1242
1243 // 生成缓存键
1244 cacheKey := cache.GeneratePluginCacheKey(keyword, plugins)
1245
1246
1247 // 如果未启用强制刷新,尝试从缓存获取结果
1248 if !forceRefresh && cacheInitialized && config.AppConfig.CacheEnabled {
1249 var data []byte
1250 var hit bool
1251 var err error
1252
1253 // 使用增强版缓存
1254 if enhancedTwoLevelCache != nil {
1255
1256 // 使用Get方法,它会检查磁盘缓存是否有更新
1257 // 如果磁盘缓存比内存缓存更新,会自动更新内存缓存并返回最新数据
1258 data, hit, err = enhancedTwoLevelCache.Get(cacheKey)
1259
1260 if err == nil && hit {
1261 var results []model.SearchResult
1262 if err := enhancedTwoLevelCache.GetSerializer().Deserialize(data, &results); err == nil {
1263 // 返回缓存数据
1264 fmt.Printf("✅ [%s] 命中缓存 结果数: %d\n", keyword, len(results))
1265 return results, nil
1266 } else {
1267 displayKey := cacheKey[:8] + "..."
1268 fmt.Printf("[主服务] 缓存反序列化失败: %s(关键词:%s) | 错误: %v\n", displayKey, keyword, err)
1269 }
1270 }
1271 }
1272 }
1273
1274 // 缓存未命中或强制刷新,执行实际搜索
1275
1276 // 获取所有可用插件
1277 var availablePlugins []plugin.AsyncSearchPlugin
1278 if s.pluginManager != nil {
1279 allPlugins := s.pluginManager.GetPlugins()
1280
1281 // 确保plugins不为nil并且有非空元素
1282 hasPlugins := plugins != nil && len(plugins) > 0
1283 hasNonEmptyPlugin := false
1284
1285 if hasPlugins {
1286 for _, p := range plugins {
1287 if p != "" {
1288 hasNonEmptyPlugin = true
1289 break

Callers 1

SearchMethod · 0.95

Calls 13

GeneratePluginCacheKeyFunction · 0.92
ExecuteBatchWithTimeoutFunction · 0.92
GetSerializerMethod · 0.80
GetPluginsMethod · 0.80
SetBothLevelsMethod · 0.80
DeserializeMethod · 0.65
NameMethod · 0.65
SetMainCacheKeyMethod · 0.65
SetCurrentKeywordMethod · 0.65
AsyncSearchMethod · 0.65
SearchMethod · 0.65
SerializeMethod · 0.65

Tested by

no test coverage detected