|
48 | 48 | const step = 0.1; |
49 | 49 | const enableVector = true; |
50 | 50 | const collectionType = KnowledgeCollectionType.Document; |
51 | | - const includedPayloads = [ |
52 | | - KnowledgePayloadName.Text, |
53 | | - KnowledgePayloadName.FileId, |
54 | | - KnowledgePayloadName.FileName, |
55 | | - KnowledgePayloadName.DataSource, |
56 | | - KnowledgePayloadName.FileSource, |
57 | | - KnowledgePayloadName.FileUrl |
58 | | - ]; |
59 | 51 | |
60 | 52 | /** @type {string} */ |
61 | 53 | let text = ""; |
|
91 | 83 | /** @type {import('$knowledgeTypes').VectorFilterGroup[]} */ |
92 | 84 | let innerSearchGroups = []; |
93 | 85 |
|
| 86 | + let sortField = ''; |
| 87 | + let sortOrder = 'desc'; |
| 88 | + /** @type {import('$knowledgeTypes').VectorSort?} */ |
| 89 | + let innerSort = { |
| 90 | + field: '', |
| 91 | + order: 'desc' |
| 92 | + }; |
| 93 | +
|
94 | 94 | /** @type {boolean} */ |
95 | 95 | let showDemo = true; |
96 | 96 | let isSearching = false; |
|
114 | 114 | * isReset: boolean, |
115 | 115 | * isLocalLoading: boolean, |
116 | 116 | * skipLoader: boolean, |
117 | | - * filterGroups: any[] |
| 117 | + * filterGroups: any[], |
| 118 | + * sort: any |
118 | 119 | * }} |
119 | 120 | */ |
120 | 121 | const defaultParams = { |
121 | 122 | startId: null, |
122 | 123 | isReset: false, |
123 | 124 | isLocalLoading: false, |
124 | 125 | skipLoader: false, |
125 | | - filterGroups: [] |
| 126 | + filterGroups: [], |
| 127 | + sort: null |
126 | 128 | }; |
127 | 129 |
|
128 | 130 | $: disabled = isLoading || isLoadingMore || isSearching; |
|
149 | 151 | ...defaultParams, |
150 | 152 | isReset: true, |
151 | 153 | skipLoader: true, |
152 | | - filterGroups: innerSearchGroups |
| 154 | + filterGroups: innerSearchGroups, |
| 155 | + sort: null |
153 | 156 | }).finally(() => isLoading = false); |
154 | 157 | }).finally(() => { |
155 | 158 | isLoading = false; |
|
173 | 176 | isFromSearch = false; |
174 | 177 |
|
175 | 178 | innerSearchGroups = buildSearchFilterGroups(searchItems); |
| 179 | + innerSort = buildSearchSort(sortField, sortOrder); |
176 | 180 |
|
177 | 181 | if (textSearch) { |
178 | 182 | getData({ |
179 | 183 | ...defaultParams, |
180 | 184 | isReset: true, |
181 | 185 | skipLoader: true, |
182 | | - filterGroups: innerSearchGroups |
| 186 | + filterGroups: innerSearchGroups, |
| 187 | + sort: innerSort |
183 | 188 | }).then(() => { |
184 | 189 | isFromSearch = true; |
185 | 190 | }).finally(() => { |
|
226 | 231 | startId: null, |
227 | 232 | isReset: true, |
228 | 233 | skipLoader: skipLoader, |
229 | | - filterGroups: innerSearchGroups |
| 234 | + filterGroups: innerSearchGroups, |
| 235 | + sort: innerSort |
230 | 236 | }); |
231 | 237 | } |
232 | 238 |
|
|
249 | 255 | textSearch = false; |
250 | 256 | selectedOperator = 'or'; |
251 | 257 | innerSearchGroups = []; |
| 258 | + sortField = ''; |
| 259 | + sortOrder = 'desc'; |
| 260 | + innerSort = { |
| 261 | + field: sortField, |
| 262 | + order: sortOrder |
| 263 | + }; |
252 | 264 | } |
253 | 265 |
|
254 | 266 |
|
|
316 | 328 | * @param {{ |
317 | 329 | * startId: string | null, |
318 | 330 | * isReset: boolean, |
319 | | - * filterGroups: any[] }} params |
| 331 | + * filterGroups: any[], |
| 332 | + * sort: any }} params |
320 | 333 | */ |
321 | 334 | function getKnowledgeListData(params = { |
322 | 335 | startId: null, |
323 | 336 | isReset: false, |
324 | | - filterGroups: [] |
| 337 | + filterGroups: [], |
| 338 | + sort: null |
325 | 339 | }) { |
326 | 340 | return new Promise((resolve, reject) => { |
327 | 341 | const filter = { |
328 | 342 | size: pageSize, |
329 | 343 | start_id: params.startId, |
330 | 344 | with_vector: enableVector, |
331 | 345 | fields: [], |
332 | | - filter_groups: params.filterGroups |
| 346 | + filter_groups: params.filterGroups, |
| 347 | + order_by: !!params.sort?.field ? params.sort : null |
333 | 348 | }; |
334 | 349 |
|
335 | 350 | getVectorKnowledgePageList( |
|
358 | 373 | * isReset: boolean, |
359 | 374 | * isLocalLoading: boolean, |
360 | 375 | * skipLoader: boolean, |
361 | | - * filterGroups: any[] }} params |
| 376 | + * filterGroups: any[], |
| 377 | + * sort: any }} params |
362 | 378 | */ |
363 | 379 | function getData(params = { |
364 | 380 | startId: null, |
365 | 381 | isReset: false, |
366 | 382 | isLocalLoading: false, |
367 | 383 | skipLoader: false, |
368 | | - filterGroups: [] |
| 384 | + filterGroups: [], |
| 385 | + sort: null |
369 | 386 | }) { |
370 | 387 | return new Promise((resolve, reject) => { |
371 | 388 | if (!params.skipLoader) { |
|
404 | 421 | ...defaultParams, |
405 | 422 | startId: nextId || null, |
406 | 423 | isLocalLoading: true, |
407 | | - filterGroups: innerSearchGroups |
| 424 | + filterGroups: innerSearchGroups, |
| 425 | + sort: innerSort |
408 | 426 | }; |
409 | 427 | getData(params); |
410 | 428 | } |
|
713 | 731 | if (isAdvSearchOn && items?.length > 0) { |
714 | 732 | const validItems = items.filter(x => x.checked && !!util.trim(x.key) && !!util.trim(x.value)) |
715 | 733 | .map(x => ({ key: util.trim(x.key), value: util.trim(x.value) })); |
716 | | - groups = [ ...groups, { filter_operator: selectedOperator, filters: validItems } ]; |
| 734 | + |
| 735 | + if (validItems.length > 0) { |
| 736 | + groups = [ ...groups, { filter_operator: selectedOperator, filters: validItems } ]; |
| 737 | + } |
717 | 738 | } |
718 | 739 |
|
719 | 740 | return groups; |
720 | 741 | } |
| 742 | +
|
| 743 | + /** |
| 744 | + * @param {string} field |
| 745 | + * @param {string} order |
| 746 | + */ |
| 747 | + function buildSearchSort(field, order) { |
| 748 | + return isAdvSearchOn ? { |
| 749 | + field: field, |
| 750 | + order: order |
| 751 | + } : null; |
| 752 | + } |
721 | 753 | </script> |
722 | 754 |
|
723 | 755 | <HeadTitle title="{$_('Document Knowledge')}" /> |
|
889 | 921 | bind:showAdvSearch={isAdvSearchOn} |
890 | 922 | bind:items={searchItems} |
891 | 923 | bind:operator={selectedOperator} |
| 924 | + bind:sortField={sortField} |
| 925 | + bind:sortOrder={sortOrder} |
892 | 926 | disabled={disabled} |
893 | 927 | /> |
894 | 928 | |
|
0 commit comments