feat: add mobile shell and unified search
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Failing after 50s
ci / 워크스페이스 빌드 검증 (push) Has been skipped
ci / Supabase Edge Functions + Cloudflare Worker (push) Successful in 20s
ci / .NET API 서버 테스트 (push) Successful in 12s
deploy-site / deploy (push) Successful in 39s
ci / 모바일 린트·타입·Jest (push) Failing after 3h10m31s
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Failing after 50s
ci / 워크스페이스 빌드 검증 (push) Has been skipped
ci / Supabase Edge Functions + Cloudflare Worker (push) Successful in 20s
ci / .NET API 서버 테스트 (push) Successful in 12s
deploy-site / deploy (push) Successful in 39s
ci / 모바일 린트·타입·Jest (push) Failing after 3h10m31s
This commit is contained in:
parent
f505a03d34
commit
5ca3709b32
98 changed files with 5168 additions and 2093 deletions
|
|
@ -30,6 +30,7 @@ import { registerAdsHandlers } from './ads-handlers'
|
|||
import { registerSupportHandlers } from './support-handlers'
|
||||
import { registerInputTelemetryHandlers } from './input-telemetry-handlers'
|
||||
import { registerSuggestionHandlers } from './suggestion-handlers'
|
||||
import { registerUnifiedSearchHandlers } from './unified-search-handlers'
|
||||
import { getLogger } from '../services/LoggerService'
|
||||
|
||||
const logger = getLogger('ipc')
|
||||
|
|
@ -44,6 +45,7 @@ export function registerAllIpcHandlers(): void {
|
|||
registerKeyBindingHandlers()
|
||||
registerLLMHandlers()
|
||||
registerHistoryHandlers()
|
||||
registerUnifiedSearchHandlers()
|
||||
registerDictionaryHandlers()
|
||||
registerInstructionHandlers()
|
||||
registerMemoHandlers()
|
||||
|
|
|
|||
19
apps/desktop/src/main/ipc/unified-search-handlers.ts
Normal file
19
apps/desktop/src/main/ipc/unified-search-handlers.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { ipcMain } from 'electron'
|
||||
import { D3ROError, ErrorCode, ipcError, ipcSuccess } from '@d3ro/core/errors'
|
||||
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
||||
import {
|
||||
getUnifiedSearchService,
|
||||
validateUnifiedSearchParams,
|
||||
} from '../services/UnifiedSearchService'
|
||||
|
||||
export function registerUnifiedSearchHandlers(): void {
|
||||
ipcMain.handle(IPC_CHANNELS.UNIFIED_SEARCH.QUERY, (_event, params: unknown) => {
|
||||
try {
|
||||
const validatedParams = validateUnifiedSearchParams(params)
|
||||
return ipcSuccess(getUnifiedSearchService().search(validatedParams))
|
||||
} catch (error) {
|
||||
if (error instanceof D3ROError) return ipcError(error.code, error.message, error.details)
|
||||
return ipcError(ErrorCode.DBQueryFailed, 'Unified search failed')
|
||||
}
|
||||
})
|
||||
}
|
||||
182
apps/desktop/src/main/services/UnifiedSearchService.ts
Normal file
182
apps/desktop/src/main/services/UnifiedSearchService.ts
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
// 기록과 회의를 스키마 변경 없이 함께 찾는 로컬 통합 검색.
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
import { count, desc, or } from 'drizzle-orm'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
import type {
|
||||
UnifiedSearchParams,
|
||||
UnifiedSearchResponse,
|
||||
UnifiedSearchResult,
|
||||
} from '@d3ro/core/types'
|
||||
import { getDatabase } from '../db'
|
||||
import { containsPattern } from '../db/like-pattern'
|
||||
import { history, meetingSessions, type History, type MeetingSessionRow } from '../db/schema'
|
||||
import { getLogger } from './LoggerService'
|
||||
|
||||
const logger = getLogger('UnifiedSearchService')
|
||||
const DEFAULT_LIMIT = 30
|
||||
const MAX_LIMIT = 50
|
||||
const MAX_QUERY_LENGTH = 200
|
||||
const EXCERPT_LENGTH = 180
|
||||
|
||||
export function validateUnifiedSearchParams(value: unknown): UnifiedSearchParams {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
||||
throw new D3ROError(ErrorCode.ConfigInvalidValue, 'Unified search parameters are required')
|
||||
}
|
||||
|
||||
const candidate = value as Record<string, unknown>
|
||||
if (typeof candidate.query !== 'string') {
|
||||
throw new D3ROError(ErrorCode.ConfigInvalidValue, 'Unified search query must be a string', {
|
||||
field: 'query',
|
||||
})
|
||||
}
|
||||
if (
|
||||
candidate.limit !== undefined
|
||||
&& (typeof candidate.limit !== 'number' || !Number.isFinite(candidate.limit))
|
||||
) {
|
||||
throw new D3ROError(ErrorCode.ConfigInvalidValue, 'Unified search limit must be a finite number', {
|
||||
field: 'limit',
|
||||
})
|
||||
}
|
||||
|
||||
return candidate.limit === undefined
|
||||
? { query: candidate.query }
|
||||
: { query: candidate.query, limit: candidate.limit as number }
|
||||
}
|
||||
|
||||
export function normalizeUnifiedSearchQuery(value: string): string {
|
||||
return value.slice(0, MAX_QUERY_LENGTH).trim().replace(/\s+/g, ' ')
|
||||
}
|
||||
|
||||
function includesQuery(value: string | null | undefined, query: string): boolean {
|
||||
return value?.toLocaleLowerCase().includes(query.toLocaleLowerCase()) === true
|
||||
}
|
||||
|
||||
export function createUnifiedSearchExcerpt(
|
||||
value: string | null | undefined,
|
||||
query: string,
|
||||
maxLength = EXCERPT_LENGTH,
|
||||
): string {
|
||||
const text = (value ?? '').replace(/\s+/g, ' ').trim()
|
||||
if (text.length <= maxLength) return text
|
||||
|
||||
const matchAt = text.toLocaleLowerCase().indexOf(query.toLocaleLowerCase())
|
||||
if (matchAt < 0) return `${text.slice(0, maxLength - 1).trimEnd()}…`
|
||||
|
||||
const context = Math.max(20, Math.floor((maxLength - query.length) / 2))
|
||||
const start = Math.max(0, matchAt - context)
|
||||
const end = Math.min(text.length, start + maxLength)
|
||||
const body = text.slice(start, end).trim()
|
||||
return `${start > 0 ? '…' : ''}${body}${end < text.length ? '…' : ''}`
|
||||
}
|
||||
|
||||
function recordResult(row: History, query: string): UnifiedSearchResult {
|
||||
const titleMatched = includesQuery(row.title, query)
|
||||
const matchingContent = [row.polishedText, row.originalText, row.summaryText]
|
||||
.find((value) => includesQuery(value, query))
|
||||
const displayContent = matchingContent ?? row.polishedText ?? row.originalText ?? row.summaryText ?? row.title
|
||||
|
||||
return {
|
||||
source: 'record',
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
excerpt: createUnifiedSearchExcerpt(displayContent, query),
|
||||
matchedField: titleMatched ? 'title' : 'content',
|
||||
occurredAt: row.createdAt,
|
||||
}
|
||||
}
|
||||
|
||||
function meetingResult(row: MeetingSessionRow, query: string): UnifiedSearchResult {
|
||||
const titleMatched = includesQuery(row.title, query)
|
||||
const matchingTranscript = [row.editedTranscript, row.rawTranscript]
|
||||
.find((value) => includesQuery(value, query))
|
||||
const displayContent = matchingTranscript ?? row.editedTranscript ?? row.rawTranscript ?? row.title
|
||||
|
||||
return {
|
||||
source: 'meeting',
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
excerpt: createUnifiedSearchExcerpt(displayContent, query),
|
||||
matchedField: titleMatched ? 'title' : 'transcript',
|
||||
occurredAt: row.startedAt,
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeUnifiedSearchResults(
|
||||
records: readonly UnifiedSearchResult[],
|
||||
meetings: readonly UnifiedSearchResult[],
|
||||
limit: number,
|
||||
): UnifiedSearchResult[] {
|
||||
return [...records, ...meetings]
|
||||
.sort((left, right) => right.occurredAt - left.occurredAt || left.id.localeCompare(right.id))
|
||||
.slice(0, limit)
|
||||
}
|
||||
|
||||
class UnifiedSearchService extends EventEmitter {
|
||||
search(value: unknown): UnifiedSearchResponse {
|
||||
const params = validateUnifiedSearchParams(value)
|
||||
const query = normalizeUnifiedSearchQuery(params.query)
|
||||
const limit = Math.max(1, Math.min(Math.floor(params.limit ?? DEFAULT_LIMIT), MAX_LIMIT))
|
||||
if (query.length === 0) return { query, results: [], total: 0 }
|
||||
|
||||
try {
|
||||
const db = getDatabase()
|
||||
const pattern = containsPattern(query)
|
||||
const recordConditions = or(
|
||||
pattern.match(history.title),
|
||||
pattern.match(history.originalText),
|
||||
pattern.match(history.polishedText),
|
||||
pattern.match(history.summaryText),
|
||||
)
|
||||
const meetingConditions = or(
|
||||
pattern.match(meetingSessions.title),
|
||||
pattern.match(meetingSessions.editedTranscript),
|
||||
pattern.match(meetingSessions.rawTranscript),
|
||||
)
|
||||
|
||||
const recordTotal = db.select({ count: count() }).from(history).where(recordConditions).get()?.count ?? 0
|
||||
const recordRows = db
|
||||
.select()
|
||||
.from(history)
|
||||
.where(recordConditions)
|
||||
.orderBy(desc(history.createdAt))
|
||||
.limit(limit)
|
||||
.all()
|
||||
const meetingTotal = db.select({ count: count() }).from(meetingSessions).where(meetingConditions).get()?.count ?? 0
|
||||
const meetingRows = db
|
||||
.select()
|
||||
.from(meetingSessions)
|
||||
.where(meetingConditions)
|
||||
.orderBy(desc(meetingSessions.startedAt))
|
||||
.limit(limit)
|
||||
.all()
|
||||
|
||||
const results = mergeUnifiedSearchResults(
|
||||
recordRows.map((row) => recordResult(row, query)),
|
||||
meetingRows.map((row) => meetingResult(row, query)),
|
||||
limit,
|
||||
)
|
||||
return { query, results, total: recordTotal + meetingTotal }
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
logger.error(`Unified search failed: ${message}`)
|
||||
throw new D3ROError(ErrorCode.DBQueryFailed, 'Unified search failed', { cause: message })
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.removeAllListeners()
|
||||
}
|
||||
}
|
||||
|
||||
let instance: UnifiedSearchService | null = null
|
||||
|
||||
export function getUnifiedSearchService(): UnifiedSearchService {
|
||||
if (instance === null) instance = new UnifiedSearchService()
|
||||
return instance
|
||||
}
|
||||
|
||||
export function resetUnifiedSearchServiceForTests(): void {
|
||||
instance?.dispose()
|
||||
instance = null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue