@rubixstudios/payload-typesense 1.7.0 → 1.8.0
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 +13 -12
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { searchCache } from '../lib/cache.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { buildParameters, getSearchMode } from '../lib/search.js';
|
|
3
|
+
import { getCompare } from './sortResults.js';
|
|
4
4
|
export const getCollections = async (client, config, query, options)=>{
|
|
5
5
|
try {
|
|
6
6
|
const enabledCollections = Object.entries(config.collections ?? {}).filter(([slug, collection])=>collection.enabled && (!options.collections?.length || options.collections.includes(slug)));
|
|
@@ -12,11 +12,11 @@ export const getCollections = async (client, config, query, options)=>{
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
const multiple = enabledCollections.length > 1;
|
|
15
|
-
const
|
|
15
|
+
const mode = getSearchMode(config, options);
|
|
16
16
|
let compare;
|
|
17
17
|
if (multiple) {
|
|
18
18
|
try {
|
|
19
|
-
compare =
|
|
19
|
+
compare = getCompare(options.sort_by, mode);
|
|
20
20
|
} catch (error) {
|
|
21
21
|
return Response.json({
|
|
22
22
|
error: error instanceof Error ? error.message : 'Invalid sort_by parameter'
|
|
@@ -29,6 +29,17 @@ export const getCollections = async (client, config, query, options)=>{
|
|
|
29
29
|
const perPage = Math.min(limit, 250);
|
|
30
30
|
const cacheKey = {
|
|
31
31
|
...options,
|
|
32
|
+
settings: config.settings,
|
|
33
|
+
vectorSearch: config.vectorSearch && {
|
|
34
|
+
enabled: config.vectorSearch.enabled,
|
|
35
|
+
alpha: config.vectorSearch.alpha,
|
|
36
|
+
k: config.vectorSearch.k,
|
|
37
|
+
distanceThreshold: config.vectorSearch.distanceThreshold
|
|
38
|
+
},
|
|
39
|
+
fields: enabledCollections.map(([slug, collection])=>[
|
|
40
|
+
slug,
|
|
41
|
+
collection.searchFields
|
|
42
|
+
]),
|
|
32
43
|
collections: enabledCollections.map(([slug])=>slug).sort().join(',')
|
|
33
44
|
};
|
|
34
45
|
const cached = searchCache.get(query, 'universal', cacheKey);
|
|
@@ -39,25 +50,18 @@ export const getCollections = async (client, config, query, options)=>{
|
|
|
39
50
|
const displayName = collection.displayName || slug;
|
|
40
51
|
const icon = collection.icon || '📄';
|
|
41
52
|
try {
|
|
42
|
-
const fields = collection.searchFields?.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
highlight_full_fields: fields,
|
|
50
|
-
num_typos: 0,
|
|
53
|
+
const fields = collection.searchFields?.length ? collection.searchFields : [
|
|
54
|
+
'title',
|
|
55
|
+
'content',
|
|
56
|
+
'description'
|
|
57
|
+
];
|
|
58
|
+
const search = (page)=>client.collections(slug).documents().search(buildParameters(config, fields, {
|
|
59
|
+
...options,
|
|
51
60
|
page,
|
|
52
61
|
per_page: perPage,
|
|
53
62
|
q: query,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
typo_tokens_threshold: 1,
|
|
57
|
-
...options.sort_by ? {
|
|
58
|
-
sort_by: options.sort_by
|
|
59
|
-
} : {}
|
|
60
|
-
});
|
|
63
|
+
search_mode: mode
|
|
64
|
+
}));
|
|
61
65
|
let page = multiple ? 1 : options.page;
|
|
62
66
|
const results = await search(page);
|
|
63
67
|
const hits = [
|
|
@@ -101,6 +105,14 @@ export const getCollections = async (client, config, query, options)=>{
|
|
|
101
105
|
}
|
|
102
106
|
});
|
|
103
107
|
const results = await Promise.all(searches);
|
|
108
|
+
if (results.every((result)=>'error' in result)) {
|
|
109
|
+
return Response.json({
|
|
110
|
+
error: 'All collection searches failed',
|
|
111
|
+
collections: results
|
|
112
|
+
}, {
|
|
113
|
+
status: 500
|
|
114
|
+
});
|
|
115
|
+
}
|
|
104
116
|
const hits = results.flatMap((result)=>result.hits);
|
|
105
117
|
const found = results.reduce((total, result)=>total + result.found, 0);
|
|
106
118
|
if (compare) hits.sort(compare);
|
package/dist/utils/keyboard.js
CHANGED
|
@@ -9,28 +9,28 @@ export function handleKeyboard(event, options) {
|
|
|
9
9
|
if (!isOpen || !results) return;
|
|
10
10
|
const items = Array.from(resultsRef.current?.querySelectorAll('[data-result-item]') ?? []);
|
|
11
11
|
if (!items.length) return;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const active = document.activeElement;
|
|
13
|
+
const current = active instanceof HTMLElement ? items.indexOf(active) : -1;
|
|
14
14
|
switch(event.key){
|
|
15
15
|
case 'ArrowDown':
|
|
16
16
|
{
|
|
17
17
|
event.preventDefault();
|
|
18
|
-
const nextIndex =
|
|
18
|
+
const nextIndex = current < items.length - 1 ? current + 1 : 0;
|
|
19
19
|
items[nextIndex]?.focus();
|
|
20
20
|
break;
|
|
21
21
|
}
|
|
22
22
|
case 'ArrowUp':
|
|
23
23
|
{
|
|
24
24
|
event.preventDefault();
|
|
25
|
-
const previousIndex =
|
|
25
|
+
const previousIndex = current > 0 ? current - 1 : items.length - 1;
|
|
26
26
|
items[previousIndex]?.focus();
|
|
27
27
|
break;
|
|
28
28
|
}
|
|
29
29
|
case 'Enter':
|
|
30
30
|
{
|
|
31
|
-
if (
|
|
31
|
+
if (current < 0) return;
|
|
32
32
|
event.preventDefault();
|
|
33
|
-
items[
|
|
33
|
+
items[current]?.click();
|
|
34
34
|
break;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type Hit } from '../types.js';
|
|
2
|
-
export declare
|
|
1
|
+
import { type Hit, type SearchMode } from '../types.js';
|
|
2
|
+
export declare function getCompare(sortBy?: string, mode?: SearchMode | boolean): (a: Hit, b: Hit) => number;
|
|
3
3
|
//# sourceMappingURL=sortResults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortResults.d.ts","sourceRoot":"","sources":["../../src/utils/sortResults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAa,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"sortResults.d.ts","sourceRoot":"","sources":["../../src/utils/sortResults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,UAAU,EAAa,MAAM,aAAa,CAAA;AA6HlE,wBAAgB,UAAU,CACxB,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,GAAE,UAAU,GAAG,OAAmB,GACrC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM,CAc5B"}
|
|
@@ -1,73 +1,103 @@
|
|
|
1
|
-
|
|
1
|
+
const SORT_PATTERN = /^([\w.]+)(?:\(missing_values:\s*(first|last)\))?\s*:\s*(asc|desc)$/;
|
|
2
|
+
const SCORE_FIELDS = new Set([
|
|
3
|
+
'_text_match',
|
|
4
|
+
'_vector_distance'
|
|
5
|
+
]);
|
|
6
|
+
function parseSorts(sortBy) {
|
|
7
|
+
if (!sortBy?.trim()) return [];
|
|
2
8
|
const sorts = [];
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'_vector_distance'
|
|
9
|
-
].includes(match[1])) {
|
|
10
|
-
throw new Error('Multi-collection sorting supports field names, _text_match and _vector_distance');
|
|
11
|
-
}
|
|
12
|
-
sorts.push({
|
|
13
|
-
direction: match[3] === 'asc' ? 1 : -1,
|
|
14
|
-
field: match[1],
|
|
15
|
-
missing: match[2]
|
|
16
|
-
});
|
|
9
|
+
for (const part of sortBy.split(',')){
|
|
10
|
+
const match = part.trim().match(SORT_PATTERN);
|
|
11
|
+
const field = match?.[1];
|
|
12
|
+
if (!field || field.startsWith('_') && !SCORE_FIELDS.has(field)) {
|
|
13
|
+
throw new Error('Multi-collection sorting supports field names, _text_match and _vector_distance');
|
|
17
14
|
}
|
|
18
|
-
if (sorts.length > 3) {
|
|
19
|
-
throw new Error('A maximum of three sort fields is supported');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (!sorts.length) {
|
|
23
15
|
sorts.push({
|
|
24
|
-
direction:
|
|
25
|
-
field
|
|
16
|
+
direction: match[3] === 'asc' ? 1 : -1,
|
|
17
|
+
field,
|
|
18
|
+
missing: match[2]
|
|
26
19
|
});
|
|
27
|
-
}
|
|
20
|
+
}
|
|
21
|
+
if (sorts.length > 3) {
|
|
22
|
+
throw new Error('A maximum of three sort fields is supported');
|
|
23
|
+
}
|
|
24
|
+
return sorts;
|
|
25
|
+
}
|
|
26
|
+
function getSorts(sortBy, vector) {
|
|
27
|
+
const sorts = parseSorts(sortBy);
|
|
28
|
+
const field = vector ? '_vector_distance' : '_text_match';
|
|
29
|
+
if (sorts.length < 3 && !sorts.some((sort)=>sort.field === field)) {
|
|
28
30
|
sorts.push({
|
|
29
|
-
direction: -1,
|
|
30
|
-
field
|
|
31
|
+
direction: vector ? 1 : -1,
|
|
32
|
+
field
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (leftMissing || rightMissing) {
|
|
40
|
-
if (leftMissing === rightMissing) continue;
|
|
41
|
-
const stringField = typeof (leftMissing ? right : left) === 'string' && sort.field !== '_text_match';
|
|
42
|
-
const first = sort.missing === 'first' || !sort.missing && stringField && sort.direction < 0;
|
|
43
|
-
return leftMissing === first ? -1 : 1;
|
|
44
|
-
}
|
|
45
|
-
let compared;
|
|
46
|
-
if (sort.field === '_text_match') {
|
|
47
|
-
const leftScore = BigInt(left);
|
|
48
|
-
const rightScore = BigInt(right);
|
|
49
|
-
compared = leftScore < rightScore ? -1 : leftScore > rightScore ? 1 : 0;
|
|
50
|
-
} else if (typeof left === 'number' && typeof right === 'number') {
|
|
51
|
-
compared = left - right;
|
|
52
|
-
} else if (typeof left === 'boolean' && typeof right === 'boolean') {
|
|
53
|
-
compared = Number(left) - Number(right);
|
|
54
|
-
} else {
|
|
55
|
-
const leftText = String(left);
|
|
56
|
-
const rightText = String(right);
|
|
57
|
-
compared = leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
|
|
58
|
-
}
|
|
59
|
-
if (compared) return compared * sort.direction;
|
|
60
|
-
}
|
|
61
|
-
return 0;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
const getValue = (hit, field)=>{
|
|
65
|
-
if (field === '_text_match') return hit.text_match_info?.score ?? hit.text_match ?? 0;
|
|
35
|
+
return sorts;
|
|
36
|
+
}
|
|
37
|
+
function getValue(hit, field) {
|
|
38
|
+
if (field === '_text_match') {
|
|
39
|
+
return hit.text_match_info?.score ?? hit.text_match ?? 0;
|
|
40
|
+
}
|
|
66
41
|
if (field === '_vector_distance') return hit.vector_distance;
|
|
67
42
|
const document = hit.document;
|
|
68
43
|
if (Object.hasOwn(document, field)) return document[field];
|
|
69
44
|
return field.split('.').reduce((value, part)=>{
|
|
70
|
-
if (!value || typeof value !== 'object' || !Object.hasOwn(value, part))
|
|
45
|
+
if (!value || typeof value !== 'object' || !Object.hasOwn(value, part)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
71
48
|
return value[part];
|
|
72
49
|
}, document);
|
|
73
|
-
}
|
|
50
|
+
}
|
|
51
|
+
function getSortValue(hit, field, hybrid) {
|
|
52
|
+
if (hybrid && field === '_text_match') {
|
|
53
|
+
return hit.hybrid_search_info?.rank_fusion_score ?? 0;
|
|
54
|
+
}
|
|
55
|
+
return getValue(hit, field);
|
|
56
|
+
}
|
|
57
|
+
function isMissing(value) {
|
|
58
|
+
return value === undefined || value === null || value === '';
|
|
59
|
+
}
|
|
60
|
+
function compareMissing(left, right, sort) {
|
|
61
|
+
const leftMissing = isMissing(left);
|
|
62
|
+
const rightMissing = isMissing(right);
|
|
63
|
+
if (!leftMissing && !rightMissing) return undefined;
|
|
64
|
+
if (leftMissing === rightMissing) return 0;
|
|
65
|
+
const stringField = typeof (leftMissing ? right : left) === 'string' && sort.field !== '_text_match';
|
|
66
|
+
const first = sort.missing === 'first' || !sort.missing && stringField && sort.direction < 0;
|
|
67
|
+
return leftMissing === first ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
function compareValues(left, right, field, hybrid) {
|
|
70
|
+
if (field === '_text_match' && !hybrid) {
|
|
71
|
+
const a = BigInt(left);
|
|
72
|
+
const b = BigInt(right);
|
|
73
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
74
|
+
}
|
|
75
|
+
if (typeof left === 'number' && typeof right === 'number') {
|
|
76
|
+
return left - right;
|
|
77
|
+
}
|
|
78
|
+
if (typeof left === 'boolean' && typeof right === 'boolean') {
|
|
79
|
+
return Number(left) - Number(right);
|
|
80
|
+
}
|
|
81
|
+
const a = String(left);
|
|
82
|
+
const b = String(right);
|
|
83
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
84
|
+
}
|
|
85
|
+
function compareSort(a, b, sort, hybrid) {
|
|
86
|
+
const left = getSortValue(a, sort.field, hybrid);
|
|
87
|
+
const right = getSortValue(b, sort.field, hybrid);
|
|
88
|
+
const missing = compareMissing(left, right, sort);
|
|
89
|
+
if (missing !== undefined) return missing;
|
|
90
|
+
return compareValues(left, right, sort.field, hybrid) * sort.direction;
|
|
91
|
+
}
|
|
92
|
+
export function getCompare(sortBy, mode = 'keyword') {
|
|
93
|
+
const vector = mode === true || mode === 'semantic';
|
|
94
|
+
const hybrid = mode === 'hybrid';
|
|
95
|
+
const sorts = getSorts(sortBy, vector);
|
|
96
|
+
return (a, b)=>{
|
|
97
|
+
for (const sort of sorts){
|
|
98
|
+
const result = compareSort(a, b, sort, hybrid);
|
|
99
|
+
if (result !== 0) return result;
|
|
100
|
+
}
|
|
101
|
+
return 0;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testConnection.d.ts","sourceRoot":"","sources":["../../src/utils/testConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,
|
|
1
|
+
{"version":3,"file":"testConnection.d.ts","sourceRoot":"","sources":["../../src/utils/testConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,wBAAsB,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ/E"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import type Typesense from 'typesense';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
page: number;
|
|
5
|
-
per_page: number;
|
|
6
|
-
sort_by?: string;
|
|
7
|
-
}): Promise<Typesense.SearchResponse<object>>;
|
|
2
|
+
import { type VectorOptions } from '../types.js';
|
|
3
|
+
export declare function vectorSearch(client: Typesense.Client, query: string, options: VectorOptions): Promise<Typesense.SearchResponse<object>>;
|
|
8
4
|
//# sourceMappingURL=vectorSearch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectorSearch.d.ts","sourceRoot":"","sources":["../../src/utils/vectorSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"vectorSearch.d.ts","sourceRoot":"","sources":["../../src/utils/vectorSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAGtC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AA0BhD,wBAAsB,YAAY,CAChC,MAAM,EAAE,SAAS,CAAC,MAAM,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,6CAGvB"}
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { buildParameters } from '../lib/search.js';
|
|
2
|
+
function getPagination(options) {
|
|
3
|
+
const { page, per_page } = options;
|
|
4
|
+
return {
|
|
5
|
+
page: Number.isInteger(page) && page > 0 ? page : 1,
|
|
6
|
+
per_page: Number.isInteger(per_page) && per_page > 0 ? Math.min(per_page, 250) : 10
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function getParameters(query, options) {
|
|
10
|
+
return buildParameters({
|
|
11
|
+
vectorSearch: {
|
|
12
|
+
...options.vectorSearch,
|
|
13
|
+
enabled: true
|
|
14
|
+
}
|
|
15
|
+
}, [], {
|
|
16
|
+
...getPagination(options),
|
|
9
17
|
q: query,
|
|
10
|
-
|
|
11
|
-
search_cutoff_ms: 5000,
|
|
18
|
+
search_mode: 'semantic',
|
|
12
19
|
...options.sort_by ? {
|
|
13
20
|
sort_by: options.sort_by
|
|
14
21
|
} : {}
|
|
15
22
|
});
|
|
16
23
|
}
|
|
24
|
+
export async function vectorSearch(client, query, options) {
|
|
25
|
+
return client.collections(options.collection).documents().search(getParameters(query, options));
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubixstudios/payload-typesense",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A production-ready search plugin that integrates Typesense with Payload CMS, offering fast, typo-tolerant search with real-time synchronization. This fork by Rubix Studios reduces bloat and introduces targeted changes for improved performance, maintainability, and flexibility.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Rubix Studios <hello@rubixstudios.com.au> (https://rubixstudios.com.au)",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"sideEffects": false,
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"import": "./dist/index.js",
|
|
39
38
|
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
40
|
"default": "./dist/index.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
@@ -48,20 +48,21 @@
|
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "pnpm build:types && pnpm build:swc",
|
|
50
50
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
51
|
-
"build:types": "tsc
|
|
51
|
+
"build:types": "tsc --build tsconfig.json --force",
|
|
52
52
|
"clean": "rimraf -g {dist,*.tsbuildinfo} && pnpm exec biome check --write && pnpm biome migrate --write",
|
|
53
53
|
"update": "pnpm self-update && pnpm update --latest && pnpm install && pnpm prune && pnpm dedupe && pnpm run clean",
|
|
54
|
-
"release": "semantic-release"
|
|
54
|
+
"release": "semantic-release",
|
|
55
|
+
"prepack": "pnpm build"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@biomejs/biome": "2.
|
|
58
|
+
"@biomejs/biome": "2.6.4",
|
|
58
59
|
"@semantic-release/changelog": "^7.0.0",
|
|
59
60
|
"@semantic-release/git": "^11.0.1",
|
|
60
|
-
"@swc/cli": "^0.8.
|
|
61
|
-
"@swc/core": "^1.16.
|
|
61
|
+
"@swc/cli": "^0.8.2",
|
|
62
|
+
"@swc/core": "^1.16.21",
|
|
62
63
|
"@types/react": "19.3.0",
|
|
63
64
|
"conventional-changelog-conventionalcommits": "^10.4.1",
|
|
64
|
-
"payload": "^3.
|
|
65
|
+
"payload": "^3.92.1",
|
|
65
66
|
"rimraf": "^6.1.3",
|
|
66
67
|
"semantic-release": "^25.0.9",
|
|
67
68
|
"typescript": "^7.0.2"
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"payload": "^3.90.0"
|
|
71
72
|
},
|
|
72
73
|
"engines": {
|
|
73
|
-
"node": ">=24",
|
|
74
|
+
"node": ">=24.22.1 <25 || >=26.12.1",
|
|
74
75
|
"pnpm": ">=10"
|
|
75
76
|
},
|
|
76
77
|
"publishConfig": {
|
|
@@ -87,8 +88,8 @@
|
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
90
|
"dependencies": {
|
|
90
|
-
"typesense": "^3.
|
|
91
|
-
"zod": "^4.6.
|
|
91
|
+
"typesense": "^3.2.0",
|
|
92
|
+
"zod": "^4.6.7"
|
|
92
93
|
},
|
|
93
|
-
"packageManager": "pnpm@12.
|
|
94
|
+
"packageManager": "pnpm@12.16.1"
|
|
94
95
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type HeadlessSearchInputProps } from '../lib/headlessSearch.js';
|
|
3
|
-
export declare function HeadlessSearchInput<T = Record<string, unknown>>(props: HeadlessSearchInputProps<T>): React.ReactElement;
|
|
4
|
-
export default HeadlessSearchInput;
|
|
5
|
-
//# sourceMappingURL=HeadlessSearchInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HeadlessSearchInput.d.ts","sourceRoot":"","sources":["../../src/components/HeadlessSearchInput.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAI1D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AAWxE,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACjC,KAAK,CAAC,YAAY,CAoUpB;eAEc,mBAAmB"}
|