Skip to content

Commit ff49d2d

Browse files
committed
perf: fix keywords logic in structured filters
1 parent 92e4588 commit ff49d2d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

app/composables/useStructuredFilters.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function hasSearchOperators(parsed: ParsedSearchOperators): boolean {
8787

8888
interface UseStructuredFiltersOptions {
8989
packages: Ref<NpmSearchResult[]>
90+
searchQuery?: Ref<string>
9091
initialFilters?: Partial<StructuredFilters>
9192
initialSort?: SortOption
9293
}
@@ -404,13 +405,16 @@ export function useStructuredFilters(options: UseStructuredFiltersOptions) {
404405
? `${searchQuery.value.trim()} keyword:${keyword}`
405406
: `keyword:${keyword}`
406407
router.replace({ query: { ...route.query, q: newQ } })
408+
409+
if (searchQuery) searchQuery.value = newQ
407410
}
408411
}
409412

410413
function removeKeyword(keyword: string) {
411414
filters.value.keywords = filters.value.keywords.filter(k => k !== keyword)
412415
const newQ = searchQuery.value.replace(new RegExp(`keyword:${keyword}($| )`, 'g'), '').trim()
413416
router.replace({ query: { ...route.query, q: newQ || undefined } })
417+
if (searchQuery) searchQuery.value = newQ
414418
}
415419

416420
function toggleKeyword(keyword: string) {

app/pages/search.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const {
147147
...parseSearchOperators(normalizeSearchParam(route.query.q)),
148148
},
149149
initialSort: 'relevance-desc', // Default to search relevance
150+
searchQuery,
150151
})
151152
152153
const isRelevanceSort = computed(

0 commit comments

Comments
 (0)