@rubixstudios/payload-typesense 1.7.0 → 1.8.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/README.md +55 -16
- package/dist/components/ThemeProvider.d.ts +3 -2
- package/dist/components/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider.js +8 -0
- package/dist/components/icons/index.d.ts +1 -0
- package/dist/components/icons/index.d.ts.map +1 -1
- package/dist/components/icons/index.js +1 -0
- package/dist/components/icons/noResultsIcon.d.ts +2 -4
- package/dist/components/icons/noResultsIcon.d.ts.map +1 -1
- package/dist/components/icons/searchIcon.d.ts +2 -4
- package/dist/components/icons/searchIcon.d.ts.map +1 -1
- package/dist/components/icons/xIcon.d.ts +2 -0
- package/dist/components/icons/xIcon.d.ts.map +1 -0
- package/dist/components/icons/xIcon.js +17 -0
- package/dist/components/index.d.ts +9 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +5 -3
- package/dist/components/render/Content.d.ts +26 -0
- package/dist/components/render/Content.d.ts.map +1 -0
- package/dist/components/render/Content.js +144 -0
- package/dist/components/render/Dialog.d.ts +20 -0
- package/dist/components/render/Dialog.d.ts.map +1 -0
- package/dist/components/render/Dialog.js +43 -0
- package/dist/components/render/Header.d.ts +2 -2
- package/dist/components/render/Header.d.ts.map +1 -1
- package/dist/components/render/Header.js +17 -39
- package/dist/components/render/Highlight.d.ts +3 -0
- package/dist/components/render/Highlight.d.ts.map +1 -0
- package/dist/components/render/Highlight.js +22 -0
- package/dist/components/render/NoResults.d.ts +2 -2
- package/dist/components/render/NoResults.d.ts.map +1 -1
- package/dist/components/render/NoResults.js +18 -39
- package/dist/components/render/ResultError.d.ts +2 -2
- package/dist/components/render/ResultError.d.ts.map +1 -1
- package/dist/components/render/ResultError.js +7 -32
- package/dist/components/render/Results.d.ts +7 -6
- package/dist/components/render/Results.d.ts.map +1 -1
- package/dist/components/render/Results.js +34 -109
- package/dist/components/render/index.d.ts +7 -4
- package/dist/components/render/index.d.ts.map +1 -1
- package/dist/components/render/index.js +7 -4
- package/dist/components/search/HeadlessDialog.d.ts +5 -0
- package/dist/components/search/HeadlessDialog.d.ts.map +1 -0
- package/dist/components/search/HeadlessDialog.js +254 -0
- package/dist/components/search/HeadlessInput.d.ts +5 -0
- package/dist/components/search/HeadlessInput.d.ts.map +1 -0
- package/dist/components/search/HeadlessInput.js +193 -0
- package/dist/components/search/SearchStyles.d.ts +8 -0
- package/dist/components/search/SearchStyles.d.ts.map +1 -0
- package/dist/components/search/SearchStyles.js +9 -0
- package/dist/components/themes/constant.d.ts +3 -0
- package/dist/components/themes/constant.d.ts.map +1 -0
- package/dist/components/themes/constant.js +75 -0
- package/dist/components/themes/hooks.d.ts +4 -4
- package/dist/components/themes/hooks.d.ts.map +1 -1
- package/dist/components/themes/hooks.js +15 -26
- package/dist/components/themes/index.d.ts +1 -0
- package/dist/components/themes/index.d.ts.map +1 -1
- package/dist/components/themes/index.js +1 -0
- package/dist/components/themes/themes.d.ts.map +1 -1
- package/dist/components/themes/themes.js +50 -7
- package/dist/components/themes/types.d.ts +62 -2
- package/dist/components/themes/types.d.ts.map +1 -1
- package/dist/components/themes/utils.d.ts +11 -4
- package/dist/components/themes/utils.d.ts.map +1 -1
- package/dist/components/themes/utils.js +450 -315
- package/dist/components/utils/decodeEntities.d.ts +2 -0
- package/dist/components/utils/decodeEntities.d.ts.map +1 -0
- package/dist/components/utils/decodeEntities.js +23 -0
- package/dist/components/utils/index.d.ts +4 -0
- package/dist/components/utils/index.d.ts.map +1 -0
- package/dist/components/utils/index.js +3 -0
- package/dist/components/utils/toKebab.d.ts +2 -0
- package/dist/components/utils/toKebab.d.ts.map +1 -0
- package/dist/components/utils/toKebab.js +3 -0
- package/dist/components/utils/toText.d.ts +2 -0
- package/dist/components/utils/toText.d.ts.map +1 -0
- package/dist/components/utils/toText.js +3 -0
- package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createAdvancedSearch.js +63 -5
- package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createSearch.js +73 -106
- package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
- package/dist/endpoints/handler/createSuggest.js +27 -25
- package/dist/endpoints/search.d.ts +1 -1
- package/dist/endpoints/search.d.ts.map +1 -1
- package/dist/endpoints/search.js +1 -1
- package/dist/hooks/useSearch.d.ts +8 -5
- package/dist/hooks/useSearch.d.ts.map +1 -1
- package/dist/hooks/useSearch.js +53 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +5 -2
- package/dist/lib/initialization.d.ts +1 -1
- package/dist/lib/initialization.d.ts.map +1 -1
- package/dist/lib/initialization.js +8 -8
- package/dist/lib/schema-mapper.d.ts +1 -1
- package/dist/lib/schema-mapper.d.ts.map +1 -1
- package/dist/lib/schema-mapper.js +16 -8
- package/dist/lib/search-dialog.d.ts +169 -0
- package/dist/lib/search-dialog.d.ts.map +1 -0
- package/dist/lib/search-dialog.js +4 -0
- package/dist/lib/{headlessSearch.d.ts → search-input.d.ts} +6 -3
- package/dist/lib/search-input.d.ts.map +1 -0
- package/dist/lib/search-pagination.d.ts +38 -0
- package/dist/lib/search-pagination.d.ts.map +1 -0
- package/dist/lib/search-pagination.js +4 -0
- package/dist/lib/search.d.ts +25 -0
- package/dist/lib/search.d.ts.map +1 -0
- package/dist/lib/search.js +59 -0
- package/dist/lib/validation.d.ts +36 -10
- package/dist/lib/validation.d.ts.map +1 -1
- package/dist/lib/validation.js +54 -18
- package/dist/types.d.ts +42 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/ensureCollection.d.ts +1 -1
- package/dist/utils/ensureCollection.d.ts.map +1 -1
- package/dist/utils/ensureCollection.js +58 -22
- package/dist/utils/getCollectionInfo.d.ts.map +1 -1
- package/dist/utils/getCollections.d.ts +2 -2
- package/dist/utils/getCollections.d.ts.map +1 -1
- package/dist/utils/getCollections.js +32 -20
- package/dist/utils/keyboard.js +6 -6
- package/dist/utils/sortResults.d.ts +2 -2
- package/dist/utils/sortResults.d.ts.map +1 -1
- package/dist/utils/sortResults.js +90 -60
- package/dist/utils/testConnection.d.ts +1 -1
- package/dist/utils/testConnection.d.ts.map +1 -1
- package/dist/utils/testConnection.js +2 -2
- package/dist/utils/vectorSearch.d.ts +2 -6
- package/dist/utils/vectorSearch.d.ts.map +1 -1
- package/dist/utils/vectorSearch.js +20 -10
- package/package.json +15 -14
- package/dist/components/HeadlessSearchInput.d.ts +0 -5
- package/dist/components/HeadlessSearchInput.d.ts.map +0 -1
- package/dist/components/HeadlessSearchInput.js +0 -237
- package/dist/lib/headlessSearch.d.ts.map +0 -1
- /package/dist/lib/{headlessSearch.js → search-input.js} +0 -0
package/dist/hooks/useSearch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
-
export function useSearch({ baseUrl, collections, minQueryLength, onResults, onSearch, perPage, vector = false }) {
|
|
3
|
+
export function useSearch({ baseUrl, collections, enabled = true, minQueryLength, onResults, onSearch, perPage, searchMode, numTypos, vector = false }) {
|
|
4
4
|
const [results, setResults] = useState(null);
|
|
5
5
|
const [isLoading, setIsLoading] = useState(false);
|
|
6
6
|
const [error, setError] = useState(null);
|
|
@@ -16,19 +16,29 @@ export function useSearch({ baseUrl, collections, minQueryLength, onResults, onS
|
|
|
16
16
|
onResults,
|
|
17
17
|
onSearch
|
|
18
18
|
]);
|
|
19
|
+
const reset = useCallback(()=>{
|
|
20
|
+
requestRef.current?.abort();
|
|
21
|
+
requestRef.current = null;
|
|
22
|
+
setResults(null);
|
|
23
|
+
setIsLoading(false);
|
|
24
|
+
setError(null);
|
|
25
|
+
}, []);
|
|
19
26
|
useEffect(()=>{
|
|
20
|
-
|
|
27
|
+
if (!enabled) reset();
|
|
28
|
+
}, [
|
|
29
|
+
enabled,
|
|
30
|
+
reset
|
|
31
|
+
]);
|
|
32
|
+
useEffect(()=>()=>{
|
|
21
33
|
requestRef.current?.abort();
|
|
22
34
|
requestRef.current = null;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const search = useCallback(async (searchQuery)=>{
|
|
35
|
+
}, []);
|
|
36
|
+
const search = useCallback(async (searchQuery, page = 1)=>{
|
|
26
37
|
requestRef.current?.abort();
|
|
27
38
|
requestRef.current = null;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
setError(null);
|
|
39
|
+
const query = searchQuery.trim();
|
|
40
|
+
if (!enabled || query.length < minQueryLength) {
|
|
41
|
+
reset();
|
|
32
42
|
return;
|
|
33
43
|
}
|
|
34
44
|
const controller = new AbortController();
|
|
@@ -38,32 +48,50 @@ export function useSearch({ baseUrl, collections, minQueryLength, onResults, onS
|
|
|
38
48
|
try {
|
|
39
49
|
const params = new URLSearchParams({
|
|
40
50
|
per_page: String(perPage),
|
|
41
|
-
|
|
51
|
+
page: String(page),
|
|
52
|
+
q: query
|
|
42
53
|
});
|
|
43
|
-
if (
|
|
54
|
+
if (searchMode) {
|
|
55
|
+
params.set('search_mode', searchMode);
|
|
56
|
+
} else if (vector) {
|
|
44
57
|
params.set('vector', 'true');
|
|
45
58
|
}
|
|
59
|
+
if (numTypos !== undefined) {
|
|
60
|
+
params.set('num_typos', String(numTypos));
|
|
61
|
+
}
|
|
46
62
|
if (collectionList) {
|
|
47
63
|
params.set('collections', collectionList);
|
|
48
64
|
}
|
|
49
|
-
let
|
|
50
|
-
while(
|
|
51
|
-
|
|
65
|
+
let end = baseUrl.length;
|
|
66
|
+
while(end > 0 && baseUrl[end - 1] === '/'){
|
|
67
|
+
end--;
|
|
52
68
|
}
|
|
69
|
+
const url = baseUrl.slice(0, end);
|
|
53
70
|
const path = collection ? `/api/search/${encodeURIComponent(collection)}` : '/api/search';
|
|
54
|
-
const response = await fetch(`${url}${path}?${params
|
|
71
|
+
const response = await fetch(`${url}${path}?${params}`, {
|
|
55
72
|
signal: controller.signal
|
|
56
73
|
});
|
|
57
74
|
if (!response.ok) {
|
|
58
|
-
|
|
75
|
+
let message = `Search failed (${response.status})`;
|
|
76
|
+
try {
|
|
77
|
+
const body = await response.json();
|
|
78
|
+
if (typeof body.error === 'string') {
|
|
79
|
+
message = body.error;
|
|
80
|
+
}
|
|
81
|
+
if (typeof body.details === 'string') {
|
|
82
|
+
message += ` (${body.details})`;
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
/* Keep the HTTP status when the response is not JSON. */ }
|
|
86
|
+
throw new Error(message);
|
|
59
87
|
}
|
|
60
88
|
const data = await response.json();
|
|
61
|
-
if (requestRef.current !== controller) {
|
|
89
|
+
if (requestRef.current !== controller || controller.signal.aborted) {
|
|
62
90
|
return;
|
|
63
91
|
}
|
|
64
92
|
setResults(data);
|
|
65
93
|
onResultsRef.current?.(data);
|
|
66
|
-
onSearchRef.current?.(
|
|
94
|
+
onSearchRef.current?.(query, data);
|
|
67
95
|
} catch (err) {
|
|
68
96
|
if (controller.signal.aborted || requestRef.current !== controller) {
|
|
69
97
|
return;
|
|
@@ -80,14 +108,19 @@ export function useSearch({ baseUrl, collections, minQueryLength, onResults, onS
|
|
|
80
108
|
baseUrl,
|
|
81
109
|
collection,
|
|
82
110
|
collectionList,
|
|
111
|
+
enabled,
|
|
83
112
|
minQueryLength,
|
|
84
113
|
perPage,
|
|
85
|
-
|
|
114
|
+
searchMode,
|
|
115
|
+
numTypos,
|
|
116
|
+
vector,
|
|
117
|
+
reset
|
|
86
118
|
]);
|
|
87
119
|
return {
|
|
88
120
|
error,
|
|
89
121
|
isLoading,
|
|
90
122
|
results,
|
|
91
|
-
search
|
|
123
|
+
search,
|
|
124
|
+
reset
|
|
92
125
|
};
|
|
93
126
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AAOrC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,cAAc,uBAAuB,CAAA;AACrC,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,eAAO,MAAM,eAAe,iBACX,eAAe,sBACb,MAAM,KAAG,MAsDzB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEndpoints } from './endpoints/search.js';
|
|
2
2
|
import { createClient } from './lib/client.js';
|
|
3
3
|
import { deleteDoc, syncDoc } from './lib/hooks.js';
|
|
4
4
|
import { initializeTypesense } from './lib/initialization.js';
|
|
5
|
+
import { getErrors, validateConfig } from './lib/validation.js';
|
|
5
6
|
export * from './components/index.js';
|
|
6
7
|
export const typesenseSearch = (pluginConfig)=>(incomingConfig)=>{
|
|
7
8
|
if (pluginConfig.disabled) return incomingConfig;
|
|
9
|
+
const validate = validateConfig(pluginConfig);
|
|
10
|
+
if (!validate.success) {
|
|
11
|
+
throw new Error(`Invalid configuration\n${getErrors(validate.errors ?? [])}`);
|
|
12
|
+
}
|
|
8
13
|
const client = createClient(pluginConfig.typesense);
|
|
9
14
|
const sync = pluginConfig.settings?.autoSync !== false;
|
|
10
|
-
const existingOnInit = incomingConfig.onInit;
|
|
11
15
|
const collections = incomingConfig.collections?.map((collection)=>{
|
|
12
16
|
const config = pluginConfig.collections?.[collection.slug];
|
|
13
17
|
if (!sync || !config?.enabled) {
|
|
@@ -32,16 +36,17 @@ export const typesenseSearch = (pluginConfig)=>(incomingConfig)=>{
|
|
|
32
36
|
}
|
|
33
37
|
};
|
|
34
38
|
});
|
|
39
|
+
const existing = incomingConfig.onInit;
|
|
35
40
|
return {
|
|
36
41
|
...incomingConfig,
|
|
37
42
|
collections,
|
|
38
43
|
endpoints: [
|
|
39
44
|
...incomingConfig.endpoints || [],
|
|
40
|
-
...
|
|
45
|
+
...createEndpoints(client, pluginConfig)
|
|
41
46
|
],
|
|
42
47
|
onInit: async (payload)=>{
|
|
43
|
-
if (
|
|
44
|
-
await
|
|
48
|
+
if (existing) {
|
|
49
|
+
await existing(payload);
|
|
45
50
|
}
|
|
46
51
|
await initializeTypesense(payload, client, pluginConfig);
|
|
47
52
|
}
|
package/dist/lib/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/lib/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACrB,MAAM,aAAa,CAAA;AAIpB,eAAO,MAAM,OAAO,WACV,SAAS,CAAC,MAAM,QAClB,MAAM,OACP,YAAY,UACT,yBAAyB,WACxB,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,KACpD,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/lib/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACrB,MAAM,aAAa,CAAA;AAIpB,eAAO,MAAM,OAAO,WACV,SAAS,CAAC,MAAM,QAClB,MAAM,OACP,YAAY,UACT,yBAAyB,WACxB,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,KACpD,OAAO,CAAC,IAAI,CAkBd,CAAA;AAED,eAAO,MAAM,SAAS,WACZ,SAAS,CAAC,MAAM,QAClB,MAAM,MACR,MAAM,KACT,OAAO,CAAC,IAAI,CAMd,CAAA"}
|
package/dist/lib/hooks.js
CHANGED
|
@@ -2,8 +2,11 @@ import { ensureCollection } from '../utils/ensureCollection.js';
|
|
|
2
2
|
import { mapCollection, mapDoc } from './schema-mapper.js';
|
|
3
3
|
export const syncDoc = async (client, slug, doc, config, vector)=>{
|
|
4
4
|
try {
|
|
5
|
-
const document = mapDoc(doc, slug, config);
|
|
6
|
-
if (!document)
|
|
5
|
+
const document = mapDoc(doc, slug, config, vector);
|
|
6
|
+
if (!document) {
|
|
7
|
+
await deleteDoc(client, slug, String(doc.id));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
7
10
|
const schema = mapCollection(slug, config, vector);
|
|
8
11
|
const { available } = await ensureCollection(client, slug, schema, vector);
|
|
9
12
|
if (!available) return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Payload } from 'payload';
|
|
2
2
|
import type Typesense from 'typesense';
|
|
3
3
|
import { type TypesenseConfig } from '../types.js';
|
|
4
|
-
export declare
|
|
4
|
+
export declare function initializeTypesense(payload: Payload, client: Typesense.Client, options: TypesenseConfig): Promise<void>;
|
|
5
5
|
//# sourceMappingURL=initialization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialization.d.ts","sourceRoot":"","sources":["../../src/lib/initialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAA;AAKpB,
|
|
1
|
+
{"version":3,"file":"initialization.d.ts","sourceRoot":"","sources":["../../src/lib/initialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAA;AAKpB,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,SAAS,CAAC,MAAM,EACxB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ensureCollection } from '../utils/ensureCollection.js';
|
|
2
2
|
import { testConnection } from '../utils/testConnection.js';
|
|
3
3
|
import { mapCollection, mapDoc } from './schema-mapper.js';
|
|
4
|
-
export
|
|
4
|
+
export async function initializeTypesense(payload, client, options) {
|
|
5
5
|
const connected = await testConnection(client);
|
|
6
6
|
if (!connected) return;
|
|
7
7
|
const vector = options.vectorSearch;
|
|
@@ -10,15 +10,15 @@ export const initializeTypesense = async (payload, client, options)=>{
|
|
|
10
10
|
if (!config?.enabled) continue;
|
|
11
11
|
await initializeCollection(payload, client, slug, config, vector, autoSync);
|
|
12
12
|
}
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
async function initializeCollection(payload, client, slug, config, vector, autoSync = true) {
|
|
15
15
|
if (!payload.collections[slug]) return;
|
|
16
16
|
const schema = mapCollection(slug, config, vector);
|
|
17
17
|
const { available } = await ensureCollection(client, slug, schema, vector, true);
|
|
18
18
|
if (!available || !autoSync) return;
|
|
19
|
-
await
|
|
20
|
-
}
|
|
21
|
-
|
|
19
|
+
await syncExisting(payload, client, slug, config, vector);
|
|
20
|
+
}
|
|
21
|
+
async function syncExisting(payload, client, slug, config, vector) {
|
|
22
22
|
try {
|
|
23
23
|
const limit = config.syncLimit ?? 1000;
|
|
24
24
|
const batchSize = 100;
|
|
@@ -39,7 +39,7 @@ const syncExistingDocuments = async (payload, client, slug, config)=>{
|
|
|
39
39
|
if (!('id' in doc)) return false;
|
|
40
40
|
const id = doc.id;
|
|
41
41
|
return typeof id === 'string' || typeof id === 'number';
|
|
42
|
-
}).map((doc)=>mapDoc(doc, slug, config)).filter((doc)=>doc !== null);
|
|
42
|
+
}).map((doc)=>mapDoc(doc, slug, config, vector)).filter((doc)=>doc !== null);
|
|
43
43
|
if (!mapped.length) continue;
|
|
44
44
|
try {
|
|
45
45
|
await client.collections(slug).documents().import(mapped, {
|
|
@@ -78,4 +78,4 @@ const syncExistingDocuments = async (payload, client, slug, config)=>{
|
|
|
78
78
|
msg: `Failed to synchronize Typesense collection ${slug}`
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type BaseDocument, type CollectionSchema, type TypesenseCollectionConfig, type TypesenseConfig } from '../types.js';
|
|
2
2
|
export declare const mapCollection: (slug: string, config: TypesenseCollectionConfig, vector?: NonNullable<TypesenseConfig['vectorSearch']>) => CollectionSchema;
|
|
3
|
-
export declare const mapDoc: (doc: BaseDocument, _slug: string, config: TypesenseCollectionConfig) => Record<string, number | string> | null;
|
|
3
|
+
export declare const mapDoc: (doc: BaseDocument, _slug: string, config: TypesenseCollectionConfig, vector?: NonNullable<TypesenseConfig['vectorSearch']>) => Record<string, number | string> | null;
|
|
4
4
|
//# sourceMappingURL=schema-mapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-mapper.d.ts","sourceRoot":"","sources":["../../src/lib/schema-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACrB,MAAM,aAAa,CAAA;AAKpB,eAAO,MAAM,aAAa,SAClB,MAAM,UACJ,yBAAyB,WACxB,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,KACpD,
|
|
1
|
+
{"version":3,"file":"schema-mapper.d.ts","sourceRoot":"","sources":["../../src/lib/schema-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACrB,MAAM,aAAa,CAAA;AAKpB,eAAO,MAAM,aAAa,SAClB,MAAM,UACJ,yBAAyB,WACxB,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,KACpD,gBAgEF,CAAA;AAED,eAAO,MAAM,MAAM,QACZ,YAAY,SACV,MAAM,UACL,yBAAyB,WACxB,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,KACpD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,IA+CpC,CAAA"}
|
|
@@ -5,7 +5,8 @@ const defaultSearchFields = [
|
|
|
5
5
|
'description'
|
|
6
6
|
];
|
|
7
7
|
export const mapCollection = (slug, config, vector)=>{
|
|
8
|
-
const searchFields = config.searchFields
|
|
8
|
+
const searchFields = config.searchFields?.length ? config.searchFields : defaultSearchFields;
|
|
9
|
+
const embedFields = vector?.enabled ? vector.embedFrom?.length ? vector.embedFrom : searchFields : [];
|
|
9
10
|
const facetFields = config.facetFields ?? [];
|
|
10
11
|
const sortFields = config.sortFields ?? [];
|
|
11
12
|
const fields = [
|
|
@@ -29,7 +30,8 @@ export const mapCollection = (slug, config, vector)=>{
|
|
|
29
30
|
const configuredFields = new Set([
|
|
30
31
|
...searchFields,
|
|
31
32
|
...facetFields,
|
|
32
|
-
...sortFields
|
|
33
|
+
...sortFields,
|
|
34
|
+
...embedFields
|
|
33
35
|
]);
|
|
34
36
|
const existingFields = new Set(fields.map((field)=>field.name));
|
|
35
37
|
for (const field of configuredFields){
|
|
@@ -42,7 +44,7 @@ export const mapCollection = (slug, config, vector)=>{
|
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
if (vector?.enabled) {
|
|
45
|
-
const embedFromFields =
|
|
47
|
+
const embedFromFields = embedFields;
|
|
46
48
|
const embeddingModel = vector.embeddingModel ?? 'ts/all-MiniLM-L12-v2';
|
|
47
49
|
fields.push({
|
|
48
50
|
name: 'embedding',
|
|
@@ -61,11 +63,16 @@ export const mapCollection = (slug, config, vector)=>{
|
|
|
61
63
|
fields
|
|
62
64
|
};
|
|
63
65
|
};
|
|
64
|
-
export const mapDoc = (doc, _slug, config)=>{
|
|
66
|
+
export const mapDoc = (doc, _slug, config, vector)=>{
|
|
65
67
|
if (doc.id === null || doc.id === undefined || doc.id === '') {
|
|
66
68
|
throw new Error("Document missing required 'id' field");
|
|
67
69
|
}
|
|
68
|
-
const searchFields = config.searchFields
|
|
70
|
+
const searchFields = config.searchFields?.length ? config.searchFields : defaultSearchFields;
|
|
71
|
+
const embedFields = vector?.enabled ? vector.embedFrom?.length ? vector.embedFrom : searchFields : [];
|
|
72
|
+
const searchableFields = new Set([
|
|
73
|
+
...searchFields,
|
|
74
|
+
...embedFields
|
|
75
|
+
]);
|
|
69
76
|
const facetFields = config.facetFields ?? [];
|
|
70
77
|
const sortFields = config.sortFields ?? [];
|
|
71
78
|
const createdAt = doc.createdAt ? new Date(doc.createdAt) : new Date();
|
|
@@ -79,18 +86,19 @@ export const mapDoc = (doc, _slug, config)=>{
|
|
|
79
86
|
const fields = new Set([
|
|
80
87
|
...searchFields,
|
|
81
88
|
...facetFields,
|
|
82
|
-
...sortFields
|
|
89
|
+
...sortFields,
|
|
90
|
+
...embedFields
|
|
83
91
|
]);
|
|
84
92
|
let hasSearchableContent = false;
|
|
85
93
|
for (const field of fields){
|
|
86
94
|
if (field === 'slug' || field === 'createdAt' || field === 'updatedAt') {
|
|
87
|
-
if (field === 'slug' &&
|
|
95
|
+
if (field === 'slug' && searchableFields.has(field) && document.slug) {
|
|
88
96
|
hasSearchableContent = true;
|
|
89
97
|
}
|
|
90
98
|
continue;
|
|
91
99
|
}
|
|
92
100
|
const value = getFieldValue(doc, field);
|
|
93
|
-
if (
|
|
101
|
+
if (searchableFields.has(field) && value.trim().length > 0) {
|
|
94
102
|
hasSearchableContent = true;
|
|
95
103
|
}
|
|
96
104
|
document[field] = facetFields.includes(field) ? value || 'unknown' : value;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type DialogHTMLAttributes, type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { type SearchResponse } from '../types.js';
|
|
3
|
+
import { type SearchInputProps } from './search-input.js';
|
|
4
|
+
import { type SearchPaginationProps } from './search-pagination.js';
|
|
5
|
+
/**
|
|
6
|
+
* Search state and default content supplied to a custom dialog content renderer.
|
|
7
|
+
*/
|
|
8
|
+
export type SearchDialogContentProps<T> = {
|
|
9
|
+
/**
|
|
10
|
+
* Default input, search states, results and pagination. Render these to retain the built-in controls.
|
|
11
|
+
*/
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Requests dialog dismissal through the component's open-state handler.
|
|
15
|
+
*/
|
|
16
|
+
close: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Current input query, including changes awaiting the debounce delay.
|
|
19
|
+
*/
|
|
20
|
+
query: string;
|
|
21
|
+
/**
|
|
22
|
+
* Current one-based page number.
|
|
23
|
+
*/
|
|
24
|
+
page: number;
|
|
25
|
+
/**
|
|
26
|
+
* Latest completed search response, or null when no response is available.
|
|
27
|
+
*/
|
|
28
|
+
results: SearchResponse<T> | null;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a search request is currently loading.
|
|
31
|
+
*/
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Current search error message, or null when no error is present.
|
|
35
|
+
*/
|
|
36
|
+
error: string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for a button that opens a modal search dialog.
|
|
40
|
+
*/
|
|
41
|
+
export interface SearchDialogProps<T = Record<string, unknown>> extends Omit<SearchInputProps<T>, 'enableSuggestions' | 'maxResults'> {
|
|
42
|
+
/**
|
|
43
|
+
* Clear the query and reset pagination when the dialog closes. Defaults to false.
|
|
44
|
+
*/
|
|
45
|
+
clearOnClose?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Custom CSS class for the default dialog close button.
|
|
48
|
+
*/
|
|
49
|
+
closeButtonClassName?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Text for the default close button. Defaults to "Close".
|
|
52
|
+
*/
|
|
53
|
+
closeLabel?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Dismiss the dialog when its backdrop is clicked. Defaults to true.
|
|
56
|
+
*/
|
|
57
|
+
closeOnBackdropClick?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Dismiss the dialog after a result is selected. Defaults to true.
|
|
60
|
+
*/
|
|
61
|
+
closeOnResultClick?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Initial open state for an uncontrolled dialog. Defaults to false.
|
|
64
|
+
*/
|
|
65
|
+
defaultOpen?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Custom CSS class for the native dialog element.
|
|
68
|
+
*/
|
|
69
|
+
dialogClassName?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Custom CSS class for the dialog content wrapper.
|
|
72
|
+
*/
|
|
73
|
+
dialogContentClassName?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Custom CSS class for the default dialog header.
|
|
76
|
+
*/
|
|
77
|
+
dialogHeaderClassName?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Accessible dialog name when dialogProps does not provide aria-label.
|
|
80
|
+
*/
|
|
81
|
+
dialogLabel?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Additional native dialog attributes. Open state and dismissal handlers are managed internally.
|
|
84
|
+
*/
|
|
85
|
+
dialogProps?: Omit<DialogHTMLAttributes<HTMLDialogElement>, 'children' | 'open' | 'onCancel' | 'onClose' | 'onClick' | 'onKeyDown'>;
|
|
86
|
+
/**
|
|
87
|
+
* Query used when the component first mounts. Defaults to an empty string.
|
|
88
|
+
*/
|
|
89
|
+
initialQuery?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Text for the default next-page button. Defaults to "Next".
|
|
92
|
+
*/
|
|
93
|
+
nextPageLabel?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Callback when opening or closing is requested.
|
|
96
|
+
* For controlled use, update the open prop in response.
|
|
97
|
+
*/
|
|
98
|
+
onOpenChange?: (open: boolean) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Callback when a different valid page is selected through pagination.
|
|
101
|
+
*/
|
|
102
|
+
onPageChange?: (page: number) => void;
|
|
103
|
+
/**
|
|
104
|
+
* Controlled open state. When omitted, the component manages its own state.
|
|
105
|
+
*/
|
|
106
|
+
open?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Custom CSS class shared by the default pagination buttons.
|
|
109
|
+
*/
|
|
110
|
+
paginationButtonClassName?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Custom CSS class for the default pagination container.
|
|
113
|
+
*/
|
|
114
|
+
paginationClassName?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Text for the default previous-page button. Defaults to "Previous".
|
|
117
|
+
*/
|
|
118
|
+
previousPageLabel?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Custom renderer for dialog content and layout.
|
|
121
|
+
* Receives the default controls as children alongside the current search state.
|
|
122
|
+
*/
|
|
123
|
+
renderDialogContent?: (props: SearchDialogContentProps<T>) => ReactNode;
|
|
124
|
+
/**
|
|
125
|
+
* Custom renderer replacing the default title and close button.
|
|
126
|
+
*/
|
|
127
|
+
renderDialogHeader?: (props: {
|
|
128
|
+
title: ReactNode;
|
|
129
|
+
close: () => void;
|
|
130
|
+
}) => ReactNode;
|
|
131
|
+
/**
|
|
132
|
+
* Custom content when no response or error is available and no request is loading.
|
|
133
|
+
*/
|
|
134
|
+
renderEmpty?: () => ReactNode;
|
|
135
|
+
/**
|
|
136
|
+
* Custom pagination renderer with page state and the page-change handler.
|
|
137
|
+
* Used when pagination is enabled and more than one page exists.
|
|
138
|
+
*/
|
|
139
|
+
renderPagination?: (props: SearchPaginationProps) => ReactNode;
|
|
140
|
+
/**
|
|
141
|
+
* Custom trigger button renderer.
|
|
142
|
+
* Spread the supplied attributes and handlers, including the ref, onto the button.
|
|
143
|
+
*/
|
|
144
|
+
renderTrigger?: (props: ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
145
|
+
ref: RefObject<HTMLButtonElement | null>;
|
|
146
|
+
}) => ReactNode;
|
|
147
|
+
/**
|
|
148
|
+
* Show pagination when the response spans multiple pages. Defaults to true.
|
|
149
|
+
*/
|
|
150
|
+
showPagination?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Content for the default dialog heading. Defaults to "Search".
|
|
153
|
+
*/
|
|
154
|
+
title?: ReactNode;
|
|
155
|
+
/**
|
|
156
|
+
* Custom CSS class for the trigger button.
|
|
157
|
+
*/
|
|
158
|
+
triggerClassName?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Content for the default trigger button. Defaults to "Search".
|
|
161
|
+
*/
|
|
162
|
+
triggerLabel?: ReactNode;
|
|
163
|
+
/**
|
|
164
|
+
* Additional trigger button attributes. Its click handler runs before the dialog opens;
|
|
165
|
+
* preventDefault() cancels opening. The component supplies type="button" and its label.
|
|
166
|
+
*/
|
|
167
|
+
triggerProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'>;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=search-dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-dialog.d.ts","sourceRoot":"","sources":["../../src/lib/search-dialog.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAEnE;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI;IACxC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAA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E,UAAU,CAAC,CAAA;CACzE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ChangeEvent, type FocusEvent, type KeyboardEvent, type ReactNode, type RefObject } from 'react';
|
|
2
2
|
import { type ThemeConfig } from '../components/themes/types.js';
|
|
3
3
|
import { type BaseSearchInputProps, type SearchResult } from '../types.js';
|
|
4
|
-
export interface
|
|
4
|
+
export interface SearchInputProps<T = Record<string, unknown>> extends BaseSearchInputProps<T> {
|
|
5
5
|
/**
|
|
6
6
|
* Collections to search in
|
|
7
7
|
*/
|
|
@@ -31,6 +31,9 @@ export interface HeadlessSearchInputProps<T = Record<string, unknown>> extends B
|
|
|
31
31
|
*/
|
|
32
32
|
renderInput?: (props: {
|
|
33
33
|
className: string;
|
|
34
|
+
'aria-label': string;
|
|
35
|
+
'aria-controls'?: string;
|
|
36
|
+
'aria-busy'?: boolean;
|
|
34
37
|
onBlur: (event: FocusEvent<HTMLInputElement>) => void;
|
|
35
38
|
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
36
39
|
onFocus: () => void;
|
|
@@ -83,8 +86,8 @@ export interface HeadlessSearchInputProps<T = Record<string, unknown>> extends B
|
|
|
83
86
|
*/
|
|
84
87
|
theme?: string | ThemeConfig;
|
|
85
88
|
/**
|
|
86
|
-
*
|
|
89
|
+
* Legacy semantic-only switch. searchMode takes precedence when supplied.
|
|
87
90
|
*/
|
|
88
91
|
vector?: boolean;
|
|
89
92
|
}
|
|
90
|
-
//# sourceMappingURL=
|
|
93
|
+
//# sourceMappingURL=search-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-input.d.ts","sourceRoot":"","sources":["../../src/lib/search-input.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,KAAK,WAAW,EAAE,M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Aa,CAAC,EAAE,MAAM,SAAS,CAAA;IAE/B;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;IAE9C;;OAEG;IACH,YAAY,CAAC,EAAE,CACb,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE;QACR,OAAO,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;QAC1C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;KAC5C,KACE,SAAS,CAAA;IAEd;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;IAElD;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEzB;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAElC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State and navigation supplied to a custom pagination renderer.
|
|
3
|
+
*/
|
|
4
|
+
export type SearchPaginationProps = {
|
|
5
|
+
/**
|
|
6
|
+
* Current one-based page number.
|
|
7
|
+
*/
|
|
8
|
+
page: number;
|
|
9
|
+
/**
|
|
10
|
+
* Number of results requested per page.
|
|
11
|
+
*/
|
|
12
|
+
perPage: number;
|
|
13
|
+
/**
|
|
14
|
+
* Total matches reported by the current search response.
|
|
15
|
+
*/
|
|
16
|
+
found: number;
|
|
17
|
+
/**
|
|
18
|
+
* Number of pages calculated from the match count and page size.
|
|
19
|
+
*/
|
|
20
|
+
totalPages: number;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a search request is currently loading.
|
|
23
|
+
*/
|
|
24
|
+
isLoading: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a page exists before the current page.
|
|
27
|
+
*/
|
|
28
|
+
hasPreviousPage: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a page exists after the current page.
|
|
31
|
+
*/
|
|
32
|
+
hasNextPage: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Requests a different page. Invalid, unchanged or loading-state requests are ignored.
|
|
35
|
+
*/
|
|
36
|
+
onPageChange: (page: number) => void;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=search-pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-pagination.d.ts","sourceRoot":"","sources":["../../src/lib/search-pagination.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,eAAe,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;IAEpB;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CACrC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type SearchParams, type TypesenseConfig } from '../types.js';
|
|
2
|
+
type SearchConfiguration = Pick<TypesenseConfig, 'settings' | 'vectorSearch'>;
|
|
3
|
+
export declare function getSearchMode(config: SearchConfiguration, params?: Partial<SearchParams>): import("../types.js").SearchMode;
|
|
4
|
+
export declare function buildParameters(config: SearchConfiguration, fields: string[], params: SearchParams): {
|
|
5
|
+
q: string;
|
|
6
|
+
query_by: string;
|
|
7
|
+
page: number;
|
|
8
|
+
per_page: number;
|
|
9
|
+
num_typos: number;
|
|
10
|
+
min_len_1typo: number;
|
|
11
|
+
min_len_2typo: number;
|
|
12
|
+
typo_tokens_threshold: number;
|
|
13
|
+
enable_typos_for_numerical_tokens: boolean;
|
|
14
|
+
enable_typos_for_alpha_numerical_tokens: boolean;
|
|
15
|
+
highlight_full_fields?: string | undefined;
|
|
16
|
+
snippet_threshold: number;
|
|
17
|
+
sort_by?: string | undefined;
|
|
18
|
+
vector_query?: string | undefined;
|
|
19
|
+
exclude_fields?: string | undefined;
|
|
20
|
+
search_cutoff_ms?: number | undefined;
|
|
21
|
+
drop_tokens_threshold?: number | undefined;
|
|
22
|
+
};
|
|
23
|
+
export declare function getCollectionName(url: URL): string | undefined;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/lib/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,cAAc,CAAC,CAAA;AAE7E,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,oCAU5F;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,YAAY;;;;;;;;;;;;;;;;;;EA6CrB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAK9D"}
|