@open-mercato/search 0.10.1-develop.8279.1.7d4003fb64 → 0.10.1-develop.8287.1.7313a0fe67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -0
- package/dist/di.js +1 -0
- package/dist/di.js.map +2 -2
- package/dist/indexer/search-indexer.js +47 -15
- package/dist/indexer/search-indexer.js.map +2 -2
- package/dist/modules/search/ai-tools.js +69 -4
- package/dist/modules/search/ai-tools.js.map +2 -2
- package/dist/modules/search/api/search/global/route.js +2 -1
- package/dist/modules/search/api/search/global/route.js.map +2 -2
- package/dist/modules/search/api/search/route.js +2 -1
- package/dist/modules/search/api/search/route.js.map +2 -2
- package/dist/service.js +46 -1
- package/dist/service.js.map +2 -2
- package/package.json +4 -4
- package/src/__tests__/search-indexer-should-index.test.ts +223 -0
- package/src/__tests__/service.test.ts +64 -0
- package/src/di.ts +1 -0
- package/src/indexer/search-indexer.ts +57 -17
- package/src/modules/search/__tests__/ai-tools.query.test.ts +44 -0
- package/src/modules/search/__tests__/ai-tools.visibility-filter.test.ts +97 -0
- package/src/modules/search/ai-tools.ts +91 -3
- package/src/modules/search/api/search/global/route.ts +1 -0
- package/src/modules/search/api/search/route.ts +1 -0
- package/src/service.ts +48 -1
- package/src/types.ts +2 -0
package/AGENTS.md
CHANGED
|
@@ -12,6 +12,8 @@ When working on search functionality, use this guide. It covers indexing, queryi
|
|
|
12
12
|
6. **MUST** use the `entityId` format `module:entity_name` and ensure it matches the entity registry exactly.
|
|
13
13
|
7. **MUST** use `fieldPolicy.hashOnly` for PII fields (email, phone, tax_id) that need exact-match filtering but not fuzzy search.
|
|
14
14
|
8. **MUST** declare `aclFeatures` on every entity, naming the owning module's view feature(s) — the same gate that entity's own list/read route enforces. `search.global` only authorizes *using* search; `aclFeatures` is what authorizes *reading the records*. Global search, the hybrid `GET /api/search/search` endpoint and the AI tools all fail closed, so an entity without it silently vanishes from results for every non-superadmin.
|
|
15
|
+
9. **MUST** use the optional `shouldIndex(ctx)` hook when only some records of an entity may be searchable (per-record opt-in). `SearchIndexer` evaluates it on every index/reindex path; `false` or a throw deletes the record from all strategies (fail closed), and the query index evaluates the same hook per record before writing `search_tokens` (tokens on `true`, deleted on `false`/throw), so tokens work without fulltext/vector providers and every token writer honors the gate.
|
|
16
|
+
10. **MUST** use the optional `filterResults(ctx)` hook when indexed records need a per-record read check beyond `aclFeatures` (e.g. the record's own open rule). `SearchService.search()` runs it per entity after merging, with `SearchOptions.viewer` (`{ auth, container }`); no viewer or a throw drops all of that entity's results (fail closed), and results can come back shorter than `limit`. Callers that should return such entities MUST pass `viewer` (the `/api/search/search` and global search routes do, and so do the `search_query`, `search.hybrid_search` and `search.get_record_context` AI tools — as the user, or as `api_key:<id>` with no user for API-key callers). Callers with no principal (agent context retrieval, the `search query` CLI) pass none, so such entities stay hidden there.
|
|
15
17
|
|
|
16
18
|
## Ask First
|
|
17
19
|
|
package/dist/di.js
CHANGED
|
@@ -123,6 +123,7 @@ function registerSearchModule(container, options) {
|
|
|
123
123
|
const searchService = new SearchService({
|
|
124
124
|
strategies,
|
|
125
125
|
resolveEntityStrategies: (entityId) => resolveEntityIndexStrategies(entityId, moduleConfigs),
|
|
126
|
+
resolveResultFilter: (entityId) => entityConfigMap.get(entityId)?.filterResults,
|
|
126
127
|
defaultStrategies,
|
|
127
128
|
fallbackStrategy: "tokens",
|
|
128
129
|
mergeConfig: options?.mergeConfig ?? {
|
package/dist/di.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/di.ts"],
|
|
4
|
-
"sourcesContent": ["import { resolveEntityIndexStrategies } from './lib/entity-strategy-policy'\nimport { asValue } from 'awilix'\nimport type { Kysely } from 'kysely'\nimport type { FullTextSearchDriver } from './fulltext/types'\nimport { SearchService } from './service'\nimport { TokenSearchStrategy } from './strategies/token.strategy'\nimport { VectorSearchStrategy, type EmbeddingService } from './strategies/vector.strategy'\nimport { FullTextSearchStrategy } from './strategies/fulltext.strategy'\nimport { createFulltextDriver } from './fulltext/drivers'\nimport { SearchIndexer } from './indexer/search-indexer'\nimport type {\n SearchStrategy,\n ResultMergeConfig,\n SearchModuleConfig,\n SearchFieldPolicy,\n SearchEntityConfig,\n PresenterEnricherFn,\n} from './types'\nimport type { VectorDriver } from './vector/types'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { SearchStrategyId } from '@open-mercato/shared/modules/search'\nimport type { Queue } from '@open-mercato/queue'\nimport type { FulltextIndexJobPayload } from './queue/fulltext-indexing'\nimport type { VectorIndexJobPayload } from './queue/vector-indexing'\nimport type { EncryptionMapEntry } from './lib/field-policy'\nimport type { TenantDataEncryptionService } from '@open-mercato/shared/lib/encryption/tenantDataEncryptionService'\nimport { createPresenterEnricher } from './lib/presenter-enricher'\nimport { createEncryptionMapResolver } from './lib/encryption-map-resolver'\nimport {\n createEncryptedCustomFieldKeysResolver,\n type CustomFieldDefinitionsDatabase,\n type EncryptedCustomFieldKeysResolver,\n} from './lib/encrypted-custom-field-resolver'\nimport { reportSearchError } from './lib/debug'\n\nexport { createEncryptionMapResolver } from './lib/encryption-map-resolver'\nexport {\n createEncryptedCustomFieldKeysResolver,\n type EncryptedCustomFieldKeysResolver,\n} from './lib/encrypted-custom-field-resolver'\n\ntype KyselyEntityManager = {\n getKysely<Database>(): Kysely<Database>\n}\n\nconst FULLTEXT_DRIVER_KEY = '__omSearchFulltextDriver__'\n\ntype SearchModuleGlobals = {\n [FULLTEXT_DRIVER_KEY]?: FullTextSearchDriver\n}\n\nfunction getSearchModuleGlobals(): SearchModuleGlobals {\n return globalThis as unknown as SearchModuleGlobals\n}\n\n/**\n * Check if encrypted fields should be excluded from search indexing.\n * Controlled by SEARCH_EXCLUDE_ENCRYPTED_FIELDS environment variable.\n * Default: false (index all fields including decrypted data)\n */\nfunction shouldExcludeEncryptedFields(): boolean {\n const raw = (process.env.SEARCH_EXCLUDE_ENCRYPTED_FIELDS ?? '').toLowerCase()\n return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on'\n}\n\nfunction createUnavailableEncryptedCustomFieldKeysResolver(): EncryptedCustomFieldKeysResolver {\n return async () => {\n throw new Error('[internal] Custom-field definitions are unavailable; refusing to index potentially encrypted custom fields')\n }\n}\n\nfunction createUnavailableEncryptionMapResolver(): (entityId: EntityId) => Promise<EncryptionMapEntry[]> {\n return async () => {\n throw new Error('[internal] Encryption map lookup is unavailable; refusing to index potentially encrypted fields')\n }\n}\n\n/**\n * Container interface - minimal subset needed for registration.\n */\nexport interface SearchContainer {\n resolve<T = unknown>(name: string): T\n register(registrations: Record<string, unknown>): void\n}\n\n/**\n * Configuration options for search module registration.\n */\nexport type SearchModuleOptions = {\n /** Override default strategies to use */\n defaultStrategies?: SearchStrategyId[]\n /** Override merge configuration */\n mergeConfig?: ResultMergeConfig\n /** Skip token strategy registration */\n skipTokens?: boolean\n /** Skip vector strategy registration */\n skipVector?: boolean\n /** Skip fulltext strategy registration */\n skipFulltext?: boolean\n /** Module configurations (from generated/search.generated.ts) */\n moduleConfigs?: SearchModuleConfig[]\n}\n\n/**\n * Register the search module in the DI container.\n *\n * This creates and registers:\n * - SearchService instance\n * - All configured search strategies\n *\n * @param container - Awilix container\n * @param options - Optional configuration overrides\n */\nexport function registerSearchModule(\n container: SearchContainer,\n options?: SearchModuleOptions,\n): void {\n const moduleConfigs = (options?.moduleConfigs ?? []).map((moduleConfig) => ({\n ...moduleConfig,\n entities: moduleConfig.entities.map((entityConfig) => {\n const buildSource = entityConfig.buildSource\n return buildSource\n ? { ...entityConfig, buildSource: (ctx: Parameters<typeof buildSource>[0]) => buildSource.call(entityConfig, { ...ctx, container }) }\n : entityConfig\n }),\n }))\n const strategies: SearchStrategy[] = []\n\n // Token strategy (always available unless explicitly skipped)\n if (!options?.skipTokens) {\n try {\n const em = container.resolve<any>('em')\n const db = em.getKysely() as Kysely<any>\n strategies.push(new TokenSearchStrategy(db))\n } catch {\n // Kysely not available via em, skipping TokenSearchStrategy\n }\n }\n\n // Vector strategy (requires embedding service and driver)\n // Note: We register even if not currently available - availability is checked at search time\n // via isAvailable(). The embedding config may be loaded later from the database.\n if (!options?.skipVector) {\n try {\n const embeddingService = container.resolve<EmbeddingService>('vectorEmbeddingService')\n const drivers = container.resolve<VectorDriver[]>('vectorDrivers')\n const primaryDriver = drivers?.[0]\n\n if (embeddingService && primaryDriver) {\n strategies.push(new VectorSearchStrategy(embeddingService, primaryDriver))\n }\n } catch {\n // Vector module not available, skipping VectorSearchStrategy\n }\n }\n\n // Build entity config map for field policy resolution\n const entityConfigMap = new Map<EntityId, SearchEntityConfig>()\n for (const moduleConfig of moduleConfigs) {\n for (const entityConfig of moduleConfig.entities) {\n if (entityConfig.enabled !== false) {\n entityConfigMap.set(entityConfig.entityId as EntityId, entityConfig)\n }\n }\n }\n\n // Fulltext strategy (requires driver configuration, e.g., MEILISEARCH_HOST)\n if (!options?.skipFulltext) {\n const excludeEncrypted = shouldExcludeEncryptedFields()\n const singletonCacheEnabled = process.env.SEARCH_DISABLE_SINGLETON_CACHE !== '1'\n const g = getSearchModuleGlobals()\n\n // The fulltext driver is safe to memoize only when SEARCH_EXCLUDE_ENCRYPTED_FIELDS is\n // OFF \u2014 in that case the driver holds no request-scoped Kysely reference. When the flag\n // is ON the encryptionMapResolver captures a per-request db handle and must stay\n // per-request to avoid cross-request data leaks.\n const canMemoize = singletonCacheEnabled && !excludeEncrypted\n\n let fulltextDriver: FullTextSearchDriver | null = canMemoize\n ? (g[FULLTEXT_DRIVER_KEY] ?? null)\n : null\n\n if (!fulltextDriver) {\n let encryptionMapResolver: ((entityId: EntityId) => Promise<EncryptionMapEntry[]>) | undefined\n if (excludeEncrypted) {\n try {\n const em = container.resolve<any>('em')\n const db = em.getKysely() as Kysely<any>\n encryptionMapResolver = createEncryptionMapResolver(db)\n } catch {\n encryptionMapResolver = createUnavailableEncryptionMapResolver()\n }\n }\n\n fulltextDriver = createFulltextDriver({\n fieldPolicyResolver: (entityId: EntityId): SearchFieldPolicy | undefined => {\n const config = entityConfigMap.get(entityId)\n return config?.fieldPolicy\n },\n encryptionMapResolver,\n })\n\n if (canMemoize && fulltextDriver) {\n g[FULLTEXT_DRIVER_KEY] = fulltextDriver\n }\n }\n\n if (fulltextDriver) {\n strategies.push(new FullTextSearchStrategy(fulltextDriver))\n }\n }\n\n // Determine default strategies based on what's available\n const defaultStrategies = options?.defaultStrategies ?? determineDefaultStrategies(strategies)\n\n // Try to resolve queryEngine for reindex support and presenter enrichment\n let queryEngine: QueryEngine | undefined\n try {\n queryEngine = container.resolve<QueryEngine>('queryEngine')\n } catch {\n // QueryEngine not available, reindex will be disabled\n }\n\n // Resolve encryption service for decrypting presenter data\n let encryptionService: TenantDataEncryptionService | null = null\n try {\n encryptionService = container.resolve<TenantDataEncryptionService>('tenantEncryptionService')\n } catch {\n // Encryption service not available, presenters won't be decrypted\n }\n\n // Create presenter enricher for database-based presenter resolution\n let presenterEnricher: PresenterEnricherFn | undefined\n try {\n const em = container.resolve<any>('em')\n const db = em.getKysely() as Kysely<any>\n presenterEnricher = createPresenterEnricher(db, entityConfigMap, queryEngine, encryptionService)\n } catch {\n // Kysely not available, presenter enrichment disabled\n }\n\n // Create search service\n const searchService = new SearchService({\n strategies,\n resolveEntityStrategies: (entityId) => resolveEntityIndexStrategies(entityId, moduleConfigs),\n defaultStrategies,\n fallbackStrategy: 'tokens',\n mergeConfig: options?.mergeConfig ?? {\n duplicateHandling: 'highest_score',\n strategyWeights: {\n fulltext: 1.2,\n vector: 1.0,\n tokens: 0.8,\n },\n },\n presenterEnricher,\n })\n\n // Try to resolve fulltextIndexQueue for queue-based reindexing\n let fulltextQueue: Queue<FulltextIndexJobPayload> | undefined\n try {\n fulltextQueue = container.resolve<Queue<FulltextIndexJobPayload>>('fulltextIndexQueue')\n } catch {\n // Queue not available, queue-based fulltext reindex will be disabled\n }\n\n // Try to resolve vectorIndexQueue for queue-based vector reindexing\n let vectorQueue: Queue<VectorIndexJobPayload> | undefined\n try {\n vectorQueue = container.resolve<Queue<VectorIndexJobPayload>>('vectorIndexQueue')\n } catch {\n // Queue not available, queue-based vector reindex will be disabled\n }\n\n let encryptedCustomFieldKeysResolver: EncryptedCustomFieldKeysResolver\n try {\n const em = container.resolve<KyselyEntityManager>('em')\n encryptedCustomFieldKeysResolver = createEncryptedCustomFieldKeysResolver(\n em.getKysely<CustomFieldDefinitionsDatabase>(),\n )\n } catch (error) {\n reportSearchError('SearchModule', error, 'search.custom_field_definitions_unavailable')\n encryptedCustomFieldKeysResolver = createUnavailableEncryptedCustomFieldKeysResolver()\n }\n\n const searchIndexer = new SearchIndexer(searchService, moduleConfigs, {\n queryEngine,\n fulltextQueue,\n vectorQueue,\n encryptedCustomFieldKeysResolver,\n })\n\n // Register in container\n container.register({\n searchService: asValue(searchService),\n searchStrategies: asValue(strategies),\n searchIndexer: asValue(searchIndexer),\n })\n}\n\n/**\n * Determine default strategy order based on available strategies.\n * Prefers fulltext > vector > tokens.\n */\nfunction determineDefaultStrategies(strategies: SearchStrategy[]): SearchStrategyId[] {\n const available = new Set(strategies.map((s) => s.id))\n const defaults: SearchStrategyId[] = []\n\n if (available.has('fulltext')) defaults.push('fulltext')\n if (available.has('vector')) defaults.push('vector')\n if (available.has('tokens')) defaults.push('tokens')\n\n return defaults.length > 0 ? defaults : ['tokens']\n}\n\n/**\n * Helper to add a custom strategy to an existing SearchService.\n *\n * @param container - DI container\n * @param strategy - Strategy to add\n */\nexport function addSearchStrategy(container: SearchContainer, strategy: SearchStrategy): void {\n const service = container.resolve<SearchService>('searchService')\n service.registerStrategy(strategy)\n\n const strategies = container.resolve<SearchStrategy[]>('searchStrategies')\n strategies.push(strategy)\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oCAAoC;AAC7C,SAAS,eAAe;AAGxB,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B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IACpC,kBAAkB,QAAQ,UAAU;AAAA,IACpC,eAAe,QAAQ,aAAa;AAAA,EACtC,CAAC;AACH;AAMA,SAAS,2BAA2B,YAAkD;AACpF,QAAM,YAAY,IAAI,IAAI,WAAW,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AACrD,QAAM,WAA+B,CAAC;AAEtC,MAAI,UAAU,IAAI,UAAU,EAAG,UAAS,KAAK,UAAU;AACvD,MAAI,UAAU,IAAI,QAAQ,EAAG,UAAS,KAAK,QAAQ;AACnD,MAAI,UAAU,IAAI,QAAQ,EAAG,UAAS,KAAK,QAAQ;AAEnD,SAAO,SAAS,SAAS,IAAI,WAAW,CAAC,QAAQ;AACnD;AAQO,SAAS,kBAAkB,WAA4B,UAAgC;AAC5F,QAAM,UAAU,UAAU,QAAuB,eAAe;AAChE,UAAQ,iBAAiB,QAAQ;AAEjC,QAAM,aAAa,UAAU,QAA0B,kBAAkB;AACzE,aAAW,KAAK,QAAQ;AAC1B;",
|
|
4
|
+
"sourcesContent": ["import { resolveEntityIndexStrategies } from './lib/entity-strategy-policy'\nimport { asValue } from 'awilix'\nimport type { Kysely } from 'kysely'\nimport type { FullTextSearchDriver } from './fulltext/types'\nimport { SearchService } from './service'\nimport { TokenSearchStrategy } from './strategies/token.strategy'\nimport { VectorSearchStrategy, type EmbeddingService } from './strategies/vector.strategy'\nimport { FullTextSearchStrategy } from './strategies/fulltext.strategy'\nimport { createFulltextDriver } from './fulltext/drivers'\nimport { SearchIndexer } from './indexer/search-indexer'\nimport type {\n SearchStrategy,\n ResultMergeConfig,\n SearchModuleConfig,\n SearchFieldPolicy,\n SearchEntityConfig,\n PresenterEnricherFn,\n} from './types'\nimport type { VectorDriver } from './vector/types'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { SearchStrategyId } from '@open-mercato/shared/modules/search'\nimport type { Queue } from '@open-mercato/queue'\nimport type { FulltextIndexJobPayload } from './queue/fulltext-indexing'\nimport type { VectorIndexJobPayload } from './queue/vector-indexing'\nimport type { EncryptionMapEntry } from './lib/field-policy'\nimport type { TenantDataEncryptionService } from '@open-mercato/shared/lib/encryption/tenantDataEncryptionService'\nimport { createPresenterEnricher } from './lib/presenter-enricher'\nimport { createEncryptionMapResolver } from './lib/encryption-map-resolver'\nimport {\n createEncryptedCustomFieldKeysResolver,\n type CustomFieldDefinitionsDatabase,\n type EncryptedCustomFieldKeysResolver,\n} from './lib/encrypted-custom-field-resolver'\nimport { reportSearchError } from './lib/debug'\n\nexport { createEncryptionMapResolver } from './lib/encryption-map-resolver'\nexport {\n createEncryptedCustomFieldKeysResolver,\n type EncryptedCustomFieldKeysResolver,\n} from './lib/encrypted-custom-field-resolver'\n\ntype KyselyEntityManager = {\n getKysely<Database>(): Kysely<Database>\n}\n\nconst FULLTEXT_DRIVER_KEY = '__omSearchFulltextDriver__'\n\ntype SearchModuleGlobals = {\n [FULLTEXT_DRIVER_KEY]?: FullTextSearchDriver\n}\n\nfunction getSearchModuleGlobals(): SearchModuleGlobals {\n return globalThis as unknown as SearchModuleGlobals\n}\n\n/**\n * Check if encrypted fields should be excluded from search indexing.\n * Controlled by SEARCH_EXCLUDE_ENCRYPTED_FIELDS environment variable.\n * Default: false (index all fields including decrypted data)\n */\nfunction shouldExcludeEncryptedFields(): boolean {\n const raw = (process.env.SEARCH_EXCLUDE_ENCRYPTED_FIELDS ?? '').toLowerCase()\n return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on'\n}\n\nfunction createUnavailableEncryptedCustomFieldKeysResolver(): EncryptedCustomFieldKeysResolver {\n return async () => {\n throw new Error('[internal] Custom-field definitions are unavailable; refusing to index potentially encrypted custom fields')\n }\n}\n\nfunction createUnavailableEncryptionMapResolver(): (entityId: EntityId) => Promise<EncryptionMapEntry[]> {\n return async () => {\n throw new Error('[internal] Encryption map lookup is unavailable; refusing to index potentially encrypted fields')\n }\n}\n\n/**\n * Container interface - minimal subset needed for registration.\n */\nexport interface SearchContainer {\n resolve<T = unknown>(name: string): T\n register(registrations: Record<string, unknown>): void\n}\n\n/**\n * Configuration options for search module registration.\n */\nexport type SearchModuleOptions = {\n /** Override default strategies to use */\n defaultStrategies?: SearchStrategyId[]\n /** Override merge configuration */\n mergeConfig?: ResultMergeConfig\n /** Skip token strategy registration */\n skipTokens?: boolean\n /** Skip vector strategy registration */\n skipVector?: boolean\n /** Skip fulltext strategy registration */\n skipFulltext?: boolean\n /** Module configurations (from generated/search.generated.ts) */\n moduleConfigs?: SearchModuleConfig[]\n}\n\n/**\n * Register the search module in the DI container.\n *\n * This creates and registers:\n * - SearchService instance\n * - All configured search strategies\n *\n * @param container - Awilix container\n * @param options - Optional configuration overrides\n */\nexport function registerSearchModule(\n container: SearchContainer,\n options?: SearchModuleOptions,\n): void {\n const moduleConfigs = (options?.moduleConfigs ?? []).map((moduleConfig) => ({\n ...moduleConfig,\n entities: moduleConfig.entities.map((entityConfig) => {\n const buildSource = entityConfig.buildSource\n return buildSource\n ? { ...entityConfig, buildSource: (ctx: Parameters<typeof buildSource>[0]) => buildSource.call(entityConfig, { ...ctx, container }) }\n : entityConfig\n }),\n }))\n const strategies: SearchStrategy[] = []\n\n // Token strategy (always available unless explicitly skipped)\n if (!options?.skipTokens) {\n try {\n const em = container.resolve<any>('em')\n const db = em.getKysely() as Kysely<any>\n strategies.push(new TokenSearchStrategy(db))\n } catch {\n // Kysely not available via em, skipping TokenSearchStrategy\n }\n }\n\n // Vector strategy (requires embedding service and driver)\n // Note: We register even if not currently available - availability is checked at search time\n // via isAvailable(). The embedding config may be loaded later from the database.\n if (!options?.skipVector) {\n try {\n const embeddingService = container.resolve<EmbeddingService>('vectorEmbeddingService')\n const drivers = container.resolve<VectorDriver[]>('vectorDrivers')\n const primaryDriver = drivers?.[0]\n\n if (embeddingService && primaryDriver) {\n strategies.push(new VectorSearchStrategy(embeddingService, primaryDriver))\n }\n } catch {\n // Vector module not available, skipping VectorSearchStrategy\n }\n }\n\n // Build entity config map for field policy resolution\n const entityConfigMap = new Map<EntityId, SearchEntityConfig>()\n for (const moduleConfig of moduleConfigs) {\n for (const entityConfig of moduleConfig.entities) {\n if (entityConfig.enabled !== false) {\n entityConfigMap.set(entityConfig.entityId as EntityId, entityConfig)\n }\n }\n }\n\n // Fulltext strategy (requires driver configuration, e.g., MEILISEARCH_HOST)\n if (!options?.skipFulltext) {\n const excludeEncrypted = shouldExcludeEncryptedFields()\n const singletonCacheEnabled = process.env.SEARCH_DISABLE_SINGLETON_CACHE !== '1'\n const g = getSearchModuleGlobals()\n\n // The fulltext driver is safe to memoize only when SEARCH_EXCLUDE_ENCRYPTED_FIELDS is\n // OFF \u2014 in that case the driver holds no request-scoped Kysely reference. When the flag\n // is ON the encryptionMapResolver captures a per-request db handle and must stay\n // per-request to avoid cross-request data leaks.\n const canMemoize = singletonCacheEnabled && !excludeEncrypted\n\n let fulltextDriver: FullTextSearchDriver | null = canMemoize\n ? (g[FULLTEXT_DRIVER_KEY] ?? null)\n : null\n\n if (!fulltextDriver) {\n let encryptionMapResolver: ((entityId: EntityId) => Promise<EncryptionMapEntry[]>) | undefined\n if (excludeEncrypted) {\n try {\n const em = container.resolve<any>('em')\n const db = em.getKysely() as Kysely<any>\n encryptionMapResolver = createEncryptionMapResolver(db)\n } catch {\n encryptionMapResolver = createUnavailableEncryptionMapResolver()\n }\n }\n\n fulltextDriver = createFulltextDriver({\n fieldPolicyResolver: (entityId: EntityId): SearchFieldPolicy | undefined => {\n const config = entityConfigMap.get(entityId)\n return config?.fieldPolicy\n },\n encryptionMapResolver,\n })\n\n if (canMemoize && fulltextDriver) {\n g[FULLTEXT_DRIVER_KEY] = fulltextDriver\n }\n }\n\n if (fulltextDriver) {\n strategies.push(new FullTextSearchStrategy(fulltextDriver))\n }\n }\n\n // Determine default strategies based on what's available\n const defaultStrategies = options?.defaultStrategies ?? determineDefaultStrategies(strategies)\n\n // Try to resolve queryEngine for reindex support and presenter enrichment\n let queryEngine: QueryEngine | undefined\n try {\n queryEngine = container.resolve<QueryEngine>('queryEngine')\n } catch {\n // QueryEngine not available, reindex will be disabled\n }\n\n // Resolve encryption service for decrypting presenter data\n let encryptionService: TenantDataEncryptionService | null = null\n try {\n encryptionService = container.resolve<TenantDataEncryptionService>('tenantEncryptionService')\n } catch {\n // Encryption service not available, presenters won't be decrypted\n }\n\n // Create presenter enricher for database-based presenter resolution\n let presenterEnricher: PresenterEnricherFn | undefined\n try {\n const em = container.resolve<any>('em')\n const db = em.getKysely() as Kysely<any>\n presenterEnricher = createPresenterEnricher(db, entityConfigMap, queryEngine, encryptionService)\n } catch {\n // Kysely not available, presenter enrichment disabled\n }\n\n // Create search service\n const searchService = new SearchService({\n strategies,\n resolveEntityStrategies: (entityId) => resolveEntityIndexStrategies(entityId, moduleConfigs),\n resolveResultFilter: (entityId) => entityConfigMap.get(entityId as EntityId)?.filterResults,\n defaultStrategies,\n fallbackStrategy: 'tokens',\n mergeConfig: options?.mergeConfig ?? {\n duplicateHandling: 'highest_score',\n strategyWeights: {\n fulltext: 1.2,\n vector: 1.0,\n tokens: 0.8,\n },\n },\n presenterEnricher,\n })\n\n // Try to resolve fulltextIndexQueue for queue-based reindexing\n let fulltextQueue: Queue<FulltextIndexJobPayload> | undefined\n try {\n fulltextQueue = container.resolve<Queue<FulltextIndexJobPayload>>('fulltextIndexQueue')\n } catch {\n // Queue not available, queue-based fulltext reindex will be disabled\n }\n\n // Try to resolve vectorIndexQueue for queue-based vector reindexing\n let vectorQueue: Queue<VectorIndexJobPayload> | undefined\n try {\n vectorQueue = container.resolve<Queue<VectorIndexJobPayload>>('vectorIndexQueue')\n } catch {\n // Queue not available, queue-based vector reindex will be disabled\n }\n\n let encryptedCustomFieldKeysResolver: EncryptedCustomFieldKeysResolver\n try {\n const em = container.resolve<KyselyEntityManager>('em')\n encryptedCustomFieldKeysResolver = createEncryptedCustomFieldKeysResolver(\n em.getKysely<CustomFieldDefinitionsDatabase>(),\n )\n } catch (error) {\n reportSearchError('SearchModule', error, 'search.custom_field_definitions_unavailable')\n encryptedCustomFieldKeysResolver = createUnavailableEncryptedCustomFieldKeysResolver()\n }\n\n const searchIndexer = new SearchIndexer(searchService, moduleConfigs, {\n queryEngine,\n fulltextQueue,\n vectorQueue,\n encryptedCustomFieldKeysResolver,\n })\n\n // Register in container\n container.register({\n searchService: asValue(searchService),\n searchStrategies: asValue(strategies),\n searchIndexer: asValue(searchIndexer),\n })\n}\n\n/**\n * Determine default strategy order based on available strategies.\n * Prefers fulltext > vector > tokens.\n */\nfunction determineDefaultStrategies(strategies: SearchStrategy[]): SearchStrategyId[] {\n const available = new Set(strategies.map((s) => s.id))\n const defaults: SearchStrategyId[] = []\n\n if (available.has('fulltext')) defaults.push('fulltext')\n if (available.has('vector')) defaults.push('vector')\n if (available.has('tokens')) defaults.push('tokens')\n\n return defaults.length > 0 ? defaults : ['tokens']\n}\n\n/**\n * Helper to add a custom strategy to an existing SearchService.\n *\n * @param container - DI container\n * @param strategy - Strategy to add\n */\nexport function addSearchStrategy(container: SearchContainer, strategy: SearchStrategy): void {\n const service = container.resolve<SearchService>('searchService')\n service.registerStrategy(strategy)\n\n const strategies = container.resolve<SearchStrategy[]>('searchStrategies')\n strategies.push(strategy)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oCAAoC;AAC7C,SAAS,eAAe;AAGxB,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,4BAAmD;AAC5D,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAkB9B,SAAS,+BAA+B;AACxC,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,OAGK;AACP,SAAS,yBAAyB;AAElC,SAAS,+BAAAA,oCAAmC;AAC5C;AAAA,EACE,0CAAAC;AAAA,OAEK;AAMP,MAAM,sBAAsB;AAM5B,SAAS,yBAA8C;AACrD,SAAO;AACT;AAOA,SAAS,+BAAwC;AAC/C,QAAM,OAAO,QAAQ,IAAI,mCAAmC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AS,KAAK,QAAQ;AACnD,MAAI,UAAU,IAAI,QAAQ,EAAG,UAAS,KAAK,QAAQ;AAEnD,SAAO,SAAS,SAAS,IAAI,WAAW,CAAC,QAAQ;AACnD;AAQO,SAAS,kBAAkB,WAA4B,UAAgC;AAC5F,QAAM,UAAU,UAAU,QAAuB,eAAe;AAChE,UAAQ,iBAAiB,QAAQ;AAEjC,QAAM,aAAa,UAAU,QAA0B,kBAAkB;AACzE,aAAW,KAAK,QAAQ;AAC1B;",
|
|
6
6
|
"names": ["createEncryptionMapResolver", "createEncryptedCustomFieldKeysResolver"]
|
|
7
7
|
}
|
|
@@ -160,22 +160,40 @@ class SearchIndexer {
|
|
|
160
160
|
const config = this.entityConfigMap.get(entityId);
|
|
161
161
|
return config?.enabled !== false;
|
|
162
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Evaluate the entity's `shouldIndex` gate. Entities without the hook always pass;
|
|
165
|
+
* a hook that throws counts as a rejection (fail closed).
|
|
166
|
+
*/
|
|
167
|
+
async passesIndexGate(config, buildContext, entityId, recordId) {
|
|
168
|
+
if (!config.shouldIndex) return true;
|
|
169
|
+
try {
|
|
170
|
+
return await config.shouldIndex(buildContext) === true;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
searchDebugWarn("SearchIndexer", "shouldIndex failed, excluding record", {
|
|
173
|
+
entityId,
|
|
174
|
+
recordId,
|
|
175
|
+
error: error instanceof Error ? error.message : error
|
|
176
|
+
});
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
163
180
|
/**
|
|
164
181
|
* Index a record in the search service.
|
|
182
|
+
* Records rejected by the entity's `shouldIndex` gate are removed from every strategy instead.
|
|
165
183
|
*/
|
|
166
184
|
async indexRecord(params) {
|
|
167
|
-
await this.
|
|
185
|
+
await this.indexRecordThroughGate(params, this.createCustomFieldExclusionLookup());
|
|
168
186
|
}
|
|
169
|
-
async
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
187
|
+
async indexRecordThroughGate(params, exclusions) {
|
|
188
|
+
const built = await this.buildIndexableRecord(params, exclusions);
|
|
189
|
+
if (built === "unconfigured" || built === "excluded") return built;
|
|
190
|
+
await this.searchService.index(built);
|
|
191
|
+
return "indexed";
|
|
174
192
|
}
|
|
175
193
|
async buildIndexableRecord(params, exclusions = this.createCustomFieldExclusionLookup()) {
|
|
176
194
|
const config = this.entityConfigMap.get(params.entityId);
|
|
177
195
|
if (!config || config.enabled === false) {
|
|
178
|
-
return
|
|
196
|
+
return "unconfigured";
|
|
179
197
|
}
|
|
180
198
|
const exclusion = await exclusions(params.entityId, params.tenantId);
|
|
181
199
|
const buildContext = {
|
|
@@ -185,6 +203,10 @@ class SearchIndexer {
|
|
|
185
203
|
tenantId: params.tenantId,
|
|
186
204
|
queryEngine: this.createBuildQueryEngine(exclusions)
|
|
187
205
|
};
|
|
206
|
+
if (!await this.passesIndexGate(config, buildContext, params.entityId, params.recordId)) {
|
|
207
|
+
await this.searchService.delete(params.entityId, params.recordId, params.tenantId);
|
|
208
|
+
return "excluded";
|
|
209
|
+
}
|
|
188
210
|
let text = config.buildSource ? [] : void 0;
|
|
189
211
|
let presenter;
|
|
190
212
|
let url;
|
|
@@ -292,7 +314,7 @@ class SearchIndexer {
|
|
|
292
314
|
customFields[key.slice(3)] = value;
|
|
293
315
|
}
|
|
294
316
|
}
|
|
295
|
-
await this.
|
|
317
|
+
const outcome = await this.indexRecordThroughGate({
|
|
296
318
|
entityId: params.entityId,
|
|
297
319
|
recordId: params.recordId,
|
|
298
320
|
tenantId: params.tenantId,
|
|
@@ -300,6 +322,9 @@ class SearchIndexer {
|
|
|
300
322
|
record,
|
|
301
323
|
customFields
|
|
302
324
|
}, exclusions);
|
|
325
|
+
if (outcome === "excluded") {
|
|
326
|
+
return { action: "skipped", reason: "excluded by shouldIndex" };
|
|
327
|
+
}
|
|
303
328
|
return { action: "indexed" };
|
|
304
329
|
} catch (error) {
|
|
305
330
|
searchError("SearchIndexer", "Failed to load record for indexing", {
|
|
@@ -353,7 +378,7 @@ class SearchIndexer {
|
|
|
353
378
|
skipped++;
|
|
354
379
|
continue;
|
|
355
380
|
}
|
|
356
|
-
const { records: built, dropped } = await this.buildIndexableRecords(
|
|
381
|
+
const { records: built, dropped, excluded } = await this.buildIndexableRecords(
|
|
357
382
|
entityId,
|
|
358
383
|
tenantId,
|
|
359
384
|
organizationId ?? null,
|
|
@@ -361,7 +386,7 @@ class SearchIndexer {
|
|
|
361
386
|
config,
|
|
362
387
|
exclusions
|
|
363
388
|
);
|
|
364
|
-
skipped += dropped;
|
|
389
|
+
skipped += dropped + excluded;
|
|
365
390
|
allRecords.push(...built);
|
|
366
391
|
} catch (error) {
|
|
367
392
|
skipped++;
|
|
@@ -513,9 +538,9 @@ class SearchIndexer {
|
|
|
513
538
|
const indexableRecords = [];
|
|
514
539
|
const exclusions = this.createCustomFieldExclusionLookup();
|
|
515
540
|
for (const param of params) {
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
518
|
-
indexableRecords.push(
|
|
541
|
+
const built = await this.buildIndexableRecord(param, exclusions);
|
|
542
|
+
if (built !== "unconfigured" && built !== "excluded") {
|
|
543
|
+
indexableRecords.push(built);
|
|
519
544
|
}
|
|
520
545
|
}
|
|
521
546
|
if (indexableRecords.length > 0) {
|
|
@@ -940,6 +965,7 @@ class SearchIndexer {
|
|
|
940
965
|
async buildIndexableRecords(entityId, tenantId, organizationId, items, config, exclusions = this.createCustomFieldExclusionLookup()) {
|
|
941
966
|
const records = [];
|
|
942
967
|
let dropped = 0;
|
|
968
|
+
let excluded = 0;
|
|
943
969
|
const exclusion = await exclusions(entityId, tenantId);
|
|
944
970
|
const plaintextExcludedCustomFields = toPlaintextExcludedCustomFields(exclusion);
|
|
945
971
|
const buildQueryEngine = this.createBuildQueryEngine(exclusions);
|
|
@@ -971,6 +997,11 @@ class SearchIndexer {
|
|
|
971
997
|
tenantId,
|
|
972
998
|
queryEngine: buildQueryEngine
|
|
973
999
|
};
|
|
1000
|
+
if (!await this.passesIndexGate(config, buildContext, entityId, recordId)) {
|
|
1001
|
+
await this.searchService.delete(entityId, recordId, tenantId);
|
|
1002
|
+
excluded++;
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
974
1005
|
let text = config.buildSource ? [] : void 0;
|
|
975
1006
|
let presenter;
|
|
976
1007
|
let url;
|
|
@@ -1033,9 +1064,10 @@ class SearchIndexer {
|
|
|
1033
1064
|
entityId,
|
|
1034
1065
|
inputCount: items.length,
|
|
1035
1066
|
outputCount: records.length,
|
|
1036
|
-
dropped
|
|
1067
|
+
dropped,
|
|
1068
|
+
excluded
|
|
1037
1069
|
});
|
|
1038
|
-
return { records, dropped };
|
|
1070
|
+
return { records, dropped, excluded };
|
|
1039
1071
|
}
|
|
1040
1072
|
}
|
|
1041
1073
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/indexer/search-indexer.ts"],
|
|
4
|
-
"sourcesContent": ["import { isEntityIndexStrategyAllowed } from '../lib/entity-strategy-policy'\nimport type { SearchService } from '../service'\nimport type {\n SearchModuleConfig,\n SearchEntityConfig,\n SearchBuildContext,\n IndexableRecord,\n SearchResultPresenter,\n SearchResultLink,\n} from '../types'\nimport type { FullTextSearchStrategy } from '../strategies/fulltext.strategy'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { Queue } from '@open-mercato/queue'\nimport type { FulltextIndexJobPayload } from '../queue/fulltext-indexing'\nimport type { VectorIndexJobPayload, VectorBatchRecord } from '../queue/vector-indexing'\nimport { reportSearchError, searchDebug, searchDebugWarn, searchError, searchWarn } from '../lib/debug'\nimport type { EncryptedCustomFieldKeysResolver } from '../lib/encrypted-custom-field-resolver'\nimport { normalizeDefinitionKey } from '@open-mercato/shared/lib/crud/custom-field-definition-index'\n\n/**\n * Maximum number of pages to process during reindex to prevent infinite loops.\n * At 50 records per page, this allows up to 500,000 records per entity.\n */\nconst MAX_PAGES = 10000\n\n/**\n * Custom fields kept out of the build context: the normalized keys of encrypted\n * definitions, every custom field when they could not be resolved, or none.\n */\ntype CustomFieldExclusion = Set<string> | 'all' | null\n\ntype CustomFieldExclusionLookup = (entityId: EntityId, tenantId: string | null) => Promise<CustomFieldExclusion>\n\nfunction toPlaintextExcludedCustomFields(\n exclusion: CustomFieldExclusion,\n): IndexableRecord['plaintextExcludedCustomFields'] {\n if (!exclusion) return undefined\n return exclusion === 'all' ? 'all' : Array.from(exclusion)\n}\n\nfunction mergeCustomFieldExclusions(exclusions: CustomFieldExclusion[]): CustomFieldExclusion {\n if (exclusions.includes('all')) return 'all'\n const sets = exclusions.filter((exclusion): exclusion is Set<string> => exclusion instanceof Set)\n if (!sets.length) return null\n if (sets.length === 1) return sets[0]\n return new Set(sets.flatMap((set) => Array.from(set)))\n}\n\nfunction isExcludedCustomField(key: string, exclusion: CustomFieldExclusion): boolean {\n if (!exclusion) return false\n if (exclusion === 'all') return true\n return exclusion.has(normalizeDefinitionKey(key))\n}\n\nfunction withoutExcludedRecordCustomFields(\n record: Record<string, unknown>,\n exclusion: CustomFieldExclusion,\n): Record<string, unknown> {\n if (!exclusion) return record\n const filtered: Record<string, unknown> = {}\n let removed = false\n for (const [key, value] of Object.entries(record)) {\n const isCustomField = key.startsWith('cf:') || key.startsWith('cf_')\n if (isCustomField && isExcludedCustomField(key.slice(3), exclusion)) {\n removed = true\n continue\n }\n filtered[key] = value\n }\n return removed ? filtered : record\n}\n\n/**\n * Build callbacks may enrich the record they receive (for example with a hydrated parent);\n * those changes reach the indexed fields as they did before the record was filtered.\n */\nfunction applyBuildRecordChanges(\n buildRecord: Record<string, unknown>,\n record: Record<string, unknown>,\n exclusion: CustomFieldExclusion,\n): void {\n if (buildRecord === record) return\n for (const [key, value] of Object.entries(buildRecord)) {\n if (record[key] !== value) record[key] = value\n }\n for (const key of Object.keys(record)) {\n if (key in buildRecord) continue\n const isCustomField = key.startsWith('cf:') || key.startsWith('cf_')\n if (isCustomField && isExcludedCustomField(key.slice(3), exclusion)) continue\n delete record[key]\n }\n}\n\nfunction withoutExcludedCustomFields(\n customFields: Record<string, unknown>,\n exclusion: CustomFieldExclusion,\n): Record<string, unknown> {\n if (!exclusion) return customFields\n const filtered: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(customFields)) {\n const isPrefixed = key.startsWith('cf:') || key.startsWith('cf_')\n if (isExcludedCustomField(key, exclusion)) continue\n if (isPrefixed && isExcludedCustomField(key.slice(3), exclusion)) continue\n filtered[key] = value\n }\n return filtered\n}\n\n/**\n * Scoped reindexes clear only the reindexed entity's (or organization's) documents. A driver\n * that can do neither `purge` nor `listDocumentIds` would keep deleted records, and recreating\n * the whole tenant index instead would drop every other entity and organization, so such a\n * reindex fails up front.\n */\nfunction canScopedPurge(fulltext: FullTextSearchStrategy): boolean {\n return typeof fulltext.canPurge !== 'function' || fulltext.canPurge()\n}\n\nfunction scopedPurgeUnsupportedError(fulltext: FullTextSearchStrategy): string {\n return `Fulltext driver \"${fulltext.driverId}\" cannot clear documents per entity (implement purge or listDocumentIds); reindex aborted to avoid keeping stale documents`\n}\n\n/**\n * Parameters for indexing a record.\n */\nexport type IndexRecordParams = {\n entityId: EntityId\n recordId: string\n tenantId: string\n organizationId?: string | null\n record: Record<string, unknown>\n customFields?: Record<string, unknown>\n}\n\ntype IndexRecordByIdParams = {\n entityId: EntityId\n recordId: string\n tenantId: string\n organizationId?: string | null\n}\n\n/**\n * Parameters for indexing a batch of records by id in a single bulk write.\n */\nexport type IndexRecordsByIdParams = {\n items: Array<{ entityId: EntityId; recordId: string }>\n tenantId: string\n organizationId?: string | null\n}\n\n/**\n * Parameters for deleting a record from the search index.\n */\nexport type DeleteRecordParams = {\n entityId: EntityId\n recordId: string\n tenantId: string\n}\n\n/**\n * Parameters for purging all records of an entity type.\n */\nexport type PurgeEntityParams = {\n entityId: EntityId\n tenantId: string\n organizationId?: string | null\n}\n\n/**\n * Parameters for reindexing an entity to fulltext search.\n */\nexport type ReindexEntityParams = {\n entityId: EntityId\n tenantId: string\n organizationId?: string | null\n /** Whether to clear this entity's documents (scoped to `organizationId` when set) first (default: true) */\n recreateIndex?: boolean\n /** Callback for progress tracking */\n onProgress?: (progress: ReindexProgress) => void\n /** Whether to use queue for batch processing (default: false) */\n useQueue?: boolean\n}\n\n/**\n * Parameters for reindexing all entities to fulltext search.\n */\nexport type ReindexAllParams = {\n tenantId: string\n organizationId?: string | null\n /** Whether to clear indexed documents first (default: true): the whole tenant index, or only `organizationId`'s documents when set */\n recreateIndex?: boolean\n /** Callback for progress tracking */\n onProgress?: (progress: ReindexProgress) => void\n /** Whether to use queue for batch processing (default: false) */\n useQueue?: boolean\n}\n\n/**\n * Progress information during reindex.\n */\nexport type ReindexProgress = {\n entityId: EntityId\n phase: 'starting' | 'fetching' | 'indexing' | 'complete'\n processed: number\n total?: number\n}\n\n/**\n * Result of a reindex operation.\n */\nexport type ReindexResult = {\n success: boolean\n entitiesProcessed: number\n recordsIndexed: number\n /** Number of records dropped due to missing id or other validation failures */\n recordsDropped?: number\n /** Number of jobs enqueued (when useQueue is true) */\n jobsEnqueued?: number\n errors: Array<{ entityId: EntityId; error: string }>\n}\n\n/**\n * Optional dependencies for SearchIndexer.\n */\nexport type SearchIndexerOptions = {\n queryEngine?: QueryEngine\n /** Queue for fulltext batch indexing */\n fulltextQueue?: Queue<FulltextIndexJobPayload>\n /** Queue for vector batch indexing */\n vectorQueue?: Queue<VectorIndexJobPayload>\n /**\n * Resolves the custom fields declared `encrypted` for an entity, so their values never reach\n * buildSource, formatResult, resolveUrl or resolveLinks and stay out of the plain text a\n * strategy stores or embeds. Without it, every custom field is left out of those callbacks.\n * `IndexableRecord.fields` keeps them for hash-only tokens.\n */\n encryptedCustomFieldKeysResolver?: EncryptedCustomFieldKeysResolver\n}\n\n/**\n * SearchIndexer orchestrates indexing operations by resolving entity configs\n * and building IndexableRecords for the SearchService.\n */\nexport class SearchIndexer {\n private readonly entityConfigMap: Map<EntityId, SearchEntityConfig>\n private readonly queryEngine?: QueryEngine\n private readonly fulltextQueue?: Queue<FulltextIndexJobPayload>\n private readonly vectorQueue?: Queue<VectorIndexJobPayload>\n private readonly encryptedCustomFieldKeysResolver?: EncryptedCustomFieldKeysResolver\n\n constructor(\n private readonly searchService: SearchService,\n private readonly moduleConfigs: SearchModuleConfig[],\n options?: SearchIndexerOptions,\n ) {\n this.entityConfigMap = new Map()\n this.queryEngine = options?.queryEngine\n this.fulltextQueue = options?.fulltextQueue\n this.vectorQueue = options?.vectorQueue\n this.encryptedCustomFieldKeysResolver = options?.encryptedCustomFieldKeysResolver\n if (!this.encryptedCustomFieldKeysResolver) {\n searchWarn('SearchIndexer', 'No encrypted custom-field resolver; excluding every custom field from build contexts')\n reportSearchError(\n 'SearchIndexer',\n new Error('[internal] SearchIndexer has no encryptedCustomFieldKeysResolver; excluding every custom field from build contexts'),\n 'search.encrypted_custom_fields_resolver_missing',\n )\n }\n for (const moduleConfig of moduleConfigs) {\n for (const entityConfig of moduleConfig.entities) {\n if (entityConfig.enabled !== false) {\n this.entityConfigMap.set(entityConfig.entityId as EntityId, entityConfig)\n }\n }\n }\n }\n\n /**\n * Returns a lookup of the custom fields to keep out of build contexts, memoized per entity and\n * tenant for one indexing call or reindex run. A missing resolver or a failed resolution excludes\n * every custom field. Failed resolutions stay cached for the current operation and are retried by\n * the fresh lookup created for the next top-level indexing call.\n */\n private createCustomFieldExclusionLookup(): CustomFieldExclusionLookup {\n const resolver = this.encryptedCustomFieldKeysResolver\n const cache = new Map<string, Promise<CustomFieldExclusion>>()\n return (entityId, tenantId) => {\n if (!resolver) return Promise.resolve('all')\n const cacheKey = `${entityId}\\u0000${tenantId ?? ''}`\n let pending = cache.get(cacheKey)\n if (!pending) {\n pending = Promise.resolve().then(() => resolver(entityId, tenantId)).catch((error): CustomFieldExclusion => {\n const resolutionError = error instanceof Error\n ? error\n : new Error('[internal] Encrypted custom-field resolver rejected with a non-Error value')\n searchWarn('SearchIndexer', 'Encrypted custom fields could not be resolved; excluding every custom field', {\n entityId,\n error: resolutionError.message,\n })\n reportSearchError('SearchIndexer', resolutionError, 'search.encrypted_custom_fields_unresolved', { entityId })\n return 'all'\n })\n cache.set(cacheKey, pending)\n }\n return pending\n }\n }\n\n /**\n * Returns a wrapped QueryEngine that forces skipAutoReindex: true on every query.\n * Used to prevent feedback loops when search indexing callbacks (buildSource, formatResult)\n * call queryEngine.query() to hydrate related entities. Encrypted custom fields are removed\n * from the hydrated records, as from the indexed record itself, including those joined in\n * from `customFieldSources`. A query without a tenant is checked against every tenant's definitions.\n */\n private createBuildQueryEngine(exclusions: CustomFieldExclusionLookup): QueryEngine | undefined {\n if (!this.queryEngine) return undefined\n const queryEngine = this.queryEngine\n const wrapped: QueryEngine = {\n query: async (entity, opts) => {\n const result = await queryEngine.query(entity, { ...opts, skipAutoReindex: true })\n const sourceEntityIds = [entity, ...(opts?.customFieldSources ?? []).map((source) => source.entityId)]\n const tenantId = opts?.tenantId ?? null\n const exclusion = mergeCustomFieldExclusions(\n await Promise.all(sourceEntityIds.map((sourceEntityId) => exclusions(sourceEntityId as EntityId, tenantId))),\n )\n if (!exclusion || !Array.isArray(result?.items)) return result\n return {\n ...result,\n items: result.items.map((item: Record<string, unknown>) => withoutExcludedRecordCustomFields(item, exclusion)),\n }\n },\n }\n return wrapped\n }\n\n /**\n * Get the entity config for a given entity ID.\n */\n getEntityConfig(entityId: EntityId): SearchEntityConfig | undefined {\n return this.entityConfigMap.get(entityId)\n }\n\n /**\n * Get all configured entity configs.\n */\n getAllEntityConfigs(): SearchEntityConfig[] {\n return Array.from(this.entityConfigMap.values())\n }\n\n /**\n * Check if an entity is configured for search indexing.\n */\n isEntityEnabled(entityId: EntityId): boolean {\n const config = this.entityConfigMap.get(entityId)\n return config?.enabled !== false\n }\n\n /**\n * Index a record in the search service.\n */\n async indexRecord(params: IndexRecordParams): Promise<void> {\n await this.indexRecordWithExclusions(params, this.createCustomFieldExclusionLookup())\n }\n\n private async indexRecordWithExclusions(\n params: IndexRecordParams,\n exclusions: CustomFieldExclusionLookup,\n ): Promise<void> {\n const indexableRecord = await this.buildIndexableRecord(params, exclusions)\n if (indexableRecord) {\n await this.searchService.index(indexableRecord)\n }\n }\n\n private async buildIndexableRecord(\n params: IndexRecordParams,\n exclusions: CustomFieldExclusionLookup = this.createCustomFieldExclusionLookup(),\n ): Promise<IndexableRecord | null> {\n const config = this.entityConfigMap.get(params.entityId)\n if (!config || config.enabled === false) {\n return null\n }\n\n const exclusion = await exclusions(params.entityId, params.tenantId)\n const buildContext: SearchBuildContext = {\n record: withoutExcludedRecordCustomFields(params.record, exclusion),\n customFields: withoutExcludedCustomFields(params.customFields ?? {}, exclusion),\n organizationId: params.organizationId,\n tenantId: params.tenantId,\n queryEngine: this.createBuildQueryEngine(exclusions),\n }\n\n // Try buildSource first (provides text, presenter, links, checksumSource)\n let text: string | string[] | undefined = config.buildSource ? [] : undefined\n let presenter: SearchResultPresenter | undefined\n let url: string | undefined\n let links: SearchResultLink[] | undefined\n let checksumSource: unknown | undefined\n\n if (config.buildSource) {\n try {\n const source = await config.buildSource(buildContext)\n if (source) {\n text = source.text ?? []\n if (source.presenter) presenter = source.presenter\n if (source.links) links = source.links\n if (source.checksumSource !== undefined) checksumSource = source.checksumSource\n }\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'buildSource failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Fall back to formatResult if no presenter from buildSource\n if (!presenter && config.formatResult) {\n try {\n const result = await config.formatResult(buildContext)\n if (result) presenter = result\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'formatResult failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Resolve URL if not already set\n if (!url && config.resolveUrl) {\n try {\n const result = await config.resolveUrl(buildContext)\n if (result) url = result\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'resolveUrl failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Resolve links if not already set\n if (!links && config.resolveLinks) {\n try {\n const result = await config.resolveLinks(buildContext)\n if (result) links = result\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'resolveLinks failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n applyBuildRecordChanges(buildContext.record, params.record, exclusion)\n\n return {\n entityId: params.entityId,\n recordId: params.recordId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n fields: params.record,\n plaintextExcludedCustomFields: toPlaintextExcludedCustomFields(exclusion),\n presenter,\n url,\n links,\n text,\n checksumSource,\n }\n }\n\n /**\n * Index a record by ID (loads the record from database first).\n * Used by workers that only have record identifiers.\n */\n async indexRecordById(params: {\n entityId: EntityId\n recordId: string\n tenantId: string\n organizationId?: string | null\n }): Promise<{ action: 'indexed' | 'skipped'; reason?: string }> {\n return this.indexRecordByIdWithExclusions(params, this.createCustomFieldExclusionLookup())\n }\n\n private async indexRecordByIdWithExclusions(\n params: IndexRecordByIdParams,\n exclusions: CustomFieldExclusionLookup,\n ): Promise<{ action: 'indexed' | 'skipped'; reason?: string }> {\n if (!this.queryEngine) {\n return { action: 'skipped', reason: 'queryEngine not available' }\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config || config.enabled === false) {\n return { action: 'skipped', reason: 'entity not configured' }\n }\n\n // Load record from database\n try {\n const result = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n filters: { id: params.recordId },\n includeCustomFields: true,\n page: { page: 1, pageSize: 1 },\n skipAutoReindex: true,\n })\n\n const record = result.items[0] as Record<string, unknown> | undefined\n if (!record) {\n return { action: 'skipped', reason: 'record not found' }\n }\n\n // Extract custom fields\n const customFields: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(record)) {\n if (key.startsWith('cf:') || key.startsWith('cf_')) {\n customFields[key.slice(3)] = value\n }\n }\n\n await this.indexRecordWithExclusions({\n entityId: params.entityId,\n recordId: params.recordId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n record,\n customFields,\n }, exclusions)\n\n return { action: 'indexed' }\n } catch (error) {\n searchError('SearchIndexer', 'Failed to load record for indexing', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n throw error\n }\n }\n\n /**\n * Index a batch of records by id in a single bulk write.\n * Unlike calling indexRecordById() in a loop, this loads each record fresh\n * (same as indexRecordById) but flushes the whole batch through a single\n * searchService.bulkIndex() call. Strategies that implement bulkIndex then\n * collapse the batch into one write; strategies without it still write per\n * record, at the bounded concurrency SearchService applies.\n */\n async indexRecordsById(params: IndexRecordsByIdParams): Promise<{ indexed: number; skipped: number }> {\n const { items, tenantId, organizationId } = params\n if (!this.queryEngine || items.length === 0) {\n return { indexed: 0, skipped: items.length }\n }\n\n const recordIdsByEntity = new Map<EntityId, string[]>()\n for (const item of items) {\n const list = recordIdsByEntity.get(item.entityId) ?? []\n list.push(item.recordId)\n recordIdsByEntity.set(item.entityId, list)\n }\n const exclusions = this.createCustomFieldExclusionLookup()\n\n const allRecords: IndexableRecord[] = []\n let skipped = 0\n\n for (const [entityId, recordIds] of recordIdsByEntity) {\n const config = this.entityConfigMap.get(entityId)\n if (!config || config.enabled === false) {\n skipped += recordIds.length\n continue\n }\n\n for (const recordId of recordIds) {\n try {\n const result = await this.queryEngine.query(entityId, {\n tenantId,\n organizationId: organizationId ?? undefined,\n filters: { id: recordId },\n includeCustomFields: true,\n page: { page: 1, pageSize: 1 },\n skipAutoReindex: true,\n })\n\n const record = result.items[0] as Record<string, unknown> | undefined\n if (!record) {\n skipped++\n continue\n }\n\n const { records: built, dropped } = await this.buildIndexableRecords(\n entityId,\n tenantId,\n organizationId ?? null,\n [record],\n config,\n exclusions,\n )\n skipped += dropped\n allRecords.push(...built)\n } catch (error) {\n skipped++\n searchError('SearchIndexer', 'Failed to load record for batch indexing', {\n entityId,\n recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n }\n\n if (allRecords.length > 0) {\n await this.searchService.bulkIndex(allRecords)\n }\n\n return { indexed: allRecords.length, skipped }\n }\n\n /**\n * Delete a record from the search index.\n */\n async deleteRecord(params: DeleteRecordParams): Promise<void> {\n await this.searchService.delete(params.entityId, params.recordId, params.tenantId)\n }\n\n /**\n * Purge all records of an entity type from the search index.\n */\n async purgeEntity(params: PurgeEntityParams): Promise<void> {\n await this.searchService.purge(params.entityId, params.tenantId, params.organizationId)\n }\n\n /**\n * Reindex an entity via all configured strategies (including vector).\n * This is the general reindex method that works with all search strategies.\n */\n async reindexEntity(params: {\n entityId: EntityId\n tenantId: string\n organizationId?: string | null\n purgeFirst?: boolean\n }): Promise<ReindexResult> {\n if (!this.queryEngine) {\n return {\n success: false,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n errors: [{ entityId: params.entityId, error: 'Query engine not available' }],\n }\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config || config.enabled === false) {\n return {\n success: false,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n errors: [{ entityId: params.entityId, error: 'Entity not configured for search' }],\n }\n }\n\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 1,\n recordsIndexed: 0,\n errors: [],\n }\n\n // Optionally purge first\n if (params.purgeFirst) {\n try {\n await this.searchService.purge(params.entityId, params.tenantId, params.organizationId)\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to purge entity before reindex', {\n entityId: params.entityId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Paginate through all records\n const exclusions = this.createCustomFieldExclusionLookup()\n let page = 1\n const pageSize = 200\n let hasMore = true\n\n while (hasMore && page <= MAX_PAGES) {\n try {\n const queryResult = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n includeCustomFields: true,\n page: { page, pageSize },\n skipAutoReindex: true,\n })\n\n const items = queryResult.items as Record<string, unknown>[]\n if (items.length === 0) {\n hasMore = false\n break\n }\n\n // Build and index records\n const { records } = await this.buildIndexableRecords(\n params.entityId,\n params.tenantId,\n params.organizationId ?? null,\n items,\n config,\n exclusions,\n )\n\n // Bulk index records via SearchService (sends to all strategies)\n if (records.length > 0) {\n try {\n await this.searchService.bulkIndex(records)\n result.recordsIndexed += records.length\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to bulk index records', {\n entityId: params.entityId,\n recordCount: records.length,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n page++\n hasMore = items.length === pageSize\n } catch (error) {\n result.success = false\n result.errors.push({\n entityId: params.entityId,\n error: error instanceof Error ? error.message : String(error),\n })\n break\n }\n }\n\n return result\n }\n\n /**\n * Reindex all enabled entities via all configured strategies.\n */\n async reindexAll(params: {\n tenantId: string\n organizationId?: string | null\n purgeFirst?: boolean\n }): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n errors: [],\n }\n\n const enabledEntities = this.listEnabledEntities()\n\n for (const entityId of enabledEntities) {\n const entityResult = await this.reindexEntity({\n entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n purgeFirst: params.purgeFirst,\n })\n\n result.entitiesProcessed++\n result.recordsIndexed += entityResult.recordsIndexed\n result.errors.push(...entityResult.errors)\n\n if (!entityResult.success) {\n result.success = false\n }\n }\n\n return result\n }\n\n /**\n * Bulk index multiple records.\n */\n async bulkIndexRecords(params: IndexRecordParams[]): Promise<void> {\n const indexableRecords: IndexableRecord[] = []\n const exclusions = this.createCustomFieldExclusionLookup()\n\n for (const param of params) {\n const indexableRecord = await this.buildIndexableRecord(param, exclusions)\n if (indexableRecord) {\n indexableRecords.push(indexableRecord)\n }\n }\n\n if (indexableRecords.length > 0) {\n try {\n await this.searchService.bulkIndex(indexableRecords)\n } catch (error) {\n throw new Error(\n `Failed to bulk index ${indexableRecords.length} records: ${\n error instanceof Error ? error.message : error\n }`\n )\n }\n }\n }\n\n /**\n * List all enabled entity IDs from the module configurations.\n */\n listEnabledEntities(): EntityId[] {\n return Array.from(this.entityConfigMap.keys())\n }\n\n /**\n * Get the fulltext strategy from the search service.\n */\n private getFulltextStrategy(): FullTextSearchStrategy | undefined {\n const strategy = this.searchService.getStrategy('fulltext')\n if (!strategy) return undefined\n return strategy as FullTextSearchStrategy\n }\n\n /**\n * Reindex a single entity type to fulltext search.\n * This fetches all records from the database and re-indexes them to fulltext only.\n *\n * When `useQueue` is true, batches are enqueued for background processing by workers.\n * When `useQueue` is false (default), batches are indexed directly (blocking).\n */\n async reindexEntityToFulltext(params: ReindexEntityParams): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n if (!isEntityIndexStrategyAllowed(params.entityId, 'fulltext', this.moduleConfigs)) return result\n\n const fulltext = this.getFulltextStrategy()\n if (!fulltext) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Fulltext strategy not available' })\n return result\n }\n\n // If useQueue is requested but no queue is available, return error\n if (params.useQueue && !this.fulltextQueue) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Fulltext queue not configured for queue-based reindexing' })\n return result\n }\n\n if (!this.queryEngine) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'QueryEngine not available for reindexing' })\n return result\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Entity not configured for search' })\n return result\n }\n\n try {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'starting',\n processed: 0,\n })\n\n if (params.recreateIndex !== false) {\n if (!canScopedPurge(fulltext)) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: scopedPurgeUnsupportedError(fulltext) })\n return result\n }\n await fulltext.purge(params.entityId, params.tenantId, params.organizationId ?? null)\n }\n\n // Fetch and index records with pagination\n const exclusions = this.createCustomFieldExclusionLookup()\n const pageSize = 200\n let page = 1\n let totalProcessed = 0\n let jobsEnqueued = 0\n\n for (;;) {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'fetching',\n processed: totalProcessed,\n })\n\n try {\n const queryResult = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n page: { page, pageSize },\n skipAutoReindex: true,\n })\n\n if (!queryResult.items.length) {\n break\n }\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'indexing',\n processed: totalProcessed,\n total: queryResult.total,\n })\n\n // Build IndexableRecords for this batch\n const { records: indexableRecords, dropped } = await this.buildIndexableRecords(\n params.entityId,\n params.tenantId,\n params.organizationId ?? null,\n queryResult.items,\n config,\n exclusions,\n )\n result.recordsDropped = (result.recordsDropped ?? 0) + dropped\n\n // Index to fulltext - either via queue or directly\n if (indexableRecords.length > 0) {\n if (params.useQueue && this.fulltextQueue) {\n // Enqueue batch for background processing - only pass minimal references\n // Worker will load fresh data from entity_indexes table\n await this.fulltextQueue.enqueue({\n jobType: 'batch-index',\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n records: indexableRecords.map((r) => ({ entityId: r.entityId, recordId: r.recordId })),\n })\n jobsEnqueued += 1\n totalProcessed += indexableRecords.length\n } else {\n // Direct indexing (blocking)\n try {\n await fulltext.bulkIndex(indexableRecords)\n totalProcessed += indexableRecords.length\n } catch (indexError) {\n // Log error but continue with remaining batches\n const errorMsg = indexError instanceof Error ? indexError.message : String(indexError)\n result.errors.push({\n entityId: params.entityId,\n error: `Batch ${page} failed: ${errorMsg}`,\n })\n }\n }\n }\n\n if (queryResult.items.length < pageSize) {\n break\n }\n page += 1\n\n // Safety check to prevent infinite loops\n if (page > MAX_PAGES) {\n break\n }\n } catch (queryError) {\n const errorMsg = queryError instanceof Error ? queryError.message : String(queryError)\n result.errors.push({\n entityId: params.entityId,\n error: `Query failed: ${errorMsg}`,\n })\n break\n }\n }\n\n result.entitiesProcessed = 1\n result.recordsIndexed = totalProcessed\n result.jobsEnqueued = jobsEnqueued\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'complete',\n processed: totalProcessed,\n total: totalProcessed,\n })\n } catch (error) {\n result.success = false\n result.errors.push({\n entityId: params.entityId,\n error: error instanceof Error ? error.message : String(error),\n })\n }\n\n return result\n }\n\n /**\n * Reindex all enabled entities to fulltext search.\n *\n * When `useQueue` is true, batches are enqueued for background processing by workers.\n * When `useQueue` is false (default), batches are indexed directly (blocking).\n */\n async reindexAllToFulltext(params: ReindexAllParams): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n const fulltext = this.getFulltextStrategy()\n if (!fulltext) {\n result.success = false\n result.errors.push({ entityId: 'all' as EntityId, error: 'Fulltext strategy not available' })\n return result\n }\n\n const clearIndex = params.recreateIndex !== false\n const organizationScoped = typeof params.organizationId === 'string' && params.organizationId.trim().length > 0\n if (clearIndex && !organizationScoped) {\n await fulltext.recreateIndex(params.tenantId)\n }\n if (clearIndex && organizationScoped && !canScopedPurge(fulltext)) {\n result.success = false\n result.errors.push({ entityId: 'all' as EntityId, error: scopedPurgeUnsupportedError(fulltext) })\n return result\n }\n\n const entities = this.listEnabledEntities()\n\n for (const entityId of entities) {\n const entityResult = await this.reindexEntityToFulltext({\n entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n recreateIndex: clearIndex && organizationScoped,\n onProgress: params.onProgress,\n useQueue: params.useQueue,\n })\n\n result.entitiesProcessed += entityResult.entitiesProcessed\n result.recordsIndexed += entityResult.recordsIndexed\n result.recordsDropped = (result.recordsDropped ?? 0) + (entityResult.recordsDropped ?? 0)\n result.jobsEnqueued = (result.jobsEnqueued ?? 0) + (entityResult.jobsEnqueued ?? 0)\n result.errors.push(...entityResult.errors)\n\n if (!entityResult.success) {\n result.success = false\n }\n }\n\n return result\n }\n\n /**\n * Reindex a single entity type to vector search.\n * This fetches all records from the database and enqueues them for vector indexing.\n *\n * When `useQueue` is true (default), record IDs are enqueued for background processing by workers.\n * When `useQueue` is false, records are indexed directly (blocking).\n */\n async reindexEntityToVector(params: ReindexEntityParams & { purgeFirst?: boolean }): Promise<ReindexResult> {\n searchDebug('SearchIndexer', 'reindexEntityToVector called', {\n entityId: params.entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n useQueue: params.useQueue,\n purgeFirst: params.purgeFirst,\n })\n\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n if (!isEntityIndexStrategyAllowed(params.entityId, 'vector', this.moduleConfigs)) return result\n\n // If useQueue is requested but no queue is available, return error\n if (params.useQueue !== false && !this.vectorQueue) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Vector queue not configured for queue-based reindexing' })\n return result\n }\n\n if (!this.queryEngine) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'QueryEngine not available for reindexing' })\n return result\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Entity not configured for search' })\n return result\n }\n\n try {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'starting',\n processed: 0,\n })\n\n // Optionally purge vector index first\n if (params.purgeFirst) {\n try {\n await this.searchService.purge(params.entityId, params.tenantId, params.organizationId)\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to purge entity before vector reindex', {\n entityId: params.entityId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Fetch and enqueue records with pagination\n const pageSize = 200\n let page = 1\n let totalProcessed = 0\n let jobsEnqueued = 0\n const exclusions = this.createCustomFieldExclusionLookup()\n\n for (;;) {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'fetching',\n processed: totalProcessed,\n })\n\n const queryResult = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n page: { page, pageSize },\n skipAutoReindex: true,\n })\n\n if (!queryResult.items.length) break\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'indexing',\n processed: totalProcessed,\n total: queryResult.total,\n })\n\n // Build batch of record references\n const batchRecords: VectorBatchRecord[] = []\n for (const item of queryResult.items) {\n const recordId = String((item as Record<string, unknown>).id ?? '')\n if (!recordId) {\n result.recordsDropped = (result.recordsDropped ?? 0) + 1\n continue\n }\n batchRecords.push({\n entityId: params.entityId,\n recordId,\n })\n }\n\n // Enqueue batch for background processing or index directly\n if (batchRecords.length > 0) {\n if (params.useQueue !== false && this.vectorQueue) {\n await this.vectorQueue.enqueue({\n jobType: 'batch-index',\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? null,\n records: batchRecords,\n })\n jobsEnqueued += 1\n totalProcessed += batchRecords.length\n searchDebug('SearchIndexer', 'Enqueued batch for vector indexing', {\n entityId: params.entityId,\n batchSize: batchRecords.length,\n jobsEnqueued,\n totalProcessed,\n })\n } else {\n // Direct indexing (blocking) - index each record via SearchService\n for (const { entityId, recordId } of batchRecords) {\n try {\n await this.indexRecordByIdWithExclusions({\n entityId: entityId as EntityId,\n recordId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n }, exclusions)\n totalProcessed++\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to index record to vector', {\n entityId,\n recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n }\n }\n\n if (queryResult.items.length < pageSize) break\n page += 1\n\n // Safety check to prevent infinite loops\n if (page > MAX_PAGES) {\n searchDebugWarn('SearchIndexer', 'Reached MAX_PAGES limit, stopping pagination', {\n entityId: params.entityId,\n maxPages: MAX_PAGES,\n totalProcessed,\n })\n break\n }\n }\n\n result.entitiesProcessed = 1\n result.recordsIndexed = totalProcessed\n result.jobsEnqueued = jobsEnqueued\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'complete',\n processed: totalProcessed,\n total: totalProcessed,\n })\n } catch (error) {\n result.success = false\n result.errors.push({\n entityId: params.entityId,\n error: error instanceof Error ? error.message : String(error),\n })\n }\n\n return result\n }\n\n /**\n * Reindex all enabled entities to vector search.\n *\n * When `useQueue` is true (default), batches are enqueued for background processing by workers.\n * When `useQueue` is false, batches are indexed directly (blocking).\n */\n async reindexAllToVector(params: ReindexAllParams & { purgeFirst?: boolean }): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n const entities = this.listEnabledEntities()\n for (const entityId of entities) {\n const entityResult = await this.reindexEntityToVector({\n entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n onProgress: params.onProgress,\n useQueue: params.useQueue,\n purgeFirst: params.purgeFirst,\n })\n\n result.entitiesProcessed += entityResult.entitiesProcessed\n result.recordsIndexed += entityResult.recordsIndexed\n result.recordsDropped = (result.recordsDropped ?? 0) + (entityResult.recordsDropped ?? 0)\n result.jobsEnqueued = (result.jobsEnqueued ?? 0) + (entityResult.jobsEnqueued ?? 0)\n result.errors.push(...entityResult.errors)\n\n if (!entityResult.success) {\n result.success = false\n }\n }\n\n return result\n }\n\n /**\n * Build IndexableRecords from raw query results.\n * Returns records and count of dropped items (missing id or other validation failures).\n */\n private async buildIndexableRecords(\n entityId: EntityId,\n tenantId: string,\n organizationId: string | null,\n items: Record<string, unknown>[],\n config: SearchEntityConfig,\n exclusions: CustomFieldExclusionLookup = this.createCustomFieldExclusionLookup(),\n ): Promise<{ records: IndexableRecord[]; dropped: number }> {\n const records: IndexableRecord[] = []\n let dropped = 0\n const exclusion = await exclusions(entityId, tenantId)\n const plaintextExcludedCustomFields = toPlaintextExcludedCustomFields(exclusion)\n const buildQueryEngine = this.createBuildQueryEngine(exclusions)\n\n if (items.length > 0) {\n searchDebug('SearchIndexer', 'Sample item structure', {\n entityId,\n sampleKeys: Object.keys(items[0]),\n hasId: 'id' in items[0],\n })\n }\n\n for (const item of items) {\n const recordId = String(item.id ?? '')\n if (!recordId) {\n searchDebugWarn('SearchIndexer', 'Skipping item without id', { entityId, itemKeys: Object.keys(item) })\n dropped++\n continue\n }\n\n // Extract custom fields from record\n const customFields: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(item)) {\n if (key.startsWith('cf:') || key.startsWith('cf_')) {\n const cfKey = key.slice(3) // Remove 'cf:' or 'cf_' prefix (both are 3 chars)\n customFields[cfKey] = value\n }\n }\n\n const buildContext: SearchBuildContext = {\n record: withoutExcludedRecordCustomFields(item, exclusion),\n customFields: withoutExcludedCustomFields(customFields, exclusion),\n organizationId,\n tenantId,\n queryEngine: buildQueryEngine,\n }\n\n // Try buildSource first (provides text, presenter, links, checksumSource)\n let text: string | string[] | undefined = config.buildSource ? [] : undefined\n let presenter: SearchResultPresenter | undefined\n let url: string | undefined\n let links: SearchResultLink[] | undefined\n let checksumSource: unknown | undefined\n\n if (config.buildSource) {\n try {\n const source = await config.buildSource(buildContext)\n if (source) {\n text = source.text ?? []\n if (source.presenter) presenter = source.presenter\n if (source.links) links = source.links\n if (source.checksumSource !== undefined) checksumSource = source.checksumSource\n }\n } catch (err) {\n searchDebugWarn('SearchIndexer', 'buildSource failed', {\n entityId,\n recordId,\n error: err instanceof Error ? err.message : err,\n })\n }\n }\n\n // Fall back to formatResult if no presenter from buildSource\n if (!presenter && config.formatResult) {\n try {\n const result = await config.formatResult(buildContext)\n if (result) presenter = result\n } catch {\n // Skip presenter on error\n }\n }\n\n // Resolve URL if not already set\n if (!url && config.resolveUrl) {\n try {\n const result = await config.resolveUrl(buildContext)\n if (result) url = result\n } catch {\n // Skip URL on error\n }\n }\n\n // Resolve links if not already set\n if (!links && config.resolveLinks) {\n try {\n const result = await config.resolveLinks(buildContext)\n if (result) links = result\n } catch {\n // Skip links on error\n }\n }\n\n applyBuildRecordChanges(buildContext.record, item, exclusion)\n\n records.push({\n entityId,\n recordId,\n tenantId,\n organizationId,\n fields: item,\n plaintextExcludedCustomFields,\n presenter,\n url,\n links,\n text,\n checksumSource,\n })\n }\n\n searchDebug('SearchIndexer', 'Finished building records', {\n entityId,\n inputCount: items.length,\n outputCount: records.length,\n dropped,\n })\n\n return { records, dropped }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oCAAoC;AAgB7C,SAAS,mBAAmB,aAAa,iBAAiB,aAAa,kBAAkB;AAEzF,SAAS,8BAA8B;AAMvC,MAAM,YAAY;AAUlB,SAAS,gCACP,WACkD;AAClD,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,cAAc,QAAQ,QAAQ,MAAM,KAAK,SAAS;AAC3D;AAEA,SAAS,2BAA2B,YAA0D;AAC5F,MAAI,WAAW,SAAS,KAAK,EAAG,QAAO;AACvC,QAAM,OAAO,WAAW,OAAO,CAAC,cAAwC,qBAAqB,GAAG;AAChG,MAAI,CAAC,KAAK,OAAQ,QAAO;AACzB,MAAI,KAAK,WAAW,EAAG,QAAO,KAAK,CAAC;AACpC,SAAO,IAAI,IAAI,KAAK,QAAQ,CAAC,QAAQ,MAAM,KAAK,GAAG,CAAC,CAAC;AACvD;AAEA,SAAS,sBAAsB,KAAa,WAA0C;AACpF,MAAI,CAAC,UAAW,QAAO;AACvB,MAAI,cAAc,MAAO,QAAO;AAChC,SAAO,UAAU,IAAI,uBAAuB,GAAG,CAAC;AAClD;AAEA,SAAS,kCACP,QACA,WACyB;AACzB,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,WAAoC,CAAC;AAC3C,MAAI,UAAU;AACd,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,UAAM,gBAAgB,IAAI,WAAW,KAAK,KAAK,IAAI,WAAW,KAAK;AACnE,QAAI,iBAAiB,sBAAsB,IAAI,MAAM,CAAC,GAAG,SAAS,GAAG;AACnE,gBAAU;AACV;AAAA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AQ,KAAK;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,gBAAY,iBAAiB,6BAA6B;AAAA,MACxD;AAAA,MACA,YAAY,MAAM;AAAA,MAClB,aAAa,QAAQ;AAAA,MACrB;AAAA,IACF,CAAC;AAED,WAAO,EAAE,SAAS,QAAQ;AAAA,EAC5B;AACF;",
|
|
4
|
+
"sourcesContent": ["import { isEntityIndexStrategyAllowed } from '../lib/entity-strategy-policy'\nimport type { SearchService } from '../service'\nimport type {\n SearchModuleConfig,\n SearchEntityConfig,\n SearchBuildContext,\n IndexableRecord,\n SearchResultPresenter,\n SearchResultLink,\n} from '../types'\nimport type { FullTextSearchStrategy } from '../strategies/fulltext.strategy'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { Queue } from '@open-mercato/queue'\nimport type { FulltextIndexJobPayload } from '../queue/fulltext-indexing'\nimport type { VectorIndexJobPayload, VectorBatchRecord } from '../queue/vector-indexing'\nimport { reportSearchError, searchDebug, searchDebugWarn, searchError, searchWarn } from '../lib/debug'\nimport type { EncryptedCustomFieldKeysResolver } from '../lib/encrypted-custom-field-resolver'\nimport { normalizeDefinitionKey } from '@open-mercato/shared/lib/crud/custom-field-definition-index'\n\n/**\n * Maximum number of pages to process during reindex to prevent infinite loops.\n * At 50 records per page, this allows up to 500,000 records per entity.\n */\nconst MAX_PAGES = 10000\n\n/**\n * Custom fields kept out of the build context: the normalized keys of encrypted\n * definitions, every custom field when they could not be resolved, or none.\n */\ntype CustomFieldExclusion = Set<string> | 'all' | null\n\ntype CustomFieldExclusionLookup = (entityId: EntityId, tenantId: string | null) => Promise<CustomFieldExclusion>\n\nfunction toPlaintextExcludedCustomFields(\n exclusion: CustomFieldExclusion,\n): IndexableRecord['plaintextExcludedCustomFields'] {\n if (!exclusion) return undefined\n return exclusion === 'all' ? 'all' : Array.from(exclusion)\n}\n\nfunction mergeCustomFieldExclusions(exclusions: CustomFieldExclusion[]): CustomFieldExclusion {\n if (exclusions.includes('all')) return 'all'\n const sets = exclusions.filter((exclusion): exclusion is Set<string> => exclusion instanceof Set)\n if (!sets.length) return null\n if (sets.length === 1) return sets[0]\n return new Set(sets.flatMap((set) => Array.from(set)))\n}\n\nfunction isExcludedCustomField(key: string, exclusion: CustomFieldExclusion): boolean {\n if (!exclusion) return false\n if (exclusion === 'all') return true\n return exclusion.has(normalizeDefinitionKey(key))\n}\n\nfunction withoutExcludedRecordCustomFields(\n record: Record<string, unknown>,\n exclusion: CustomFieldExclusion,\n): Record<string, unknown> {\n if (!exclusion) return record\n const filtered: Record<string, unknown> = {}\n let removed = false\n for (const [key, value] of Object.entries(record)) {\n const isCustomField = key.startsWith('cf:') || key.startsWith('cf_')\n if (isCustomField && isExcludedCustomField(key.slice(3), exclusion)) {\n removed = true\n continue\n }\n filtered[key] = value\n }\n return removed ? filtered : record\n}\n\n/**\n * Build callbacks may enrich the record they receive (for example with a hydrated parent);\n * those changes reach the indexed fields as they did before the record was filtered.\n */\nfunction applyBuildRecordChanges(\n buildRecord: Record<string, unknown>,\n record: Record<string, unknown>,\n exclusion: CustomFieldExclusion,\n): void {\n if (buildRecord === record) return\n for (const [key, value] of Object.entries(buildRecord)) {\n if (record[key] !== value) record[key] = value\n }\n for (const key of Object.keys(record)) {\n if (key in buildRecord) continue\n const isCustomField = key.startsWith('cf:') || key.startsWith('cf_')\n if (isCustomField && isExcludedCustomField(key.slice(3), exclusion)) continue\n delete record[key]\n }\n}\n\nfunction withoutExcludedCustomFields(\n customFields: Record<string, unknown>,\n exclusion: CustomFieldExclusion,\n): Record<string, unknown> {\n if (!exclusion) return customFields\n const filtered: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(customFields)) {\n const isPrefixed = key.startsWith('cf:') || key.startsWith('cf_')\n if (isExcludedCustomField(key, exclusion)) continue\n if (isPrefixed && isExcludedCustomField(key.slice(3), exclusion)) continue\n filtered[key] = value\n }\n return filtered\n}\n\n/**\n * Scoped reindexes clear only the reindexed entity's (or organization's) documents. A driver\n * that can do neither `purge` nor `listDocumentIds` would keep deleted records, and recreating\n * the whole tenant index instead would drop every other entity and organization, so such a\n * reindex fails up front.\n */\nfunction canScopedPurge(fulltext: FullTextSearchStrategy): boolean {\n return typeof fulltext.canPurge !== 'function' || fulltext.canPurge()\n}\n\nfunction scopedPurgeUnsupportedError(fulltext: FullTextSearchStrategy): string {\n return `Fulltext driver \"${fulltext.driverId}\" cannot clear documents per entity (implement purge or listDocumentIds); reindex aborted to avoid keeping stale documents`\n}\n\n/**\n * Parameters for indexing a record.\n */\nexport type IndexRecordParams = {\n entityId: EntityId\n recordId: string\n tenantId: string\n organizationId?: string | null\n record: Record<string, unknown>\n customFields?: Record<string, unknown>\n}\n\ntype IndexRecordByIdParams = {\n entityId: EntityId\n recordId: string\n tenantId: string\n organizationId?: string | null\n}\n\n/**\n * Parameters for indexing a batch of records by id in a single bulk write.\n */\nexport type IndexRecordsByIdParams = {\n items: Array<{ entityId: EntityId; recordId: string }>\n tenantId: string\n organizationId?: string | null\n}\n\n/**\n * Parameters for deleting a record from the search index.\n */\nexport type DeleteRecordParams = {\n entityId: EntityId\n recordId: string\n tenantId: string\n}\n\n/**\n * Parameters for purging all records of an entity type.\n */\nexport type PurgeEntityParams = {\n entityId: EntityId\n tenantId: string\n organizationId?: string | null\n}\n\n/**\n * Parameters for reindexing an entity to fulltext search.\n */\nexport type ReindexEntityParams = {\n entityId: EntityId\n tenantId: string\n organizationId?: string | null\n /** Whether to clear this entity's documents (scoped to `organizationId` when set) first (default: true) */\n recreateIndex?: boolean\n /** Callback for progress tracking */\n onProgress?: (progress: ReindexProgress) => void\n /** Whether to use queue for batch processing (default: false) */\n useQueue?: boolean\n}\n\n/**\n * Parameters for reindexing all entities to fulltext search.\n */\nexport type ReindexAllParams = {\n tenantId: string\n organizationId?: string | null\n /** Whether to clear indexed documents first (default: true): the whole tenant index, or only `organizationId`'s documents when set */\n recreateIndex?: boolean\n /** Callback for progress tracking */\n onProgress?: (progress: ReindexProgress) => void\n /** Whether to use queue for batch processing (default: false) */\n useQueue?: boolean\n}\n\n/**\n * Progress information during reindex.\n */\nexport type ReindexProgress = {\n entityId: EntityId\n phase: 'starting' | 'fetching' | 'indexing' | 'complete'\n processed: number\n total?: number\n}\n\n/**\n * Result of a reindex operation.\n */\nexport type ReindexResult = {\n success: boolean\n entitiesProcessed: number\n recordsIndexed: number\n /** Number of records dropped due to missing id or other validation failures */\n recordsDropped?: number\n /** Number of jobs enqueued (when useQueue is true) */\n jobsEnqueued?: number\n errors: Array<{ entityId: EntityId; error: string }>\n}\n\n/**\n * Optional dependencies for SearchIndexer.\n */\nexport type SearchIndexerOptions = {\n queryEngine?: QueryEngine\n /** Queue for fulltext batch indexing */\n fulltextQueue?: Queue<FulltextIndexJobPayload>\n /** Queue for vector batch indexing */\n vectorQueue?: Queue<VectorIndexJobPayload>\n /**\n * Resolves the custom fields declared `encrypted` for an entity, so their values never reach\n * buildSource, formatResult, resolveUrl or resolveLinks and stay out of the plain text a\n * strategy stores or embeds. Without it, every custom field is left out of those callbacks.\n * `IndexableRecord.fields` keeps them for hash-only tokens.\n */\n encryptedCustomFieldKeysResolver?: EncryptedCustomFieldKeysResolver\n}\n\n/**\n * SearchIndexer orchestrates indexing operations by resolving entity configs\n * and building IndexableRecords for the SearchService.\n */\nexport class SearchIndexer {\n private readonly entityConfigMap: Map<EntityId, SearchEntityConfig>\n private readonly queryEngine?: QueryEngine\n private readonly fulltextQueue?: Queue<FulltextIndexJobPayload>\n private readonly vectorQueue?: Queue<VectorIndexJobPayload>\n private readonly encryptedCustomFieldKeysResolver?: EncryptedCustomFieldKeysResolver\n\n constructor(\n private readonly searchService: SearchService,\n private readonly moduleConfigs: SearchModuleConfig[],\n options?: SearchIndexerOptions,\n ) {\n this.entityConfigMap = new Map()\n this.queryEngine = options?.queryEngine\n this.fulltextQueue = options?.fulltextQueue\n this.vectorQueue = options?.vectorQueue\n this.encryptedCustomFieldKeysResolver = options?.encryptedCustomFieldKeysResolver\n if (!this.encryptedCustomFieldKeysResolver) {\n searchWarn('SearchIndexer', 'No encrypted custom-field resolver; excluding every custom field from build contexts')\n reportSearchError(\n 'SearchIndexer',\n new Error('[internal] SearchIndexer has no encryptedCustomFieldKeysResolver; excluding every custom field from build contexts'),\n 'search.encrypted_custom_fields_resolver_missing',\n )\n }\n for (const moduleConfig of moduleConfigs) {\n for (const entityConfig of moduleConfig.entities) {\n if (entityConfig.enabled !== false) {\n this.entityConfigMap.set(entityConfig.entityId as EntityId, entityConfig)\n }\n }\n }\n }\n\n /**\n * Returns a lookup of the custom fields to keep out of build contexts, memoized per entity and\n * tenant for one indexing call or reindex run. A missing resolver or a failed resolution excludes\n * every custom field. Failed resolutions stay cached for the current operation and are retried by\n * the fresh lookup created for the next top-level indexing call.\n */\n private createCustomFieldExclusionLookup(): CustomFieldExclusionLookup {\n const resolver = this.encryptedCustomFieldKeysResolver\n const cache = new Map<string, Promise<CustomFieldExclusion>>()\n return (entityId, tenantId) => {\n if (!resolver) return Promise.resolve('all')\n const cacheKey = `${entityId}\\u0000${tenantId ?? ''}`\n let pending = cache.get(cacheKey)\n if (!pending) {\n pending = Promise.resolve().then(() => resolver(entityId, tenantId)).catch((error): CustomFieldExclusion => {\n const resolutionError = error instanceof Error\n ? error\n : new Error('[internal] Encrypted custom-field resolver rejected with a non-Error value')\n searchWarn('SearchIndexer', 'Encrypted custom fields could not be resolved; excluding every custom field', {\n entityId,\n error: resolutionError.message,\n })\n reportSearchError('SearchIndexer', resolutionError, 'search.encrypted_custom_fields_unresolved', { entityId })\n return 'all'\n })\n cache.set(cacheKey, pending)\n }\n return pending\n }\n }\n\n /**\n * Returns a wrapped QueryEngine that forces skipAutoReindex: true on every query.\n * Used to prevent feedback loops when search indexing callbacks (buildSource, formatResult)\n * call queryEngine.query() to hydrate related entities. Encrypted custom fields are removed\n * from the hydrated records, as from the indexed record itself, including those joined in\n * from `customFieldSources`. A query without a tenant is checked against every tenant's definitions.\n */\n private createBuildQueryEngine(exclusions: CustomFieldExclusionLookup): QueryEngine | undefined {\n if (!this.queryEngine) return undefined\n const queryEngine = this.queryEngine\n const wrapped: QueryEngine = {\n query: async (entity, opts) => {\n const result = await queryEngine.query(entity, { ...opts, skipAutoReindex: true })\n const sourceEntityIds = [entity, ...(opts?.customFieldSources ?? []).map((source) => source.entityId)]\n const tenantId = opts?.tenantId ?? null\n const exclusion = mergeCustomFieldExclusions(\n await Promise.all(sourceEntityIds.map((sourceEntityId) => exclusions(sourceEntityId as EntityId, tenantId))),\n )\n if (!exclusion || !Array.isArray(result?.items)) return result\n return {\n ...result,\n items: result.items.map((item: Record<string, unknown>) => withoutExcludedRecordCustomFields(item, exclusion)),\n }\n },\n }\n return wrapped\n }\n\n /**\n * Get the entity config for a given entity ID.\n */\n getEntityConfig(entityId: EntityId): SearchEntityConfig | undefined {\n return this.entityConfigMap.get(entityId)\n }\n\n /**\n * Get all configured entity configs.\n */\n getAllEntityConfigs(): SearchEntityConfig[] {\n return Array.from(this.entityConfigMap.values())\n }\n\n /**\n * Check if an entity is configured for search indexing.\n */\n isEntityEnabled(entityId: EntityId): boolean {\n const config = this.entityConfigMap.get(entityId)\n return config?.enabled !== false\n }\n\n /**\n * Evaluate the entity's `shouldIndex` gate. Entities without the hook always pass;\n * a hook that throws counts as a rejection (fail closed).\n */\n private async passesIndexGate(\n config: SearchEntityConfig,\n buildContext: SearchBuildContext,\n entityId: EntityId,\n recordId: string,\n ): Promise<boolean> {\n if (!config.shouldIndex) return true\n try {\n return (await config.shouldIndex(buildContext)) === true\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'shouldIndex failed, excluding record', {\n entityId,\n recordId,\n error: error instanceof Error ? error.message : error,\n })\n return false\n }\n }\n\n /**\n * Index a record in the search service.\n * Records rejected by the entity's `shouldIndex` gate are removed from every strategy instead.\n */\n async indexRecord(params: IndexRecordParams): Promise<void> {\n await this.indexRecordThroughGate(params, this.createCustomFieldExclusionLookup())\n }\n\n private async indexRecordThroughGate(\n params: IndexRecordParams,\n exclusions: CustomFieldExclusionLookup,\n ): Promise<'indexed' | 'excluded' | 'unconfigured'> {\n const built = await this.buildIndexableRecord(params, exclusions)\n if (built === 'unconfigured' || built === 'excluded') return built\n await this.searchService.index(built)\n return 'indexed'\n }\n\n private async buildIndexableRecord(\n params: IndexRecordParams,\n exclusions: CustomFieldExclusionLookup = this.createCustomFieldExclusionLookup(),\n ): Promise<IndexableRecord | 'unconfigured' | 'excluded'> {\n const config = this.entityConfigMap.get(params.entityId)\n if (!config || config.enabled === false) {\n return 'unconfigured'\n }\n\n const exclusion = await exclusions(params.entityId, params.tenantId)\n const buildContext: SearchBuildContext = {\n record: withoutExcludedRecordCustomFields(params.record, exclusion),\n customFields: withoutExcludedCustomFields(params.customFields ?? {}, exclusion),\n organizationId: params.organizationId,\n tenantId: params.tenantId,\n queryEngine: this.createBuildQueryEngine(exclusions),\n }\n\n if (!(await this.passesIndexGate(config, buildContext, params.entityId, params.recordId))) {\n await this.searchService.delete(params.entityId, params.recordId, params.tenantId)\n return 'excluded'\n }\n\n // Try buildSource first (provides text, presenter, links, checksumSource)\n let text: string | string[] | undefined = config.buildSource ? [] : undefined\n let presenter: SearchResultPresenter | undefined\n let url: string | undefined\n let links: SearchResultLink[] | undefined\n let checksumSource: unknown | undefined\n\n if (config.buildSource) {\n try {\n const source = await config.buildSource(buildContext)\n if (source) {\n text = source.text ?? []\n if (source.presenter) presenter = source.presenter\n if (source.links) links = source.links\n if (source.checksumSource !== undefined) checksumSource = source.checksumSource\n }\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'buildSource failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Fall back to formatResult if no presenter from buildSource\n if (!presenter && config.formatResult) {\n try {\n const result = await config.formatResult(buildContext)\n if (result) presenter = result\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'formatResult failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Resolve URL if not already set\n if (!url && config.resolveUrl) {\n try {\n const result = await config.resolveUrl(buildContext)\n if (result) url = result\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'resolveUrl failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Resolve links if not already set\n if (!links && config.resolveLinks) {\n try {\n const result = await config.resolveLinks(buildContext)\n if (result) links = result\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'resolveLinks failed', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n applyBuildRecordChanges(buildContext.record, params.record, exclusion)\n\n return {\n entityId: params.entityId,\n recordId: params.recordId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n fields: params.record,\n plaintextExcludedCustomFields: toPlaintextExcludedCustomFields(exclusion),\n presenter,\n url,\n links,\n text,\n checksumSource,\n }\n }\n\n /**\n * Index a record by ID (loads the record from database first).\n * Used by workers that only have record identifiers.\n */\n async indexRecordById(params: {\n entityId: EntityId\n recordId: string\n tenantId: string\n organizationId?: string | null\n }): Promise<{ action: 'indexed' | 'skipped'; reason?: string }> {\n return this.indexRecordByIdWithExclusions(params, this.createCustomFieldExclusionLookup())\n }\n\n private async indexRecordByIdWithExclusions(\n params: IndexRecordByIdParams,\n exclusions: CustomFieldExclusionLookup,\n ): Promise<{ action: 'indexed' | 'skipped'; reason?: string }> {\n if (!this.queryEngine) {\n return { action: 'skipped', reason: 'queryEngine not available' }\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config || config.enabled === false) {\n return { action: 'skipped', reason: 'entity not configured' }\n }\n\n // Load record from database\n try {\n const result = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n filters: { id: params.recordId },\n includeCustomFields: true,\n page: { page: 1, pageSize: 1 },\n skipAutoReindex: true,\n })\n\n const record = result.items[0] as Record<string, unknown> | undefined\n if (!record) {\n return { action: 'skipped', reason: 'record not found' }\n }\n\n // Extract custom fields\n const customFields: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(record)) {\n if (key.startsWith('cf:') || key.startsWith('cf_')) {\n customFields[key.slice(3)] = value\n }\n }\n\n const outcome = await this.indexRecordThroughGate({\n entityId: params.entityId,\n recordId: params.recordId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n record,\n customFields,\n }, exclusions)\n\n if (outcome === 'excluded') {\n return { action: 'skipped', reason: 'excluded by shouldIndex' }\n }\n return { action: 'indexed' }\n } catch (error) {\n searchError('SearchIndexer', 'Failed to load record for indexing', {\n entityId: params.entityId,\n recordId: params.recordId,\n error: error instanceof Error ? error.message : error,\n })\n throw error\n }\n }\n\n /**\n * Index a batch of records by id in a single bulk write.\n * Unlike calling indexRecordById() in a loop, this loads each record fresh\n * (same as indexRecordById) but flushes the whole batch through a single\n * searchService.bulkIndex() call. Strategies that implement bulkIndex then\n * collapse the batch into one write; strategies without it still write per\n * record, at the bounded concurrency SearchService applies.\n */\n async indexRecordsById(params: IndexRecordsByIdParams): Promise<{ indexed: number; skipped: number }> {\n const { items, tenantId, organizationId } = params\n if (!this.queryEngine || items.length === 0) {\n return { indexed: 0, skipped: items.length }\n }\n\n const recordIdsByEntity = new Map<EntityId, string[]>()\n for (const item of items) {\n const list = recordIdsByEntity.get(item.entityId) ?? []\n list.push(item.recordId)\n recordIdsByEntity.set(item.entityId, list)\n }\n const exclusions = this.createCustomFieldExclusionLookup()\n\n const allRecords: IndexableRecord[] = []\n let skipped = 0\n\n for (const [entityId, recordIds] of recordIdsByEntity) {\n const config = this.entityConfigMap.get(entityId)\n if (!config || config.enabled === false) {\n skipped += recordIds.length\n continue\n }\n\n for (const recordId of recordIds) {\n try {\n const result = await this.queryEngine.query(entityId, {\n tenantId,\n organizationId: organizationId ?? undefined,\n filters: { id: recordId },\n includeCustomFields: true,\n page: { page: 1, pageSize: 1 },\n skipAutoReindex: true,\n })\n\n const record = result.items[0] as Record<string, unknown> | undefined\n if (!record) {\n skipped++\n continue\n }\n\n const { records: built, dropped, excluded } = await this.buildIndexableRecords(\n entityId,\n tenantId,\n organizationId ?? null,\n [record],\n config,\n exclusions,\n )\n skipped += dropped + excluded\n allRecords.push(...built)\n } catch (error) {\n skipped++\n searchError('SearchIndexer', 'Failed to load record for batch indexing', {\n entityId,\n recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n }\n\n if (allRecords.length > 0) {\n await this.searchService.bulkIndex(allRecords)\n }\n\n return { indexed: allRecords.length, skipped }\n }\n\n /**\n * Delete a record from the search index.\n */\n async deleteRecord(params: DeleteRecordParams): Promise<void> {\n await this.searchService.delete(params.entityId, params.recordId, params.tenantId)\n }\n\n /**\n * Purge all records of an entity type from the search index.\n */\n async purgeEntity(params: PurgeEntityParams): Promise<void> {\n await this.searchService.purge(params.entityId, params.tenantId, params.organizationId)\n }\n\n /**\n * Reindex an entity via all configured strategies (including vector).\n * This is the general reindex method that works with all search strategies.\n */\n async reindexEntity(params: {\n entityId: EntityId\n tenantId: string\n organizationId?: string | null\n purgeFirst?: boolean\n }): Promise<ReindexResult> {\n if (!this.queryEngine) {\n return {\n success: false,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n errors: [{ entityId: params.entityId, error: 'Query engine not available' }],\n }\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config || config.enabled === false) {\n return {\n success: false,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n errors: [{ entityId: params.entityId, error: 'Entity not configured for search' }],\n }\n }\n\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 1,\n recordsIndexed: 0,\n errors: [],\n }\n\n // Optionally purge first\n if (params.purgeFirst) {\n try {\n await this.searchService.purge(params.entityId, params.tenantId, params.organizationId)\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to purge entity before reindex', {\n entityId: params.entityId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Paginate through all records\n const exclusions = this.createCustomFieldExclusionLookup()\n let page = 1\n const pageSize = 200\n let hasMore = true\n\n while (hasMore && page <= MAX_PAGES) {\n try {\n const queryResult = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n includeCustomFields: true,\n page: { page, pageSize },\n skipAutoReindex: true,\n })\n\n const items = queryResult.items as Record<string, unknown>[]\n if (items.length === 0) {\n hasMore = false\n break\n }\n\n // Build and index records\n const { records } = await this.buildIndexableRecords(\n params.entityId,\n params.tenantId,\n params.organizationId ?? null,\n items,\n config,\n exclusions,\n )\n\n // Bulk index records via SearchService (sends to all strategies)\n if (records.length > 0) {\n try {\n await this.searchService.bulkIndex(records)\n result.recordsIndexed += records.length\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to bulk index records', {\n entityId: params.entityId,\n recordCount: records.length,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n page++\n hasMore = items.length === pageSize\n } catch (error) {\n result.success = false\n result.errors.push({\n entityId: params.entityId,\n error: error instanceof Error ? error.message : String(error),\n })\n break\n }\n }\n\n return result\n }\n\n /**\n * Reindex all enabled entities via all configured strategies.\n */\n async reindexAll(params: {\n tenantId: string\n organizationId?: string | null\n purgeFirst?: boolean\n }): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n errors: [],\n }\n\n const enabledEntities = this.listEnabledEntities()\n\n for (const entityId of enabledEntities) {\n const entityResult = await this.reindexEntity({\n entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n purgeFirst: params.purgeFirst,\n })\n\n result.entitiesProcessed++\n result.recordsIndexed += entityResult.recordsIndexed\n result.errors.push(...entityResult.errors)\n\n if (!entityResult.success) {\n result.success = false\n }\n }\n\n return result\n }\n\n /**\n * Bulk index multiple records.\n */\n async bulkIndexRecords(params: IndexRecordParams[]): Promise<void> {\n const indexableRecords: IndexableRecord[] = []\n const exclusions = this.createCustomFieldExclusionLookup()\n\n for (const param of params) {\n const built = await this.buildIndexableRecord(param, exclusions)\n if (built !== 'unconfigured' && built !== 'excluded') {\n indexableRecords.push(built)\n }\n }\n\n if (indexableRecords.length > 0) {\n try {\n await this.searchService.bulkIndex(indexableRecords)\n } catch (error) {\n throw new Error(\n `Failed to bulk index ${indexableRecords.length} records: ${\n error instanceof Error ? error.message : error\n }`\n )\n }\n }\n }\n\n /**\n * List all enabled entity IDs from the module configurations.\n */\n listEnabledEntities(): EntityId[] {\n return Array.from(this.entityConfigMap.keys())\n }\n\n /**\n * Get the fulltext strategy from the search service.\n */\n private getFulltextStrategy(): FullTextSearchStrategy | undefined {\n const strategy = this.searchService.getStrategy('fulltext')\n if (!strategy) return undefined\n return strategy as FullTextSearchStrategy\n }\n\n /**\n * Reindex a single entity type to fulltext search.\n * This fetches all records from the database and re-indexes them to fulltext only.\n *\n * When `useQueue` is true, batches are enqueued for background processing by workers.\n * When `useQueue` is false (default), batches are indexed directly (blocking).\n */\n async reindexEntityToFulltext(params: ReindexEntityParams): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n if (!isEntityIndexStrategyAllowed(params.entityId, 'fulltext', this.moduleConfigs)) return result\n\n const fulltext = this.getFulltextStrategy()\n if (!fulltext) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Fulltext strategy not available' })\n return result\n }\n\n // If useQueue is requested but no queue is available, return error\n if (params.useQueue && !this.fulltextQueue) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Fulltext queue not configured for queue-based reindexing' })\n return result\n }\n\n if (!this.queryEngine) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'QueryEngine not available for reindexing' })\n return result\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Entity not configured for search' })\n return result\n }\n\n try {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'starting',\n processed: 0,\n })\n\n if (params.recreateIndex !== false) {\n if (!canScopedPurge(fulltext)) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: scopedPurgeUnsupportedError(fulltext) })\n return result\n }\n await fulltext.purge(params.entityId, params.tenantId, params.organizationId ?? null)\n }\n\n // Fetch and index records with pagination\n const exclusions = this.createCustomFieldExclusionLookup()\n const pageSize = 200\n let page = 1\n let totalProcessed = 0\n let jobsEnqueued = 0\n\n for (;;) {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'fetching',\n processed: totalProcessed,\n })\n\n try {\n const queryResult = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n page: { page, pageSize },\n skipAutoReindex: true,\n })\n\n if (!queryResult.items.length) {\n break\n }\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'indexing',\n processed: totalProcessed,\n total: queryResult.total,\n })\n\n // Build IndexableRecords for this batch\n const { records: indexableRecords, dropped } = await this.buildIndexableRecords(\n params.entityId,\n params.tenantId,\n params.organizationId ?? null,\n queryResult.items,\n config,\n exclusions,\n )\n result.recordsDropped = (result.recordsDropped ?? 0) + dropped\n\n // Index to fulltext - either via queue or directly\n if (indexableRecords.length > 0) {\n if (params.useQueue && this.fulltextQueue) {\n // Enqueue batch for background processing - only pass minimal references\n // Worker will load fresh data from entity_indexes table\n await this.fulltextQueue.enqueue({\n jobType: 'batch-index',\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n records: indexableRecords.map((r) => ({ entityId: r.entityId, recordId: r.recordId })),\n })\n jobsEnqueued += 1\n totalProcessed += indexableRecords.length\n } else {\n // Direct indexing (blocking)\n try {\n await fulltext.bulkIndex(indexableRecords)\n totalProcessed += indexableRecords.length\n } catch (indexError) {\n // Log error but continue with remaining batches\n const errorMsg = indexError instanceof Error ? indexError.message : String(indexError)\n result.errors.push({\n entityId: params.entityId,\n error: `Batch ${page} failed: ${errorMsg}`,\n })\n }\n }\n }\n\n if (queryResult.items.length < pageSize) {\n break\n }\n page += 1\n\n // Safety check to prevent infinite loops\n if (page > MAX_PAGES) {\n break\n }\n } catch (queryError) {\n const errorMsg = queryError instanceof Error ? queryError.message : String(queryError)\n result.errors.push({\n entityId: params.entityId,\n error: `Query failed: ${errorMsg}`,\n })\n break\n }\n }\n\n result.entitiesProcessed = 1\n result.recordsIndexed = totalProcessed\n result.jobsEnqueued = jobsEnqueued\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'complete',\n processed: totalProcessed,\n total: totalProcessed,\n })\n } catch (error) {\n result.success = false\n result.errors.push({\n entityId: params.entityId,\n error: error instanceof Error ? error.message : String(error),\n })\n }\n\n return result\n }\n\n /**\n * Reindex all enabled entities to fulltext search.\n *\n * When `useQueue` is true, batches are enqueued for background processing by workers.\n * When `useQueue` is false (default), batches are indexed directly (blocking).\n */\n async reindexAllToFulltext(params: ReindexAllParams): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n const fulltext = this.getFulltextStrategy()\n if (!fulltext) {\n result.success = false\n result.errors.push({ entityId: 'all' as EntityId, error: 'Fulltext strategy not available' })\n return result\n }\n\n const clearIndex = params.recreateIndex !== false\n const organizationScoped = typeof params.organizationId === 'string' && params.organizationId.trim().length > 0\n if (clearIndex && !organizationScoped) {\n await fulltext.recreateIndex(params.tenantId)\n }\n if (clearIndex && organizationScoped && !canScopedPurge(fulltext)) {\n result.success = false\n result.errors.push({ entityId: 'all' as EntityId, error: scopedPurgeUnsupportedError(fulltext) })\n return result\n }\n\n const entities = this.listEnabledEntities()\n\n for (const entityId of entities) {\n const entityResult = await this.reindexEntityToFulltext({\n entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n recreateIndex: clearIndex && organizationScoped,\n onProgress: params.onProgress,\n useQueue: params.useQueue,\n })\n\n result.entitiesProcessed += entityResult.entitiesProcessed\n result.recordsIndexed += entityResult.recordsIndexed\n result.recordsDropped = (result.recordsDropped ?? 0) + (entityResult.recordsDropped ?? 0)\n result.jobsEnqueued = (result.jobsEnqueued ?? 0) + (entityResult.jobsEnqueued ?? 0)\n result.errors.push(...entityResult.errors)\n\n if (!entityResult.success) {\n result.success = false\n }\n }\n\n return result\n }\n\n /**\n * Reindex a single entity type to vector search.\n * This fetches all records from the database and enqueues them for vector indexing.\n *\n * When `useQueue` is true (default), record IDs are enqueued for background processing by workers.\n * When `useQueue` is false, records are indexed directly (blocking).\n */\n async reindexEntityToVector(params: ReindexEntityParams & { purgeFirst?: boolean }): Promise<ReindexResult> {\n searchDebug('SearchIndexer', 'reindexEntityToVector called', {\n entityId: params.entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n useQueue: params.useQueue,\n purgeFirst: params.purgeFirst,\n })\n\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n if (!isEntityIndexStrategyAllowed(params.entityId, 'vector', this.moduleConfigs)) return result\n\n // If useQueue is requested but no queue is available, return error\n if (params.useQueue !== false && !this.vectorQueue) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Vector queue not configured for queue-based reindexing' })\n return result\n }\n\n if (!this.queryEngine) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'QueryEngine not available for reindexing' })\n return result\n }\n\n const config = this.entityConfigMap.get(params.entityId)\n if (!config) {\n result.success = false\n result.errors.push({ entityId: params.entityId, error: 'Entity not configured for search' })\n return result\n }\n\n try {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'starting',\n processed: 0,\n })\n\n // Optionally purge vector index first\n if (params.purgeFirst) {\n try {\n await this.searchService.purge(params.entityId, params.tenantId, params.organizationId)\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to purge entity before vector reindex', {\n entityId: params.entityId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n\n // Fetch and enqueue records with pagination\n const pageSize = 200\n let page = 1\n let totalProcessed = 0\n let jobsEnqueued = 0\n const exclusions = this.createCustomFieldExclusionLookup()\n\n for (;;) {\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'fetching',\n processed: totalProcessed,\n })\n\n const queryResult = await this.queryEngine.query(params.entityId, {\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? undefined,\n page: { page, pageSize },\n skipAutoReindex: true,\n })\n\n if (!queryResult.items.length) break\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'indexing',\n processed: totalProcessed,\n total: queryResult.total,\n })\n\n // Build batch of record references\n const batchRecords: VectorBatchRecord[] = []\n for (const item of queryResult.items) {\n const recordId = String((item as Record<string, unknown>).id ?? '')\n if (!recordId) {\n result.recordsDropped = (result.recordsDropped ?? 0) + 1\n continue\n }\n batchRecords.push({\n entityId: params.entityId,\n recordId,\n })\n }\n\n // Enqueue batch for background processing or index directly\n if (batchRecords.length > 0) {\n if (params.useQueue !== false && this.vectorQueue) {\n await this.vectorQueue.enqueue({\n jobType: 'batch-index',\n tenantId: params.tenantId,\n organizationId: params.organizationId ?? null,\n records: batchRecords,\n })\n jobsEnqueued += 1\n totalProcessed += batchRecords.length\n searchDebug('SearchIndexer', 'Enqueued batch for vector indexing', {\n entityId: params.entityId,\n batchSize: batchRecords.length,\n jobsEnqueued,\n totalProcessed,\n })\n } else {\n // Direct indexing (blocking) - index each record via SearchService\n for (const { entityId, recordId } of batchRecords) {\n try {\n await this.indexRecordByIdWithExclusions({\n entityId: entityId as EntityId,\n recordId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n }, exclusions)\n totalProcessed++\n } catch (error) {\n searchDebugWarn('SearchIndexer', 'Failed to index record to vector', {\n entityId,\n recordId,\n error: error instanceof Error ? error.message : error,\n })\n }\n }\n }\n }\n\n if (queryResult.items.length < pageSize) break\n page += 1\n\n // Safety check to prevent infinite loops\n if (page > MAX_PAGES) {\n searchDebugWarn('SearchIndexer', 'Reached MAX_PAGES limit, stopping pagination', {\n entityId: params.entityId,\n maxPages: MAX_PAGES,\n totalProcessed,\n })\n break\n }\n }\n\n result.entitiesProcessed = 1\n result.recordsIndexed = totalProcessed\n result.jobsEnqueued = jobsEnqueued\n\n params.onProgress?.({\n entityId: params.entityId,\n phase: 'complete',\n processed: totalProcessed,\n total: totalProcessed,\n })\n } catch (error) {\n result.success = false\n result.errors.push({\n entityId: params.entityId,\n error: error instanceof Error ? error.message : String(error),\n })\n }\n\n return result\n }\n\n /**\n * Reindex all enabled entities to vector search.\n *\n * When `useQueue` is true (default), batches are enqueued for background processing by workers.\n * When `useQueue` is false, batches are indexed directly (blocking).\n */\n async reindexAllToVector(params: ReindexAllParams & { purgeFirst?: boolean }): Promise<ReindexResult> {\n const result: ReindexResult = {\n success: true,\n entitiesProcessed: 0,\n recordsIndexed: 0,\n recordsDropped: 0,\n jobsEnqueued: 0,\n errors: [],\n }\n\n const entities = this.listEnabledEntities()\n for (const entityId of entities) {\n const entityResult = await this.reindexEntityToVector({\n entityId,\n tenantId: params.tenantId,\n organizationId: params.organizationId,\n onProgress: params.onProgress,\n useQueue: params.useQueue,\n purgeFirst: params.purgeFirst,\n })\n\n result.entitiesProcessed += entityResult.entitiesProcessed\n result.recordsIndexed += entityResult.recordsIndexed\n result.recordsDropped = (result.recordsDropped ?? 0) + (entityResult.recordsDropped ?? 0)\n result.jobsEnqueued = (result.jobsEnqueued ?? 0) + (entityResult.jobsEnqueued ?? 0)\n result.errors.push(...entityResult.errors)\n\n if (!entityResult.success) {\n result.success = false\n }\n }\n\n return result\n }\n\n /**\n * Build IndexableRecords from raw query results.\n * Returns records and count of dropped items (missing id or other validation failures).\n */\n private async buildIndexableRecords(\n entityId: EntityId,\n tenantId: string,\n organizationId: string | null,\n items: Record<string, unknown>[],\n config: SearchEntityConfig,\n exclusions: CustomFieldExclusionLookup = this.createCustomFieldExclusionLookup(),\n ): Promise<{ records: IndexableRecord[]; dropped: number; excluded: number }> {\n const records: IndexableRecord[] = []\n let dropped = 0\n let excluded = 0\n const exclusion = await exclusions(entityId, tenantId)\n const plaintextExcludedCustomFields = toPlaintextExcludedCustomFields(exclusion)\n const buildQueryEngine = this.createBuildQueryEngine(exclusions)\n\n if (items.length > 0) {\n searchDebug('SearchIndexer', 'Sample item structure', {\n entityId,\n sampleKeys: Object.keys(items[0]),\n hasId: 'id' in items[0],\n })\n }\n\n for (const item of items) {\n const recordId = String(item.id ?? '')\n if (!recordId) {\n searchDebugWarn('SearchIndexer', 'Skipping item without id', { entityId, itemKeys: Object.keys(item) })\n dropped++\n continue\n }\n\n // Extract custom fields from record\n const customFields: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(item)) {\n if (key.startsWith('cf:') || key.startsWith('cf_')) {\n const cfKey = key.slice(3) // Remove 'cf:' or 'cf_' prefix (both are 3 chars)\n customFields[cfKey] = value\n }\n }\n\n const buildContext: SearchBuildContext = {\n record: withoutExcludedRecordCustomFields(item, exclusion),\n customFields: withoutExcludedCustomFields(customFields, exclusion),\n organizationId,\n tenantId,\n queryEngine: buildQueryEngine,\n }\n\n if (!(await this.passesIndexGate(config, buildContext, entityId, recordId))) {\n await this.searchService.delete(entityId, recordId, tenantId)\n excluded++\n continue\n }\n\n // Try buildSource first (provides text, presenter, links, checksumSource)\n let text: string | string[] | undefined = config.buildSource ? [] : undefined\n let presenter: SearchResultPresenter | undefined\n let url: string | undefined\n let links: SearchResultLink[] | undefined\n let checksumSource: unknown | undefined\n\n if (config.buildSource) {\n try {\n const source = await config.buildSource(buildContext)\n if (source) {\n text = source.text ?? []\n if (source.presenter) presenter = source.presenter\n if (source.links) links = source.links\n if (source.checksumSource !== undefined) checksumSource = source.checksumSource\n }\n } catch (err) {\n searchDebugWarn('SearchIndexer', 'buildSource failed', {\n entityId,\n recordId,\n error: err instanceof Error ? err.message : err,\n })\n }\n }\n\n // Fall back to formatResult if no presenter from buildSource\n if (!presenter && config.formatResult) {\n try {\n const result = await config.formatResult(buildContext)\n if (result) presenter = result\n } catch {\n // Skip presenter on error\n }\n }\n\n // Resolve URL if not already set\n if (!url && config.resolveUrl) {\n try {\n const result = await config.resolveUrl(buildContext)\n if (result) url = result\n } catch {\n // Skip URL on error\n }\n }\n\n // Resolve links if not already set\n if (!links && config.resolveLinks) {\n try {\n const result = await config.resolveLinks(buildContext)\n if (result) links = result\n } catch {\n // Skip links on error\n }\n }\n\n applyBuildRecordChanges(buildContext.record, item, exclusion)\n\n records.push({\n entityId,\n recordId,\n tenantId,\n organizationId,\n fields: item,\n plaintextExcludedCustomFields,\n presenter,\n url,\n links,\n text,\n checksumSource,\n })\n }\n\n searchDebug('SearchIndexer', 'Finished building records', {\n entityId,\n inputCount: items.length,\n outputCount: records.length,\n dropped,\n excluded,\n })\n\n return { records, dropped, excluded }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oCAAoC;AAgB7C,SAAS,mBAAmB,aAAa,iBAAiB,aAAa,kBAAkB;AAEzF,SAAS,8BAA8B;AAMvC,MAAM,YAAY;AAUlB,SAAS,gCACP,WACkD;AAClD,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,cAAc,QAAQ,QAAQ,MAAM,KAAK,SAAS;AAC3D;AAEA,SAAS,2BAA2B,YAA0D;AAC5F,MAAI,WAAW,SAAS,KAAK,EAAG,QAAO;AACvC,QAAM,OAAO,WAAW,OAAO,CAAC,cAAwC,qBAAqB,GAAG;AAChG,MAAI,CAAC,KAAK,OAAQ,QAAO;AACzB,MAAI,KAAK,WAAW,EAAG,QAAO,KAAK,CAAC;AACpC,SAAO,IAAI,IAAI,KAAK,QAAQ,CAAC,QAAQ,MAAM,KAAK,GAAG,CAAC,CAAC;AACvD;AAEA,SAAS,sBAAsB,KAAa,WA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