@@ -10,13 +10,6 @@ import { normalizeSearchParam } from '#shared/utils/url'
1010const route = useRoute ()
1111const router = useRouter ()
1212
13- const { searchProvider } = useSearchProvider ()
14- const searchProviderValue = computed (() => {
15- const p = normalizeSearchParam (route .query .p )
16- if (p === ' npm' || searchProvider .value === ' npm' ) return ' npm'
17- return ' algolia'
18- })
19-
2013// Preferences (persisted to localStorage)
2114const {
2215 viewMode,
@@ -33,12 +26,11 @@ const updateUrlPage = debounce((page: number) => {
3326 query: {
3427 ... route .query ,
3528 page: page > 1 ? page : undefined ,
36- p: searchProviderValue .value === ' npm' ? ' npm' : undefined ,
3729 },
3830 })
3931}, 500 )
4032
41- const searchQuery = useGlobalSearchQuery ()
33+ const { model : searchQuery, provider : searchProvider } = useGlobalSearch ()
4234const query = computed (() => searchQuery .value )
4335
4436// Track if page just loaded (for hiding "Searching..." during view transition)
@@ -131,7 +123,7 @@ const ALL_SORT_KEYS: SortKey[] = [
131123
132124// Disable sort keys the current provider can't meaningfully sort by
133125const disabledSortKeys = computed <SortKey []>(() => {
134- const supported = PROVIDER_SORT_KEYS [searchProviderValue .value ]
126+ const supported = PROVIDER_SORT_KEYS [searchProvider .value ]
135127 return ALL_SORT_KEYS .filter (k => ! supported .has (k ))
136128})
137129
@@ -155,6 +147,7 @@ const {
155147 ... parseSearchOperators (normalizeSearchParam (route .query .q )),
156148 },
157149 initialSort: ' relevance-desc' , // Default to search relevance
150+ searchQueryModel: searchQuery ,
158151})
159152
160153const isRelevanceSort = computed (
@@ -173,14 +166,14 @@ const requestedSize = computed(() => {
173166 // When sorting by something other than relevance, fetch a large batch
174167 // so client-side sorting operates on a meaningful pool of matching results
175168 if (! isRelevanceSort .value ) {
176- const cap = EAGER_LOAD_SIZE [searchProviderValue .value ]
169+ const cap = EAGER_LOAD_SIZE [searchProvider .value ]
177170 return Math .max (base , cap )
178171 }
179172 return base
180173})
181174
182175// Reset to relevance sort when switching to a provider that doesn't support the current sort key
183- watch (searchProviderValue , provider => {
176+ watch (searchProvider , provider => {
184177 const { key } = parseSortOption (sortOption .value )
185178 const supported = PROVIDER_SORT_KEYS [provider ]
186179 if (! supported .has (key )) {
@@ -200,7 +193,7 @@ const {
200193 packageAvailability,
201194} = useSearch (
202195 query ,
203- searchProviderValue ,
196+ searchProvider ,
204197 () => ({
205198 size: requestedSize .value ,
206199 }),
0 commit comments