graphile-search 1.1.0 → 1.1.1
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/adapters/tsvector.js
CHANGED
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createTsvectorAdapter = createTsvectorAdapter;
|
|
10
10
|
function isTsvectorCodec(codec) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// In graphile-build-pg >= 5.0.0-rc.8, the built-in TYPES.tsvector codec
|
|
12
|
+
// has name === 'tsvector' but does NOT have extensions.pg. We need to
|
|
13
|
+
// match both the built-in codec and our custom codec (for older versions).
|
|
14
|
+
return (codec?.name === 'tsvector' ||
|
|
15
|
+
(codec?.extensions?.pg?.schemaName === 'pg_catalog' &&
|
|
16
|
+
codec?.extensions?.pg?.name === 'tsvector'));
|
|
13
17
|
}
|
|
14
18
|
function createTsvectorAdapter(options = {}) {
|
|
15
19
|
const { filterPrefix = 'tsv', tsConfig = 'english' } = options;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
* TsvectorCodecPlugin
|
|
3
3
|
*
|
|
4
4
|
* Teaches PostGraphile v5 how to handle PostgreSQL's tsvector and tsquery types.
|
|
5
|
-
* Without this, tsvector columns are invisible to the schema builder and the
|
|
6
|
-
* search plugin cannot generate condition fields.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
6
|
+
* In graphile-build-pg >= 5.0.0-rc.8, tsvector/tsquery codecs are handled
|
|
7
|
+
* natively and tsvector columns are HIDDEN by default (PgAttributesPlugin
|
|
8
|
+
* HIDE_BY_DEFAULT). This plugin:
|
|
9
|
+
*
|
|
9
10
|
* 1. Creates codecs for tsvector/tsquery via gather.hooks.pgCodecs_findPgCodec
|
|
11
|
+
* (kept for backward compatibility with older versions; rc.8+ handles this
|
|
12
|
+
* natively so the hook returns early when event.pgCodec is already set)
|
|
10
13
|
* 2. Registers a custom "FullText" scalar type for tsvector columns
|
|
11
14
|
* 3. Maps tsvector codec to the FullText scalar (isolating filter operators)
|
|
12
15
|
* 4. Maps tsquery codec to GraphQL String
|
|
13
|
-
* 5.
|
|
16
|
+
* 5. Re-enables tsvector columns for select/filterBy so that search plugins
|
|
17
|
+
* can detect and use them (overrides rc.8's HIDE_BY_DEFAULT)
|
|
18
|
+
* 6. Optionally hides tsvector columns from output types
|
|
14
19
|
*/
|
|
15
20
|
import type { GraphileConfig } from 'graphile-config';
|
|
16
21
|
/**
|
package/codecs/tsvector-codec.js
CHANGED
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
* TsvectorCodecPlugin
|
|
4
4
|
*
|
|
5
5
|
* Teaches PostGraphile v5 how to handle PostgreSQL's tsvector and tsquery types.
|
|
6
|
-
* Without this, tsvector columns are invisible to the schema builder and the
|
|
7
|
-
* search plugin cannot generate condition fields.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
7
|
+
* In graphile-build-pg >= 5.0.0-rc.8, tsvector/tsquery codecs are handled
|
|
8
|
+
* natively and tsvector columns are HIDDEN by default (PgAttributesPlugin
|
|
9
|
+
* HIDE_BY_DEFAULT). This plugin:
|
|
10
|
+
*
|
|
10
11
|
* 1. Creates codecs for tsvector/tsquery via gather.hooks.pgCodecs_findPgCodec
|
|
12
|
+
* (kept for backward compatibility with older versions; rc.8+ handles this
|
|
13
|
+
* natively so the hook returns early when event.pgCodec is already set)
|
|
11
14
|
* 2. Registers a custom "FullText" scalar type for tsvector columns
|
|
12
15
|
* 3. Maps tsvector codec to the FullText scalar (isolating filter operators)
|
|
13
16
|
* 4. Maps tsquery codec to GraphQL String
|
|
14
|
-
* 5.
|
|
17
|
+
* 5. Re-enables tsvector columns for select/filterBy so that search plugins
|
|
18
|
+
* can detect and use them (overrides rc.8's HIDE_BY_DEFAULT)
|
|
19
|
+
* 6. Optionally hides tsvector columns from output types
|
|
15
20
|
*/
|
|
16
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -130,25 +135,41 @@ function createTsvectorCodecPlugin(options = {}) {
|
|
|
130
135
|
},
|
|
131
136
|
},
|
|
132
137
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
// In graphile-build-pg >= 5.0.0-rc.8, PgAttributesPlugin HIDE_BY_DEFAULT
|
|
139
|
+
// hides tsvector columns entirely (-attribute:select, -attribute:base,
|
|
140
|
+
// -condition:attribute:filterBy, etc.). We need entity behavior to
|
|
141
|
+
// re-enable them so search plugins can detect and use them.
|
|
142
|
+
entityBehavior: {
|
|
143
|
+
pgCodecAttribute: {
|
|
144
|
+
inferred: {
|
|
145
|
+
after: ['default'],
|
|
146
|
+
provides: ['tsvectorCodecPlugin'],
|
|
147
|
+
callback(behavior, [codec, attributeName]) {
|
|
148
|
+
const attr = codec.attributes?.[attributeName];
|
|
149
|
+
const attrCodec = attr?.codec;
|
|
150
|
+
const isTsvector = attrCodec?.name === 'tsvector' ||
|
|
151
|
+
(attrCodec?.extensions?.pg?.schemaName === 'pg_catalog' &&
|
|
152
|
+
attrCodec?.extensions?.pg?.name === 'tsvector');
|
|
153
|
+
if (!isTsvector) {
|
|
154
|
+
return behavior;
|
|
155
|
+
}
|
|
156
|
+
if (hideTsvectorColumns) {
|
|
157
|
+
// User explicitly wants tsvector columns hidden from output
|
|
158
|
+
return [behavior, '-attribute:select'];
|
|
159
|
+
}
|
|
160
|
+
// Re-enable tsvector columns that rc.8 hides by default.
|
|
161
|
+
// The search plugin needs attribute:select to detect columns,
|
|
162
|
+
// and condition:attribute:filterBy for standard filter support.
|
|
163
|
+
return [
|
|
164
|
+
behavior,
|
|
165
|
+
'attribute:select',
|
|
166
|
+
'attribute:base',
|
|
167
|
+
'condition:attribute:filterBy',
|
|
168
|
+
];
|
|
148
169
|
},
|
|
149
170
|
},
|
|
150
|
-
}
|
|
151
|
-
|
|
171
|
+
},
|
|
172
|
+
},
|
|
152
173
|
},
|
|
153
174
|
};
|
|
154
175
|
}
|
package/esm/adapters/tsvector.js
CHANGED
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
* Wraps the same SQL logic as graphile-tsvector but as a SearchAdapter.
|
|
6
6
|
*/
|
|
7
7
|
function isTsvectorCodec(codec) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// In graphile-build-pg >= 5.0.0-rc.8, the built-in TYPES.tsvector codec
|
|
9
|
+
// has name === 'tsvector' but does NOT have extensions.pg. We need to
|
|
10
|
+
// match both the built-in codec and our custom codec (for older versions).
|
|
11
|
+
return (codec?.name === 'tsvector' ||
|
|
12
|
+
(codec?.extensions?.pg?.schemaName === 'pg_catalog' &&
|
|
13
|
+
codec?.extensions?.pg?.name === 'tsvector'));
|
|
10
14
|
}
|
|
11
15
|
export function createTsvectorAdapter(options = {}) {
|
|
12
16
|
const { filterPrefix = 'tsv', tsConfig = 'english' } = options;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
* TsvectorCodecPlugin
|
|
3
3
|
*
|
|
4
4
|
* Teaches PostGraphile v5 how to handle PostgreSQL's tsvector and tsquery types.
|
|
5
|
-
* Without this, tsvector columns are invisible to the schema builder and the
|
|
6
|
-
* search plugin cannot generate condition fields.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
6
|
+
* In graphile-build-pg >= 5.0.0-rc.8, tsvector/tsquery codecs are handled
|
|
7
|
+
* natively and tsvector columns are HIDDEN by default (PgAttributesPlugin
|
|
8
|
+
* HIDE_BY_DEFAULT). This plugin:
|
|
9
|
+
*
|
|
9
10
|
* 1. Creates codecs for tsvector/tsquery via gather.hooks.pgCodecs_findPgCodec
|
|
11
|
+
* (kept for backward compatibility with older versions; rc.8+ handles this
|
|
12
|
+
* natively so the hook returns early when event.pgCodec is already set)
|
|
10
13
|
* 2. Registers a custom "FullText" scalar type for tsvector columns
|
|
11
14
|
* 3. Maps tsvector codec to the FullText scalar (isolating filter operators)
|
|
12
15
|
* 4. Maps tsquery codec to GraphQL String
|
|
13
|
-
* 5.
|
|
16
|
+
* 5. Re-enables tsvector columns for select/filterBy so that search plugins
|
|
17
|
+
* can detect and use them (overrides rc.8's HIDE_BY_DEFAULT)
|
|
18
|
+
* 6. Optionally hides tsvector columns from output types
|
|
14
19
|
*/
|
|
15
20
|
import type { GraphileConfig } from 'graphile-config';
|
|
16
21
|
/**
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
* TsvectorCodecPlugin
|
|
3
3
|
*
|
|
4
4
|
* Teaches PostGraphile v5 how to handle PostgreSQL's tsvector and tsquery types.
|
|
5
|
-
* Without this, tsvector columns are invisible to the schema builder and the
|
|
6
|
-
* search plugin cannot generate condition fields.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
6
|
+
* In graphile-build-pg >= 5.0.0-rc.8, tsvector/tsquery codecs are handled
|
|
7
|
+
* natively and tsvector columns are HIDDEN by default (PgAttributesPlugin
|
|
8
|
+
* HIDE_BY_DEFAULT). This plugin:
|
|
9
|
+
*
|
|
9
10
|
* 1. Creates codecs for tsvector/tsquery via gather.hooks.pgCodecs_findPgCodec
|
|
11
|
+
* (kept for backward compatibility with older versions; rc.8+ handles this
|
|
12
|
+
* natively so the hook returns early when event.pgCodec is already set)
|
|
10
13
|
* 2. Registers a custom "FullText" scalar type for tsvector columns
|
|
11
14
|
* 3. Maps tsvector codec to the FullText scalar (isolating filter operators)
|
|
12
15
|
* 4. Maps tsquery codec to GraphQL String
|
|
13
|
-
* 5.
|
|
16
|
+
* 5. Re-enables tsvector columns for select/filterBy so that search plugins
|
|
17
|
+
* can detect and use them (overrides rc.8's HIDE_BY_DEFAULT)
|
|
18
|
+
* 6. Optionally hides tsvector columns from output types
|
|
14
19
|
*/
|
|
15
20
|
import { GraphQLString } from 'graphql';
|
|
16
21
|
import sql from 'pg-sql2';
|
|
@@ -123,25 +128,41 @@ export function createTsvectorCodecPlugin(options = {}) {
|
|
|
123
128
|
},
|
|
124
129
|
},
|
|
125
130
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
// In graphile-build-pg >= 5.0.0-rc.8, PgAttributesPlugin HIDE_BY_DEFAULT
|
|
132
|
+
// hides tsvector columns entirely (-attribute:select, -attribute:base,
|
|
133
|
+
// -condition:attribute:filterBy, etc.). We need entity behavior to
|
|
134
|
+
// re-enable them so search plugins can detect and use them.
|
|
135
|
+
entityBehavior: {
|
|
136
|
+
pgCodecAttribute: {
|
|
137
|
+
inferred: {
|
|
138
|
+
after: ['default'],
|
|
139
|
+
provides: ['tsvectorCodecPlugin'],
|
|
140
|
+
callback(behavior, [codec, attributeName]) {
|
|
141
|
+
const attr = codec.attributes?.[attributeName];
|
|
142
|
+
const attrCodec = attr?.codec;
|
|
143
|
+
const isTsvector = attrCodec?.name === 'tsvector' ||
|
|
144
|
+
(attrCodec?.extensions?.pg?.schemaName === 'pg_catalog' &&
|
|
145
|
+
attrCodec?.extensions?.pg?.name === 'tsvector');
|
|
146
|
+
if (!isTsvector) {
|
|
147
|
+
return behavior;
|
|
148
|
+
}
|
|
149
|
+
if (hideTsvectorColumns) {
|
|
150
|
+
// User explicitly wants tsvector columns hidden from output
|
|
151
|
+
return [behavior, '-attribute:select'];
|
|
152
|
+
}
|
|
153
|
+
// Re-enable tsvector columns that rc.8 hides by default.
|
|
154
|
+
// The search plugin needs attribute:select to detect columns,
|
|
155
|
+
// and condition:attribute:filterBy for standard filter support.
|
|
156
|
+
return [
|
|
157
|
+
behavior,
|
|
158
|
+
'attribute:select',
|
|
159
|
+
'attribute:base',
|
|
160
|
+
'condition:attribute:filterBy',
|
|
161
|
+
];
|
|
141
162
|
},
|
|
142
163
|
},
|
|
143
|
-
}
|
|
144
|
-
|
|
164
|
+
},
|
|
165
|
+
},
|
|
145
166
|
},
|
|
146
167
|
};
|
|
147
168
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-search",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^22.19.11",
|
|
33
33
|
"@types/pg": "^8.18.0",
|
|
34
|
-
"graphile-connection-filter": "^1.1.
|
|
35
|
-
"graphile-test": "^4.5.
|
|
34
|
+
"graphile-connection-filter": "^1.1.1",
|
|
35
|
+
"graphile-test": "^4.5.3",
|
|
36
36
|
"makage": "^0.1.10",
|
|
37
|
-
"pg": "^8.
|
|
38
|
-
"pgsql-test": "^4.5.
|
|
37
|
+
"pg": "^8.20.0",
|
|
38
|
+
"pgsql-test": "^4.5.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@dataplan/pg": "1.0.0-rc.
|
|
42
|
-
"graphile-build": "5.0.0-rc.
|
|
43
|
-
"graphile-build-pg": "5.0.0-rc.
|
|
44
|
-
"graphile-config": "1.0.0-rc.
|
|
45
|
-
"graphql": "
|
|
46
|
-
"pg-sql2": "5.0.0-rc.
|
|
47
|
-
"postgraphile": "5.0.0-rc.
|
|
41
|
+
"@dataplan/pg": "1.0.0-rc.8",
|
|
42
|
+
"graphile-build": "5.0.0-rc.6",
|
|
43
|
+
"graphile-build-pg": "5.0.0-rc.8",
|
|
44
|
+
"graphile-config": "1.0.0-rc.6",
|
|
45
|
+
"graphql": "16.13.0",
|
|
46
|
+
"pg-sql2": "5.0.0-rc.5",
|
|
47
|
+
"postgraphile": "5.0.0-rc.10"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"postgraphile",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"hybrid-search",
|
|
63
63
|
"searchScore"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "21fd7c2c30663548cf15aa448c1935ab56e5497d"
|
|
66
66
|
}
|