MCPcopy Create free account
hub / github.com/experdot/pointer / performGlobalSearch

Function performGlobalSearch

src/renderer/src/utils/globalSearchUtils.ts:234–306  ·  view source on GitHub ↗
(
  query: string,
  options: GlobalSearchOptions,
  pages: PageRecord[],
  loadMessages: (pageId: string) => Promise<MessagesRecord>
)

Source from the content-addressed store, hash-verified

232 * 执行全局搜索
233 */
234export async function performGlobalSearch(
235 query: string,
236 options: GlobalSearchOptions,
237 pages: PageRecord[],
238 loadMessages: (pageId: string) => Promise<MessagesRecord>
239): Promise<GlobalSearchResult> {
240 if (!query.trim()) {
241 return { groups: [], totalCount: 0 }
242 }
243
244 const pattern = createSearchPattern(query, {
245 matchCase: options.matchCase,
246 useRegex: options.useRegex,
247 matchWholeWord: options.matchWholeWord
248 })
249
250 if (!pattern) {
251 return { groups: [], totalCount: 0 }
252 }
253
254 const groups: GlobalSearchResultGroup[] = []
255 let totalCount = 0
256
257 // 获取所有文件夹用于计算路径
258 const folders = useFoldersStore.getState().folders
259
260 // 根据文件夹筛选过滤页面
261 const filteredPages = pages.filter((page) =>
262 isInFolders(page.parentFolderId, options.folderIds, folders)
263 )
264
265 // 并行加载所有页面的消息
266 const messagePromises = filteredPages.map(async (page) => {
267 try {
268 const record = await loadMessages(page.id)
269 return { page, record }
270 } catch {
271 return { page, record: null }
272 }
273 })
274
275 const results = await Promise.all(messagePromises)
276
277 for (const { page, record } of results) {
278 if (!record?.messages.length) continue
279
280 const messageGroups = searchInMessages(record.messages, pattern, page.id, options)
281
282 if (messageGroups.length > 0) {
283 // 计算该页面的总匹配数
284 const pageMatchCount = messageGroups.reduce((sum, mg) => sum + mg.matches.length, 0)
285
286 groups.push({
287 pageId: page.id,
288 pageTitle: page.name,
289 createdAt: page.createdAt,
290 folderPath: getFolderPath(page.parentFolderId, folders),
291 messageGroups,

Callers 1

useGlobalSearchFunction · 0.90

Calls 4

createSearchPatternFunction · 0.90
isInFoldersFunction · 0.85
searchInMessagesFunction · 0.85
getFolderPathFunction · 0.85

Tested by

no test coverage detected