@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.
Files changed (139) hide show
  1. package/README.md +55 -16
  2. package/dist/components/ThemeProvider.d.ts +3 -2
  3. package/dist/components/ThemeProvider.d.ts.map +1 -1
  4. package/dist/components/ThemeProvider.js +8 -0
  5. package/dist/components/icons/index.d.ts +1 -0
  6. package/dist/components/icons/index.d.ts.map +1 -1
  7. package/dist/components/icons/index.js +1 -0
  8. package/dist/components/icons/noResultsIcon.d.ts +2 -4
  9. package/dist/components/icons/noResultsIcon.d.ts.map +1 -1
  10. package/dist/components/icons/searchIcon.d.ts +2 -4
  11. package/dist/components/icons/searchIcon.d.ts.map +1 -1
  12. package/dist/components/icons/xIcon.d.ts +2 -0
  13. package/dist/components/icons/xIcon.d.ts.map +1 -0
  14. package/dist/components/icons/xIcon.js +17 -0
  15. package/dist/components/index.d.ts +9 -5
  16. package/dist/components/index.d.ts.map +1 -1
  17. package/dist/components/index.js +5 -3
  18. package/dist/components/render/Content.d.ts +26 -0
  19. package/dist/components/render/Content.d.ts.map +1 -0
  20. package/dist/components/render/Content.js +144 -0
  21. package/dist/components/render/Dialog.d.ts +20 -0
  22. package/dist/components/render/Dialog.d.ts.map +1 -0
  23. package/dist/components/render/Dialog.js +43 -0
  24. package/dist/components/render/Header.d.ts +2 -2
  25. package/dist/components/render/Header.d.ts.map +1 -1
  26. package/dist/components/render/Header.js +17 -39
  27. package/dist/components/render/Highlight.d.ts +3 -0
  28. package/dist/components/render/Highlight.d.ts.map +1 -0
  29. package/dist/components/render/Highlight.js +22 -0
  30. package/dist/components/render/NoResults.d.ts +2 -2
  31. package/dist/components/render/NoResults.d.ts.map +1 -1
  32. package/dist/components/render/NoResults.js +18 -39
  33. package/dist/components/render/ResultError.d.ts +2 -2
  34. package/dist/components/render/ResultError.d.ts.map +1 -1
  35. package/dist/components/render/ResultError.js +7 -32
  36. package/dist/components/render/Results.d.ts +7 -6
  37. package/dist/components/render/Results.d.ts.map +1 -1
  38. package/dist/components/render/Results.js +34 -109
  39. package/dist/components/render/index.d.ts +7 -4
  40. package/dist/components/render/index.d.ts.map +1 -1
  41. package/dist/components/render/index.js +7 -4
  42. package/dist/components/search/HeadlessDialog.d.ts +5 -0
  43. package/dist/components/search/HeadlessDialog.d.ts.map +1 -0
  44. package/dist/components/search/HeadlessDialog.js +254 -0
  45. package/dist/components/search/HeadlessInput.d.ts +5 -0
  46. package/dist/components/search/HeadlessInput.d.ts.map +1 -0
  47. package/dist/components/search/HeadlessInput.js +193 -0
  48. package/dist/components/search/SearchStyles.d.ts +8 -0
  49. package/dist/components/search/SearchStyles.d.ts.map +1 -0
  50. package/dist/components/search/SearchStyles.js +9 -0
  51. package/dist/components/themes/constant.d.ts +3 -0
  52. package/dist/components/themes/constant.d.ts.map +1 -0
  53. package/dist/components/themes/constant.js +75 -0
  54. package/dist/components/themes/hooks.d.ts +4 -4
  55. package/dist/components/themes/hooks.d.ts.map +1 -1
  56. package/dist/components/themes/hooks.js +15 -26
  57. package/dist/components/themes/index.d.ts +1 -0
  58. package/dist/components/themes/index.d.ts.map +1 -1
  59. package/dist/components/themes/index.js +1 -0
  60. package/dist/components/themes/themes.d.ts.map +1 -1
  61. package/dist/components/themes/themes.js +50 -7
  62. package/dist/components/themes/types.d.ts +62 -2
  63. package/dist/components/themes/types.d.ts.map +1 -1
  64. package/dist/components/themes/utils.d.ts +11 -4
  65. package/dist/components/themes/utils.d.ts.map +1 -1
  66. package/dist/components/themes/utils.js +450 -315
  67. package/dist/components/utils/decodeEntities.d.ts +2 -0
  68. package/dist/components/utils/decodeEntities.d.ts.map +1 -0
  69. package/dist/components/utils/decodeEntities.js +23 -0
  70. package/dist/components/utils/index.d.ts +4 -0
  71. package/dist/components/utils/index.d.ts.map +1 -0
  72. package/dist/components/utils/index.js +3 -0
  73. package/dist/components/utils/toKebab.d.ts +2 -0
  74. package/dist/components/utils/toKebab.d.ts.map +1 -0
  75. package/dist/components/utils/toKebab.js +3 -0
  76. package/dist/components/utils/toText.d.ts +2 -0
  77. package/dist/components/utils/toText.d.ts.map +1 -0
  78. package/dist/components/utils/toText.js +3 -0
  79. package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
  80. package/dist/endpoints/handler/createAdvancedSearch.js +63 -5
  81. package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
  82. package/dist/endpoints/handler/createSearch.js +73 -106
  83. package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
  84. package/dist/endpoints/handler/createSuggest.js +27 -25
  85. package/dist/endpoints/search.d.ts +1 -1
  86. package/dist/endpoints/search.d.ts.map +1 -1
  87. package/dist/endpoints/search.js +1 -1
  88. package/dist/hooks/useSearch.d.ts +8 -5
  89. package/dist/hooks/useSearch.d.ts.map +1 -1
  90. package/dist/hooks/useSearch.js +53 -20
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +10 -5
  93. package/dist/lib/hooks.d.ts.map +1 -1
  94. package/dist/lib/hooks.js +5 -2
  95. package/dist/lib/initialization.d.ts +1 -1
  96. package/dist/lib/initialization.d.ts.map +1 -1
  97. package/dist/lib/initialization.js +8 -8
  98. package/dist/lib/schema-mapper.d.ts +1 -1
  99. package/dist/lib/schema-mapper.d.ts.map +1 -1
  100. package/dist/lib/schema-mapper.js +16 -8
  101. package/dist/lib/search-dialog.d.ts +169 -0
  102. package/dist/lib/search-dialog.d.ts.map +1 -0
  103. package/dist/lib/search-dialog.js +4 -0
  104. package/dist/lib/{headlessSearch.d.ts → search-input.d.ts} +6 -3
  105. package/dist/lib/search-input.d.ts.map +1 -0
  106. package/dist/lib/search-pagination.d.ts +38 -0
  107. package/dist/lib/search-pagination.d.ts.map +1 -0
  108. package/dist/lib/search-pagination.js +4 -0
  109. package/dist/lib/search.d.ts +25 -0
  110. package/dist/lib/search.d.ts.map +1 -0
  111. package/dist/lib/search.js +59 -0
  112. package/dist/lib/validation.d.ts +36 -10
  113. package/dist/lib/validation.d.ts.map +1 -1
  114. package/dist/lib/validation.js +54 -18
  115. package/dist/types.d.ts +42 -3
  116. package/dist/types.d.ts.map +1 -1
  117. package/dist/utils/ensureCollection.d.ts +1 -1
  118. package/dist/utils/ensureCollection.d.ts.map +1 -1
  119. package/dist/utils/ensureCollection.js +58 -22
  120. package/dist/utils/getCollectionInfo.d.ts.map +1 -1
  121. package/dist/utils/getCollections.d.ts +2 -2
  122. package/dist/utils/getCollections.d.ts.map +1 -1
  123. package/dist/utils/getCollections.js +32 -20
  124. package/dist/utils/keyboard.js +6 -6
  125. package/dist/utils/sortResults.d.ts +2 -2
  126. package/dist/utils/sortResults.d.ts.map +1 -1
  127. package/dist/utils/sortResults.js +90 -60
  128. package/dist/utils/testConnection.d.ts +1 -1
  129. package/dist/utils/testConnection.d.ts.map +1 -1
  130. package/dist/utils/testConnection.js +2 -2
  131. package/dist/utils/vectorSearch.d.ts +2 -6
  132. package/dist/utils/vectorSearch.d.ts.map +1 -1
  133. package/dist/utils/vectorSearch.js +20 -10
  134. package/package.json +13 -12
  135. package/dist/components/HeadlessSearchInput.d.ts +0 -5
  136. package/dist/components/HeadlessSearchInput.d.ts.map +0 -1
  137. package/dist/components/HeadlessSearchInput.js +0 -237
  138. package/dist/lib/headlessSearch.d.ts.map +0 -1
  139. /package/dist/lib/{headlessSearch.js → search-input.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { searchCache } from '../lib/cache.js';
2
- import { getComparator } from './sortResults.js';
3
- import { vectorSearch } from './vectorSearch.js';
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 vector = Boolean(options.vector && config.vectorSearch?.enabled);
15
+ const mode = getSearchMode(config, options);
16
16
  let compare;
17
17
  if (multiple) {
18
18
  try {
19
- compare = getComparator(options.sort_by, vector);
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?.join(',') || 'title,content,description';
43
- const search = (page)=>vector ? vectorSearch(client, query, {
44
- collection: slug,
45
- page,
46
- per_page: perPage,
47
- sort_by: options.sort_by
48
- }) : client.collections(slug).documents().search({
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
- query_by: fields,
55
- snippet_threshold: 30,
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);
@@ -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 activeElement = document.activeElement;
13
- const currentIndex = activeElement instanceof HTMLElement ? items.indexOf(activeElement) : -1;
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 = currentIndex < items.length - 1 ? currentIndex + 1 : 0;
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 = currentIndex > 0 ? currentIndex - 1 : items.length - 1;
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 (currentIndex < 0) return;
31
+ if (current < 0) return;
32
32
  event.preventDefault();
33
- items[currentIndex]?.click();
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 const getComparator: (sortBy?: string, vector?: boolean) => (a: Hit, b: Hit) => number;
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;AAEjD,eAAO,MAAM,aAAa,YAAa,MAAM,2BAoChC,GAAG,KAAK,GAAG,KAAG,MAyC1B,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
- export const getComparator = (sortBy, vector = false)=>{
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
- if (sortBy?.trim()) {
4
- for (const part of sortBy.split(',')){
5
- const match = part.trim().match(/^([\w.]+)(?:\(missing_values:\s*(first|last)\))?\s*:\s*(asc|desc)$/);
6
- if (!match?.[1] || match[1].startsWith('_') && ![
7
- '_text_match',
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: vector ? 1 : -1,
25
- field: vector ? '_vector_distance' : '_text_match'
16
+ direction: match[3] === 'asc' ? 1 : -1,
17
+ field,
18
+ missing: match[2]
26
19
  });
27
- } else if (sorts.length < 3 && !sorts.some((sort)=>sort.field === '_text_match')) {
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: '_text_match'
31
+ direction: vector ? 1 : -1,
32
+ field
31
33
  });
32
34
  }
33
- return (a, b)=>{
34
- for (const sort of sorts){
35
- const left = getValue(a, sort.field);
36
- const right = getValue(b, sort.field);
37
- const leftMissing = left === undefined || left === null || left === '';
38
- const rightMissing = right === undefined || right === null || right === '';
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)) return undefined;
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,3 +1,3 @@
1
1
  import type Typesense from 'typesense';
2
- export declare const testConnection: (client: Typesense.Client) => Promise<boolean>;
2
+ export declare function testConnection(client: Typesense.Client): Promise<boolean>;
3
3
  //# sourceMappingURL=testConnection.d.ts.map
@@ -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,eAAO,MAAM,cAAc,WAAkB,SAAS,CAAC,MAAM,KAAG,OAAO,CAAC,OAAO,CAO9E,CAAA"}
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,8 @@
1
- export const testConnection = async (client)=>{
1
+ export async function testConnection(client) {
2
2
  try {
3
3
  const health = await client.health.retrieve();
4
4
  return health.ok === true;
5
5
  } catch {
6
6
  return false;
7
7
  }
8
- };
8
+ }
@@ -1,8 +1,4 @@
1
1
  import type Typesense from 'typesense';
2
- export declare function vectorSearch(client: Typesense.Client, query: string, options: {
3
- collection: string;
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;AAEtC,wBAAsB,YAAY,CAChC,MAAM,EAAE,SAAS,CAAC,MAAM,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;IACP,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,6CAmBF"}
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
- export async function vectorSearch(client, query, options) {
2
- const { collection, page, per_page } = options;
3
- const pageNum = Number.isInteger(page) && page > 0 ? page : 1;
4
- const perPageNum = Number.isInteger(per_page) && per_page > 0 ? Math.min(per_page, 250) : 10;
5
- return client.collections(collection).documents().search({
6
- num_typos: 0,
7
- page: pageNum,
8
- per_page: perPageNum,
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
- query_by: 'embedding',
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.7.0",
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 -p tsconfig.json",
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.5.15",
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.1",
61
- "@swc/core": "^1.16.17",
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.90.2",
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.1.1",
91
- "zod": "^4.6.5"
91
+ "typesense": "^3.2.0",
92
+ "zod": "^4.6.7"
92
93
  },
93
- "packageManager": "pnpm@12.11.2"
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"}