|
50 | 50 | const duration = 2000; |
51 | 51 | const maxLength = 4096; |
52 | 52 | const step = 0.1; |
| 53 | + const searchLimit = 10; |
53 | 54 | const enableVector = true; |
54 | 55 | const collectionType = KnowledgeCollectionType.QuestionAnswer; |
55 | 56 | |
|
58 | 59 | let successText = "Done"; |
59 | 60 | let errorText = "Error"; |
60 | 61 | let confidence = '0.5'; |
| 62 | + let elapsedTime = ''; |
61 | 63 |
|
62 | 64 | /** @type {string} */ |
63 | 65 | let selectedCollection; |
|
116 | 118 | let textSearch = false; |
117 | 119 | let isAdvSearchOn = false; |
118 | 120 | let disableSearchBtn = false; |
| 121 | + let isExactSearch = false; |
119 | 122 |
|
120 | 123 | /** @type {{ |
121 | 124 | * startId: string | null, |
|
135 | 138 | sort: null |
136 | 139 | }; |
137 | 140 |
|
138 | | - $: disabled = isLoading || isLoadingMore || isSearching; |
| 141 | + $: disableBase = isLoading || isLoadingMore || isSearching; |
| 142 | + $: disabled = !selectedCollection || disableBase; |
139 | 143 | $: { |
140 | 144 | disableSearchBtn = false; |
141 | | - if (isSearching || isLoadingMore) { |
| 145 | + if (!selectedCollection || isSearching || isLoadingMore) { |
142 | 146 | disableSearchBtn = true; |
143 | 147 | } else if (textSearch && searchItems.length > 0) { |
144 | 148 | disableSearchBtn = false; |
|
184 | 188 | isSearching = true; |
185 | 189 | searchDone = false; |
186 | 190 | isFromSearch = false; |
| 191 | + elapsedTime = ''; |
| 192 | + const start = new Date(); |
187 | 193 |
|
188 | 194 | innerSearchGroups = buildSearchFilterGroups(searchItems); |
189 | 195 | innerSort = buildSearchSort(sortField, sortOrder); |
|
200 | 206 | }).finally(() => { |
201 | 207 | isSearching = false; |
202 | 208 | searchDone = true; |
| 209 | + const gap = new Date().getTime() - start.getTime(); |
| 210 | + elapsedTime = `${(gap / 1000).toFixed(3)}s`; |
203 | 211 | }); |
204 | 212 | } else { |
205 | 213 | /** @type {import('$knowledgeTypes').SearchKnowledgeRequest} */ |
206 | 214 | const params = { |
207 | 215 | text: util.trim(text), |
| 216 | + limit: searchLimit, |
208 | 217 | confidence: Number(validateConfidenceNumber(confidence)), |
209 | 218 | with_vector: enableVector, |
210 | 219 | filter_groups: innerSearchGroups, |
211 | | - search_param: { exact_search: false } |
| 220 | + search_param: { exact_search: isExactSearch } |
212 | 221 | }; |
213 | 222 |
|
214 | 223 | searchVectorKnowledge(selectedCollection, params).then(res => { |
|
219 | 228 | isSearching = false; |
220 | 229 | searchDone = true; |
221 | 230 | nextId = null; |
| 231 | + const gap = new Date().getTime() - start.getTime(); |
| 232 | + elapsedTime = `${(gap / 1000).toFixed(3)}s`; |
222 | 233 | }); |
223 | 234 | } |
224 | 235 | } |
|
264 | 275 |
|
265 | 276 | function resetStates() { |
266 | 277 | text = ""; |
| 278 | + elapsedTime = ''; |
267 | 279 | nextId = null; |
268 | 280 | isSearching = false; |
269 | 281 | searchDone = false; |
270 | 282 | isFromSearch = false; |
271 | 283 | textSearch = false; |
| 284 | + isExactSearch = false; |
272 | 285 | selectedOperator = 'or'; |
273 | 286 | innerSearchGroups = []; |
274 | 287 | sortField = ''; |
|
924 | 937 | bind:value={text} |
925 | 938 | on:keydown={(e) => pressKey(e)} |
926 | 939 | /> |
927 | | - <div class="text-secondary text-end text-count"> |
928 | | - {text?.length || 0}/{maxLength} |
| 940 | + <div class="text-secondary text-count d-flex justify-content-between"> |
| 941 | + <div> |
| 942 | + {#if elapsedTime} |
| 943 | + {`Elapsed time: ${elapsedTime}`} |
| 944 | + {/if} |
| 945 | + </div> |
| 946 | + <div>{text?.length || 0}/{maxLength}</div> |
929 | 947 | </div> |
930 | 948 | |
931 | 949 | <div class="mt-3 knowledge-search-footer"> |
|
978 | 996 | <span>{'Keyword search'}</span> |
979 | 997 | </div> |
980 | 998 | </div> |
| 999 | + {#if !textSearch} |
| 1000 | + <div class="search-input justify-content-center"> |
| 1001 | + <div class="line-align-center"> |
| 1002 | + <Input |
| 1003 | + class='input-text fw-bold' |
| 1004 | + type="checkbox" |
| 1005 | + label="Exact search" |
| 1006 | + disabled={disabled} |
| 1007 | + bind:checked={isExactSearch} |
| 1008 | + /> |
| 1009 | + </div> |
| 1010 | + </div> |
| 1011 | + {/if} |
981 | 1012 | <div class="line-align-center"> |
982 | 1013 | <Button |
983 | 1014 | color="primary" |
|
1090 | 1121 | > |
1091 | 1122 | <Button |
1092 | 1123 | class="btn btn-sm btn-soft-primary collection-action-btn" |
1093 | | - disabled={disabled} |
| 1124 | + disabled={disableBase} |
1094 | 1125 | on:click={() => toggleCollectionCreate()} |
1095 | 1126 | > |
1096 | 1127 | <i class="mdi mdi-plus" /> |
|
0 commit comments