graphile-search 2.20.5 → 2.20.6
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/README.md +14 -0
- package/adapters/tsvector.js +8 -3
- package/codecs/operator-factories.d.ts +1 -1
- package/codecs/operator-factories.js +5 -2
- package/esm/adapters/tsvector.js +8 -3
- package/esm/codecs/operator-factories.d.ts +1 -1
- package/esm/codecs/operator-factories.js +5 -2
- package/esm/plugin.js +17 -2
- package/esm/preset.js +3 -3
- package/esm/ts-config.d.ts +5 -0
- package/esm/ts-config.js +41 -0
- package/package.json +2 -2
- package/plugin.js +17 -2
- package/preset.js +3 -3
- package/ts-config.d.ts +5 -0
- package/ts-config.js +47 -0
package/README.md
CHANGED
|
@@ -48,6 +48,20 @@ const preset = {
|
|
|
48
48
|
};
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
### Request language
|
|
52
|
+
|
|
53
|
+
Without an explicit configuration, tsvector filters, `unifiedSearch`, and
|
|
54
|
+
`FullText.matches` use the request context's ordered `langCodes`. The first
|
|
55
|
+
supported primary subtag selects a PostgreSQL configuration (`fr-CA` → `french`,
|
|
56
|
+
`de-DE` → `german`); built-in configuration names such as `french` also work.
|
|
57
|
+
Missing, empty, or entirely unsupported preferences retain the English default.
|
|
58
|
+
The server supplies these preferences from HTTP and WebSocket `Accept-Language`.
|
|
59
|
+
|
|
60
|
+
An explicit column `@tsConfig` tag takes precedence over adapter `tsConfig`,
|
|
61
|
+
then preset `tsConfig`, then request preferences. Configuration names and query
|
|
62
|
+
text are SQL parameters; request preferences can select only built-in names
|
|
63
|
+
from the language mapping.
|
|
64
|
+
|
|
51
65
|
## Features
|
|
52
66
|
|
|
53
67
|
- **4 search algorithms** via adapters: tsvector (ts_rank), BM25 (pg_textsearch), pg_trgm (similarity), pgvector (distance)
|
package/adapters/tsvector.js
CHANGED
|
@@ -22,7 +22,7 @@ function isTsvectorCodec(codec) {
|
|
|
22
22
|
codec?.extensions?.pg?.name === 'tsvector'));
|
|
23
23
|
}
|
|
24
24
|
function createTsvectorAdapter(options = {}) {
|
|
25
|
-
const { filterPrefix = 'tsv', tsConfig
|
|
25
|
+
const { filterPrefix = 'tsv', tsConfig } = options;
|
|
26
26
|
return {
|
|
27
27
|
name: 'tsv',
|
|
28
28
|
scoreSemantics: {
|
|
@@ -46,9 +46,12 @@ function createTsvectorAdapter(options = {}) {
|
|
|
46
46
|
const chunksInfo = (0, chunks_1.getChunksInfo)(codec);
|
|
47
47
|
const hasChunkFulltext = chunksInfo?.searchField &&
|
|
48
48
|
chunksInfo.searchIndexes.includes('fulltext');
|
|
49
|
+
const columnConfig = attribute.extensions?.tags?.tsConfig;
|
|
49
50
|
columns.push({
|
|
50
51
|
attributeName,
|
|
51
|
-
adapterData: hasChunkFulltext
|
|
52
|
+
adapterData: hasChunkFulltext || typeof columnConfig === 'string'
|
|
53
|
+
? { ...(hasChunkFulltext ? chunksInfo : {}), ...(typeof columnConfig === 'string' && { tsConfig: columnConfig }) }
|
|
54
|
+
: undefined,
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -75,7 +78,9 @@ function createTsvectorAdapter(options = {}) {
|
|
|
75
78
|
}
|
|
76
79
|
if (val.trim().length === 0)
|
|
77
80
|
return null;
|
|
78
|
-
const
|
|
81
|
+
const data = column.adapterData;
|
|
82
|
+
const config = data?.tsConfig ?? tsConfig ?? data?.requestTsConfig ?? 'english';
|
|
83
|
+
const tsquery = sql `websearch_to_tsquery(${sql.value(config)}::regconfig, ${sql.value(val)})`;
|
|
79
84
|
const columnExpr = sql `${alias}.${sql.identifier(column.attributeName)}`;
|
|
80
85
|
// Check for chunk-aware querying
|
|
81
86
|
const chunksInfo = column.adapterData;
|
|
@@ -13,7 +13,7 @@ import type { ConnectionFilterOperatorFactory } from 'graphile-connection-filter
|
|
|
13
13
|
* Declared here so it's registered via the declarative
|
|
14
14
|
* `connectionFilterOperatorFactories` API.
|
|
15
15
|
*/
|
|
16
|
-
export declare function createMatchesOperatorFactory(fullTextScalarName: string, tsConfig
|
|
16
|
+
export declare function createMatchesOperatorFactory(fullTextScalarName: string, tsConfig?: string): ConnectionFilterOperatorFactory;
|
|
17
17
|
/**
|
|
18
18
|
* Creates the `similarTo` and `wordSimilarTo` filter operator factories
|
|
19
19
|
* for pg_trgm fuzzy text matching. Declared here so they're registered
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createMatchesOperatorFactory = createMatchesOperatorFactory;
|
|
13
13
|
exports.createTrgmOperatorFactories = createTrgmOperatorFactories;
|
|
14
|
+
const ts_config_1 = require("../ts-config");
|
|
14
15
|
/**
|
|
15
16
|
* Creates the `matches` filter operator factory for full-text search.
|
|
16
17
|
* Declared here so it's registered via the declarative
|
|
@@ -27,8 +28,10 @@ function createMatchesOperatorFactory(fullTextScalarName, tsConfig) {
|
|
|
27
28
|
description: 'Performs a full text search on the field.',
|
|
28
29
|
resolveType: () => GraphQLString,
|
|
29
30
|
resolveInputCodec: TYPES ? () => TYPES.text : undefined,
|
|
30
|
-
resolve(sqlIdentifier, sqlValue, _input,
|
|
31
|
-
|
|
31
|
+
resolve(sqlIdentifier, sqlValue, _input, $where, _details) {
|
|
32
|
+
const columnConfig = $where.extensions?.pgFilterAttribute?.attribute?.extensions?.tags?.tsConfig;
|
|
33
|
+
const config = (typeof columnConfig === 'string' ? columnConfig : undefined) ?? tsConfig ?? (0, ts_config_1.conditionTsConfig)($where) ?? 'english';
|
|
34
|
+
return sql `${sqlIdentifier} @@ websearch_to_tsquery(${sql.value(config)}::regconfig, ${sqlValue})`;
|
|
32
35
|
},
|
|
33
36
|
},
|
|
34
37
|
}];
|
package/esm/adapters/tsvector.js
CHANGED
|
@@ -19,7 +19,7 @@ function isTsvectorCodec(codec) {
|
|
|
19
19
|
codec?.extensions?.pg?.name === 'tsvector'));
|
|
20
20
|
}
|
|
21
21
|
export function createTsvectorAdapter(options = {}) {
|
|
22
|
-
const { filterPrefix = 'tsv', tsConfig
|
|
22
|
+
const { filterPrefix = 'tsv', tsConfig } = options;
|
|
23
23
|
return {
|
|
24
24
|
name: 'tsv',
|
|
25
25
|
scoreSemantics: {
|
|
@@ -43,9 +43,12 @@ export function createTsvectorAdapter(options = {}) {
|
|
|
43
43
|
const chunksInfo = getChunksInfo(codec);
|
|
44
44
|
const hasChunkFulltext = chunksInfo?.searchField &&
|
|
45
45
|
chunksInfo.searchIndexes.includes('fulltext');
|
|
46
|
+
const columnConfig = attribute.extensions?.tags?.tsConfig;
|
|
46
47
|
columns.push({
|
|
47
48
|
attributeName,
|
|
48
|
-
adapterData: hasChunkFulltext
|
|
49
|
+
adapterData: hasChunkFulltext || typeof columnConfig === 'string'
|
|
50
|
+
? { ...(hasChunkFulltext ? chunksInfo : {}), ...(typeof columnConfig === 'string' && { tsConfig: columnConfig }) }
|
|
51
|
+
: undefined,
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -72,7 +75,9 @@ export function createTsvectorAdapter(options = {}) {
|
|
|
72
75
|
}
|
|
73
76
|
if (val.trim().length === 0)
|
|
74
77
|
return null;
|
|
75
|
-
const
|
|
78
|
+
const data = column.adapterData;
|
|
79
|
+
const config = data?.tsConfig ?? tsConfig ?? data?.requestTsConfig ?? 'english';
|
|
80
|
+
const tsquery = sql `websearch_to_tsquery(${sql.value(config)}::regconfig, ${sql.value(val)})`;
|
|
76
81
|
const columnExpr = sql `${alias}.${sql.identifier(column.attributeName)}`;
|
|
77
82
|
// Check for chunk-aware querying
|
|
78
83
|
const chunksInfo = column.adapterData;
|
|
@@ -13,7 +13,7 @@ import type { ConnectionFilterOperatorFactory } from 'graphile-connection-filter
|
|
|
13
13
|
* Declared here so it's registered via the declarative
|
|
14
14
|
* `connectionFilterOperatorFactories` API.
|
|
15
15
|
*/
|
|
16
|
-
export declare function createMatchesOperatorFactory(fullTextScalarName: string, tsConfig
|
|
16
|
+
export declare function createMatchesOperatorFactory(fullTextScalarName: string, tsConfig?: string): ConnectionFilterOperatorFactory;
|
|
17
17
|
/**
|
|
18
18
|
* Creates the `similarTo` and `wordSimilarTo` filter operator factories
|
|
19
19
|
* for pg_trgm fuzzy text matching. Declared here so they're registered
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* They are used in the ConstructivePreset's connectionFilterOperatorFactories
|
|
8
8
|
* array to wire search operators into the declarative filter system.
|
|
9
9
|
*/
|
|
10
|
+
import { conditionTsConfig } from '../ts-config';
|
|
10
11
|
/**
|
|
11
12
|
* Creates the `matches` filter operator factory for full-text search.
|
|
12
13
|
* Declared here so it's registered via the declarative
|
|
@@ -23,8 +24,10 @@ export function createMatchesOperatorFactory(fullTextScalarName, tsConfig) {
|
|
|
23
24
|
description: 'Performs a full text search on the field.',
|
|
24
25
|
resolveType: () => GraphQLString,
|
|
25
26
|
resolveInputCodec: TYPES ? () => TYPES.text : undefined,
|
|
26
|
-
resolve(sqlIdentifier, sqlValue, _input,
|
|
27
|
-
|
|
27
|
+
resolve(sqlIdentifier, sqlValue, _input, $where, _details) {
|
|
28
|
+
const columnConfig = $where.extensions?.pgFilterAttribute?.attribute?.extensions?.tags?.tsConfig;
|
|
29
|
+
const config = (typeof columnConfig === 'string' ? columnConfig : undefined) ?? tsConfig ?? conditionTsConfig($where) ?? 'english';
|
|
30
|
+
return sql `${sqlIdentifier} @@ websearch_to_tsquery(${sql.value(config)}::regconfig, ${sqlValue})`;
|
|
28
31
|
},
|
|
29
32
|
},
|
|
30
33
|
}];
|
package/esm/plugin.js
CHANGED
|
@@ -21,6 +21,7 @@ import 'graphile-build-pg';
|
|
|
21
21
|
import 'graphile-connection-filter';
|
|
22
22
|
import { TYPES } from '@dataplan/pg';
|
|
23
23
|
import { getQueryBuilder } from 'graphile-plugin-utils';
|
|
24
|
+
import { columnWithRequestTsConfig, REQUEST_TS_CONFIG, requestTsConfig } from './ts-config';
|
|
24
25
|
/**
|
|
25
26
|
* Carried on a filter field that searches vector columns, for whatever embeds
|
|
26
27
|
* the search text (graphile-llm): which columns, and the model each column's
|
|
@@ -543,6 +544,20 @@ export function createUnifiedSearchPlugin(options) {
|
|
|
543
544
|
GraphQLObjectType_fields_field_args_arg(arg, build, context) {
|
|
544
545
|
const { argName, isPgFieldConnection, isPgFieldSimpleCollection, pgFieldResource } = context.scope;
|
|
545
546
|
const { applyPlan } = arg;
|
|
547
|
+
if (argName === (build.options.connectionFilterArgumentName ?? 'where') && applyPlan &&
|
|
548
|
+
(isPgFieldConnection || isPgFieldSimpleCollection)) {
|
|
549
|
+
return {
|
|
550
|
+
...arg,
|
|
551
|
+
applyPlan($parent, $result, input, info) {
|
|
552
|
+
const $select = isPgFieldConnection ? $result.getSubplan() : $result;
|
|
553
|
+
const { context, lambda } = build.grafast;
|
|
554
|
+
$select.apply(lambda(context(), (ctx) => (qb) => {
|
|
555
|
+
qb.setMeta(REQUEST_TS_CONFIG, requestTsConfig(ctx.langCodes));
|
|
556
|
+
}, true));
|
|
557
|
+
return applyPlan($parent, $result, input, info);
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
}
|
|
546
561
|
if (argName !== 'orderBy' || !applyPlan || (!isPgFieldConnection && !isPgFieldSimpleCollection))
|
|
547
562
|
return arg;
|
|
548
563
|
const codec = pgFieldResource?.codec;
|
|
@@ -971,7 +986,7 @@ export function createUnifiedSearchPlugin(options) {
|
|
|
971
986
|
apply: function plan($condition, val) {
|
|
972
987
|
if (val == null)
|
|
973
988
|
return;
|
|
974
|
-
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, column, val, build);
|
|
989
|
+
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, adapter.name === 'tsv' ? columnWithRequestTsConfig(column, $condition) : column, val, build);
|
|
975
990
|
const result = applyFor($condition.alias);
|
|
976
991
|
if (!result)
|
|
977
992
|
return;
|
|
@@ -1046,7 +1061,7 @@ export function createUnifiedSearchPlugin(options) {
|
|
|
1046
1061
|
for (const column of columns) {
|
|
1047
1062
|
// Convert text to adapter-specific filter input
|
|
1048
1063
|
const filterInput = adapter.buildTextSearchInput(text);
|
|
1049
|
-
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, column, filterInput, build);
|
|
1064
|
+
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, adapter.name === 'tsv' ? columnWithRequestTsConfig(column, $condition) : column, filterInput, build);
|
|
1050
1065
|
const result = applyFor($condition.alias);
|
|
1051
1066
|
if (!result)
|
|
1052
1067
|
continue;
|
package/esm/preset.js
CHANGED
|
@@ -29,11 +29,11 @@ import { createUnifiedSearchPlugin } from './plugin';
|
|
|
29
29
|
* Creates a preset that includes the unified search plugin with all enabled adapters.
|
|
30
30
|
*/
|
|
31
31
|
export function UnifiedSearchPreset(options = {}) {
|
|
32
|
-
const { tsvector = true, bm25 = true, trgm = true, pgvector = true, enableSearchScore = true, enableUnifiedSearch = true, searchScoreWeights, fullTextScalarName = 'FullText', tsConfig
|
|
32
|
+
const { tsvector = true, bm25 = true, trgm = true, pgvector = true, enableSearchScore = true, enableUnifiedSearch = true, searchScoreWeights, fullTextScalarName = 'FullText', tsConfig, rrfK, } = options;
|
|
33
33
|
const adapters = [];
|
|
34
34
|
if (tsvector) {
|
|
35
35
|
const opts = typeof tsvector === 'object' ? tsvector : {};
|
|
36
|
-
adapters.push(createTsvectorAdapter(opts));
|
|
36
|
+
adapters.push(createTsvectorAdapter({ ...opts, tsConfig: opts.tsConfig ?? tsConfig }));
|
|
37
37
|
}
|
|
38
38
|
if (bm25) {
|
|
39
39
|
const opts = typeof bm25 === 'object' ? bm25 : {};
|
|
@@ -65,7 +65,7 @@ export function UnifiedSearchPreset(options = {}) {
|
|
|
65
65
|
// Collect operator factories for connection filter integration
|
|
66
66
|
const operatorFactories = [];
|
|
67
67
|
if (tsvector)
|
|
68
|
-
operatorFactories.push(createMatchesOperatorFactory(fullTextScalarName, tsConfig));
|
|
68
|
+
operatorFactories.push(createMatchesOperatorFactory(fullTextScalarName, typeof tsvector === 'object' ? tsvector.tsConfig ?? tsConfig : tsConfig));
|
|
69
69
|
if (trgm)
|
|
70
70
|
operatorFactories.push(createTrgmOperatorFactories());
|
|
71
71
|
return {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SearchableColumn } from './types';
|
|
2
|
+
export declare const REQUEST_TS_CONFIG = "__graphile_search_ts_config";
|
|
3
|
+
export declare function requestTsConfig(langCodes: unknown): string;
|
|
4
|
+
export declare function conditionTsConfig(condition: any): string | undefined;
|
|
5
|
+
export declare function columnWithRequestTsConfig(column: SearchableColumn, condition: any): SearchableColumn;
|
package/esm/ts-config.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const REQUEST_TS_CONFIG = '__graphile_search_ts_config';
|
|
2
|
+
const languageConfigs = new Map(Object.entries({
|
|
3
|
+
ar: 'arabic', hy: 'armenian', eu: 'basque', ca: 'catalan', da: 'danish',
|
|
4
|
+
nl: 'dutch', en: 'english', et: 'estonian', fi: 'finnish', fr: 'french',
|
|
5
|
+
de: 'german', el: 'greek', hi: 'hindi', hu: 'hungarian', id: 'indonesian',
|
|
6
|
+
ga: 'irish', it: 'italian', lt: 'lithuanian', ne: 'nepali', no: 'norwegian',
|
|
7
|
+
nb: 'norwegian', nn: 'norwegian', pt: 'portuguese', ro: 'romanian',
|
|
8
|
+
ru: 'russian', sr: 'serbian', es: 'spanish', sv: 'swedish', ta: 'tamil',
|
|
9
|
+
tr: 'turkish', yi: 'yiddish',
|
|
10
|
+
}));
|
|
11
|
+
const configNames = new Set([...languageConfigs.values(), 'simple']);
|
|
12
|
+
export function requestTsConfig(langCodes) {
|
|
13
|
+
if (Array.isArray(langCodes)) {
|
|
14
|
+
for (const code of langCodes) {
|
|
15
|
+
if (typeof code !== 'string')
|
|
16
|
+
continue;
|
|
17
|
+
const normalized = code.toLowerCase();
|
|
18
|
+
const name = configNames.has(normalized) ? normalized : languageConfigs.get(normalized.split('-')[0]);
|
|
19
|
+
if (name)
|
|
20
|
+
return `pg_catalog.${name}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return 'english';
|
|
24
|
+
}
|
|
25
|
+
export function conditionTsConfig(condition) {
|
|
26
|
+
for (let current = condition; current; current = current.parent) {
|
|
27
|
+
const config = current.getMetaRaw?.(REQUEST_TS_CONFIG);
|
|
28
|
+
if (config !== undefined)
|
|
29
|
+
return config;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
export function columnWithRequestTsConfig(column, condition) {
|
|
34
|
+
return {
|
|
35
|
+
...column,
|
|
36
|
+
adapterData: {
|
|
37
|
+
...(column.adapterData && typeof column.adapterData === 'object' ? column.adapterData : {}),
|
|
38
|
+
requestTsConfig: conditionTsConfig(condition),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-search",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.6",
|
|
4
4
|
"description": "Unified PostGraphile v5 search plugin — abstracts tsvector, BM25, pg_trgm, and pgvector behind a single adapter-based architecture with composite searchScore",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/constructive",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"hybrid-search",
|
|
66
66
|
"searchScore"
|
|
67
67
|
],
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "bb542c4fbc549dc8a5cced5214da5141fc480cd3"
|
|
69
69
|
}
|
package/plugin.js
CHANGED
|
@@ -25,6 +25,7 @@ require("graphile-build-pg");
|
|
|
25
25
|
require("graphile-connection-filter");
|
|
26
26
|
const pg_1 = require("@dataplan/pg");
|
|
27
27
|
const graphile_plugin_utils_1 = require("graphile-plugin-utils");
|
|
28
|
+
const ts_config_1 = require("./ts-config");
|
|
28
29
|
/**
|
|
29
30
|
* Carried on a filter field that searches vector columns, for whatever embeds
|
|
30
31
|
* the search text (graphile-llm): which columns, and the model each column's
|
|
@@ -547,6 +548,20 @@ function createUnifiedSearchPlugin(options) {
|
|
|
547
548
|
GraphQLObjectType_fields_field_args_arg(arg, build, context) {
|
|
548
549
|
const { argName, isPgFieldConnection, isPgFieldSimpleCollection, pgFieldResource } = context.scope;
|
|
549
550
|
const { applyPlan } = arg;
|
|
551
|
+
if (argName === (build.options.connectionFilterArgumentName ?? 'where') && applyPlan &&
|
|
552
|
+
(isPgFieldConnection || isPgFieldSimpleCollection)) {
|
|
553
|
+
return {
|
|
554
|
+
...arg,
|
|
555
|
+
applyPlan($parent, $result, input, info) {
|
|
556
|
+
const $select = isPgFieldConnection ? $result.getSubplan() : $result;
|
|
557
|
+
const { context, lambda } = build.grafast;
|
|
558
|
+
$select.apply(lambda(context(), (ctx) => (qb) => {
|
|
559
|
+
qb.setMeta(ts_config_1.REQUEST_TS_CONFIG, (0, ts_config_1.requestTsConfig)(ctx.langCodes));
|
|
560
|
+
}, true));
|
|
561
|
+
return applyPlan($parent, $result, input, info);
|
|
562
|
+
},
|
|
563
|
+
};
|
|
564
|
+
}
|
|
550
565
|
if (argName !== 'orderBy' || !applyPlan || (!isPgFieldConnection && !isPgFieldSimpleCollection))
|
|
551
566
|
return arg;
|
|
552
567
|
const codec = pgFieldResource?.codec;
|
|
@@ -975,7 +990,7 @@ function createUnifiedSearchPlugin(options) {
|
|
|
975
990
|
apply: function plan($condition, val) {
|
|
976
991
|
if (val == null)
|
|
977
992
|
return;
|
|
978
|
-
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, column, val, build);
|
|
993
|
+
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, adapter.name === 'tsv' ? (0, ts_config_1.columnWithRequestTsConfig)(column, $condition) : column, val, build);
|
|
979
994
|
const result = applyFor($condition.alias);
|
|
980
995
|
if (!result)
|
|
981
996
|
return;
|
|
@@ -1050,7 +1065,7 @@ function createUnifiedSearchPlugin(options) {
|
|
|
1050
1065
|
for (const column of columns) {
|
|
1051
1066
|
// Convert text to adapter-specific filter input
|
|
1052
1067
|
const filterInput = adapter.buildTextSearchInput(text);
|
|
1053
|
-
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, column, filterInput, build);
|
|
1068
|
+
const applyFor = (alias) => adapter.buildFilterApply(sql, alias, adapter.name === 'tsv' ? (0, ts_config_1.columnWithRequestTsConfig)(column, $condition) : column, filterInput, build);
|
|
1054
1069
|
const result = applyFor($condition.alias);
|
|
1055
1070
|
if (!result)
|
|
1056
1071
|
continue;
|
package/preset.js
CHANGED
|
@@ -32,11 +32,11 @@ const plugin_1 = require("./plugin");
|
|
|
32
32
|
* Creates a preset that includes the unified search plugin with all enabled adapters.
|
|
33
33
|
*/
|
|
34
34
|
function UnifiedSearchPreset(options = {}) {
|
|
35
|
-
const { tsvector = true, bm25 = true, trgm = true, pgvector = true, enableSearchScore = true, enableUnifiedSearch = true, searchScoreWeights, fullTextScalarName = 'FullText', tsConfig
|
|
35
|
+
const { tsvector = true, bm25 = true, trgm = true, pgvector = true, enableSearchScore = true, enableUnifiedSearch = true, searchScoreWeights, fullTextScalarName = 'FullText', tsConfig, rrfK, } = options;
|
|
36
36
|
const adapters = [];
|
|
37
37
|
if (tsvector) {
|
|
38
38
|
const opts = typeof tsvector === 'object' ? tsvector : {};
|
|
39
|
-
adapters.push((0, tsvector_1.createTsvectorAdapter)(opts));
|
|
39
|
+
adapters.push((0, tsvector_1.createTsvectorAdapter)({ ...opts, tsConfig: opts.tsConfig ?? tsConfig }));
|
|
40
40
|
}
|
|
41
41
|
if (bm25) {
|
|
42
42
|
const opts = typeof bm25 === 'object' ? bm25 : {};
|
|
@@ -68,7 +68,7 @@ function UnifiedSearchPreset(options = {}) {
|
|
|
68
68
|
// Collect operator factories for connection filter integration
|
|
69
69
|
const operatorFactories = [];
|
|
70
70
|
if (tsvector)
|
|
71
|
-
operatorFactories.push((0, operator_factories_1.createMatchesOperatorFactory)(fullTextScalarName, tsConfig));
|
|
71
|
+
operatorFactories.push((0, operator_factories_1.createMatchesOperatorFactory)(fullTextScalarName, typeof tsvector === 'object' ? tsvector.tsConfig ?? tsConfig : tsConfig));
|
|
72
72
|
if (trgm)
|
|
73
73
|
operatorFactories.push((0, operator_factories_1.createTrgmOperatorFactories)());
|
|
74
74
|
return {
|
package/ts-config.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SearchableColumn } from './types';
|
|
2
|
+
export declare const REQUEST_TS_CONFIG = "__graphile_search_ts_config";
|
|
3
|
+
export declare function requestTsConfig(langCodes: unknown): string;
|
|
4
|
+
export declare function conditionTsConfig(condition: any): string | undefined;
|
|
5
|
+
export declare function columnWithRequestTsConfig(column: SearchableColumn, condition: any): SearchableColumn;
|
package/ts-config.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUEST_TS_CONFIG = void 0;
|
|
4
|
+
exports.requestTsConfig = requestTsConfig;
|
|
5
|
+
exports.conditionTsConfig = conditionTsConfig;
|
|
6
|
+
exports.columnWithRequestTsConfig = columnWithRequestTsConfig;
|
|
7
|
+
exports.REQUEST_TS_CONFIG = '__graphile_search_ts_config';
|
|
8
|
+
const languageConfigs = new Map(Object.entries({
|
|
9
|
+
ar: 'arabic', hy: 'armenian', eu: 'basque', ca: 'catalan', da: 'danish',
|
|
10
|
+
nl: 'dutch', en: 'english', et: 'estonian', fi: 'finnish', fr: 'french',
|
|
11
|
+
de: 'german', el: 'greek', hi: 'hindi', hu: 'hungarian', id: 'indonesian',
|
|
12
|
+
ga: 'irish', it: 'italian', lt: 'lithuanian', ne: 'nepali', no: 'norwegian',
|
|
13
|
+
nb: 'norwegian', nn: 'norwegian', pt: 'portuguese', ro: 'romanian',
|
|
14
|
+
ru: 'russian', sr: 'serbian', es: 'spanish', sv: 'swedish', ta: 'tamil',
|
|
15
|
+
tr: 'turkish', yi: 'yiddish',
|
|
16
|
+
}));
|
|
17
|
+
const configNames = new Set([...languageConfigs.values(), 'simple']);
|
|
18
|
+
function requestTsConfig(langCodes) {
|
|
19
|
+
if (Array.isArray(langCodes)) {
|
|
20
|
+
for (const code of langCodes) {
|
|
21
|
+
if (typeof code !== 'string')
|
|
22
|
+
continue;
|
|
23
|
+
const normalized = code.toLowerCase();
|
|
24
|
+
const name = configNames.has(normalized) ? normalized : languageConfigs.get(normalized.split('-')[0]);
|
|
25
|
+
if (name)
|
|
26
|
+
return `pg_catalog.${name}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return 'english';
|
|
30
|
+
}
|
|
31
|
+
function conditionTsConfig(condition) {
|
|
32
|
+
for (let current = condition; current; current = current.parent) {
|
|
33
|
+
const config = current.getMetaRaw?.(exports.REQUEST_TS_CONFIG);
|
|
34
|
+
if (config !== undefined)
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
function columnWithRequestTsConfig(column, condition) {
|
|
40
|
+
return {
|
|
41
|
+
...column,
|
|
42
|
+
adapterData: {
|
|
43
|
+
...(column.adapterData && typeof column.adapterData === 'object' ? column.adapterData : {}),
|
|
44
|
+
requestTsConfig: conditionTsConfig(condition),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|