@open-mercato/search 0.5.1-develop.2691.d8a0934b37 → 0.5.1-develop.2694.732417c5ec
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/dist/di.js +9 -9
- package/dist/di.js.map +2 -2
- package/dist/lib/presenter-enricher.js +14 -14
- package/dist/lib/presenter-enricher.js.map +2 -2
- package/dist/modules/search/api/embeddings/reindex/cancel/route.js +2 -2
- package/dist/modules/search/api/embeddings/reindex/cancel/route.js.map +2 -2
- package/dist/modules/search/api/embeddings/reindex/route.js +3 -3
- package/dist/modules/search/api/embeddings/reindex/route.js.map +2 -2
- package/dist/modules/search/api/reindex/cancel/route.js +2 -2
- package/dist/modules/search/api/reindex/cancel/route.js.map +2 -2
- package/dist/modules/search/api/reindex/route.js +4 -4
- package/dist/modules/search/api/reindex/route.js.map +2 -2
- package/dist/modules/search/api/settings/route.js +3 -3
- package/dist/modules/search/api/settings/route.js.map +2 -2
- package/dist/modules/search/lib/reindex-lock.js +20 -17
- package/dist/modules/search/lib/reindex-lock.js.map +2 -2
- package/dist/modules/search/subscribers/fulltext_upsert.js +2 -2
- package/dist/modules/search/subscribers/fulltext_upsert.js.map +2 -2
- package/dist/modules/search/subscribers/vector_delete.js +2 -2
- package/dist/modules/search/subscribers/vector_delete.js.map +2 -2
- package/dist/modules/search/subscribers/vector_upsert.js +2 -2
- package/dist/modules/search/subscribers/vector_upsert.js.map +2 -2
- package/dist/modules/search/workers/fulltext-index.worker.js +7 -7
- package/dist/modules/search/workers/fulltext-index.worker.js.map +2 -2
- package/dist/modules/search/workers/vector-index.worker.js +7 -7
- package/dist/modules/search/workers/vector-index.worker.js.map +2 -2
- package/dist/strategies/token.strategy.js +15 -10
- package/dist/strategies/token.strategy.js.map +2 -2
- package/jest.config.cjs +4 -2
- package/package.json +4 -4
- package/src/__tests__/presenter-enricher.test.ts +17 -60
- package/src/__tests__/workers.test.ts +20 -21
- package/src/di.ts +22 -21
- package/src/lib/presenter-enricher.ts +21 -20
- package/src/modules/search/api/embeddings/reindex/cancel/route.ts +4 -3
- package/src/modules/search/api/embeddings/reindex/route.ts +5 -4
- package/src/modules/search/api/reindex/cancel/route.ts +4 -3
- package/src/modules/search/api/reindex/route.ts +5 -5
- package/src/modules/search/api/settings/route.ts +5 -4
- package/src/modules/search/lib/reindex-lock.ts +50 -32
- package/src/modules/search/subscribers/fulltext_upsert.ts +6 -2
- package/src/modules/search/subscribers/vector_delete.ts +6 -2
- package/src/modules/search/subscribers/vector_upsert.ts +6 -2
- package/src/modules/search/workers/fulltext-index.worker.ts +10 -9
- package/src/modules/search/workers/vector-index.worker.ts +10 -9
- package/src/strategies/token.strategy.ts +25 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Kysely, sql, type SqlBool } from 'kysely'
|
|
2
2
|
import type {
|
|
3
3
|
SearchStrategy,
|
|
4
4
|
SearchStrategyId,
|
|
@@ -34,7 +34,7 @@ export class TokenSearchStrategy implements SearchStrategy {
|
|
|
34
34
|
private readonly defaultLimit: number
|
|
35
35
|
|
|
36
36
|
constructor(
|
|
37
|
-
private readonly
|
|
37
|
+
private readonly db: Kysely<any>,
|
|
38
38
|
config?: TokenStrategyConfig,
|
|
39
39
|
) {
|
|
40
40
|
this.minMatchRatio = config?.minMatchRatio ?? 0.5
|
|
@@ -63,25 +63,29 @@ export class TokenSearchStrategy implements SearchStrategy {
|
|
|
63
63
|
const minMatches = Math.max(1, Math.ceil(hashes.length * this.minMatchRatio))
|
|
64
64
|
const limit = options.limit ?? this.defaultLimit
|
|
65
65
|
|
|
66
|
-
let queryBuilder = this.
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.
|
|
66
|
+
let queryBuilder = this.db
|
|
67
|
+
.selectFrom('search_tokens' as any)
|
|
68
|
+
.select([
|
|
69
|
+
'entity_type' as any,
|
|
70
|
+
'entity_id' as any,
|
|
71
|
+
sql<string>`count(*)`.as('match_count'),
|
|
72
|
+
])
|
|
73
|
+
.where('token_hash' as any, 'in', hashes)
|
|
74
|
+
.where('tenant_id' as any, '=', options.tenantId)
|
|
75
|
+
.groupBy(['entity_type' as any, 'entity_id' as any])
|
|
76
|
+
.having(sql<SqlBool>`count(distinct token_hash) >= ${minMatches}`)
|
|
77
|
+
.orderBy(sql`count(distinct token_hash) desc`)
|
|
74
78
|
.limit(limit)
|
|
75
79
|
|
|
76
80
|
if (options.organizationId) {
|
|
77
|
-
queryBuilder = queryBuilder.where('organization_id', options.organizationId)
|
|
81
|
+
queryBuilder = queryBuilder.where('organization_id' as any, '=', options.organizationId)
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
if (options.entityTypes?.length) {
|
|
81
|
-
queryBuilder = queryBuilder.
|
|
85
|
+
queryBuilder = queryBuilder.where('entity_type' as any, 'in', options.entityTypes)
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
const rows = await queryBuilder as Array<{ entity_type: string; entity_id: string; match_count: string | number }>
|
|
88
|
+
const rows = await queryBuilder.execute() as Array<{ entity_type: string; entity_id: string; match_count: string | number }>
|
|
85
89
|
|
|
86
90
|
return rows.map((row) => {
|
|
87
91
|
const matchCount = typeof row.match_count === 'string'
|
|
@@ -105,7 +109,7 @@ export class TokenSearchStrategy implements SearchStrategy {
|
|
|
105
109
|
'@open-mercato/core/modules/query_index/lib/search-tokens'
|
|
106
110
|
)
|
|
107
111
|
|
|
108
|
-
await replaceSearchTokensForRecord(this.
|
|
112
|
+
await replaceSearchTokensForRecord(this.db, {
|
|
109
113
|
entityType: record.entityId,
|
|
110
114
|
recordId: record.recordId,
|
|
111
115
|
tenantId: record.tenantId,
|
|
@@ -120,7 +124,7 @@ export class TokenSearchStrategy implements SearchStrategy {
|
|
|
120
124
|
'@open-mercato/core/modules/query_index/lib/search-tokens'
|
|
121
125
|
)
|
|
122
126
|
|
|
123
|
-
await deleteSearchTokensForRecord(this.
|
|
127
|
+
await deleteSearchTokensForRecord(this.db, {
|
|
124
128
|
entityType: entityId,
|
|
125
129
|
recordId,
|
|
126
130
|
tenantId,
|
|
@@ -142,12 +146,14 @@ export class TokenSearchStrategy implements SearchStrategy {
|
|
|
142
146
|
doc: record.fields as Record<string, unknown>,
|
|
143
147
|
}))
|
|
144
148
|
|
|
145
|
-
await replaceSearchTokensForBatch(this.
|
|
149
|
+
await replaceSearchTokensForBatch(this.db, payloads)
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
async purge(entityId: EntityId, tenantId: string): Promise<void> {
|
|
149
|
-
await this.
|
|
150
|
-
.
|
|
151
|
-
.
|
|
153
|
+
await this.db
|
|
154
|
+
.deleteFrom('search_tokens' as any)
|
|
155
|
+
.where('entity_type' as any, '=', entityId)
|
|
156
|
+
.where('tenant_id' as any, '=', tenantId)
|
|
157
|
+
.execute()
|
|
152
158
|
}
|
|
153
159
|
}
|