Appearance
useSearchBar Composable ​
File Information ​
- Path:
app/composables/core/components/search/useSearchBar.ts - Purpose: Search bar logic, suggestions, and results display
- Type: Core Composable
Overview ​
Search bar logic, suggestions, and results display
Features ​
Submitting a search (fetchResults) ​
The bar behaves differently depending on whether the user is already on the search results page (route.name === "brand_name-search").
- On the results page the bar does not search itself. It rewrites the encrypted
qURL and hands the query touseSearchthrough thesearch-results-pagemitt event. It emitssearch-url-from-barfirst souseSearchskips the reload itsroute.query.qwatcher would otherwise trigger, and the page runs one search instead of two. See useSearch URL state. - Anywhere else it runs a dropdown preview search:
| Setting | Value |
|---|---|
| Collections | digital_assets, plus dam_collections and digital_assets_categories unless an asset-only filter is active (hasAssetOnlyFilter) |
| Filters | getCollectionFilters("", includeLibrary) from useCommonSearch |
| Fields | buildSearchFieldParams(collections) (weights shared with admin) |
per_page | SEARCH_LIBRARY_DROPDOWN_LIMIT (5) |
sort_by | _text_match:desc,modified_at:desc (the _eval band is prepended by searchAssets) |
text_match_type | max_score |
q | formatted query or * |
Asset hits get search_matches from getSearchMatches. Collage and folder hits are cut to 5 and mapped with mapCollageHit / mapFolderHit and their found totals are kept in collageCount / folderCount. A successful preview is tracked with trackSearchPerformed({ ..., source: "overlay" }), with folder and collage counts sent as null when the library was excluded. Errors show getSearchErrorMessage(error) in the snackbar and clear the dropdown.
Recent searches are only posted (postRecentSearch) for queries of at least MIN_SEARCH_LENGTH = 3 characters.
Opening the results page (redirectToSearch(tabArg?)) ​
Used by "View all" links and the submit action from outside the results page.
tabArgis used only if it is a string inSEARCH_TABS; anything else (for example aMouseEventfrom a click handler) is ignored and the tab becomesassets.- Cancel the pending debounced search and filter timeout, clear
searchHistory. - Post a recent search when the formatted term has at least
MIN_SEARCH_LENGTH(3) characters, and store the key. - Encrypt
{ searchKey: searchTerm || null, filter: allFilterList, tab }androuter.pushtobrand_name-searchwith only?q=<encrypted>.
Since ee26b58 the tab travels inside q instead of a separate ?tab= param (which was added only for non-assets tabs). Errors show getSearchErrorMessage(error) in the snackbar.
typescript
// "View all collages" in the dropdown
redirectToSearch("collages")
// -> /<brand_name>/search?q=<encrypt({ searchKey: "logo", filter: [], tab: "collages" })>SearchBar.vue computes hasMatchColumn over the items of every visible section (showAssets, showCollages, showFolders) and passes it as :match-column to the asset, collage and folder lists (340c6e0). The shared "Matched In" header and all three lists therefore show or hide the column together, keeping columns aligned under one header. See useSearchAssets.
Tabs ​
SearchBar.vue renders SearchTabs with include-all (All / Assets / Collages / Folders) above the dropdown results; the active tab is component state, not part of this composable.
Return Type ​
Refer to the composable source code for return type definitions. Composables use TypeScript for type-safe return values.
Parameters ​
Refer to the composable source code for parameter definitions. Composables use TypeScript for type-safe parameters.
Usage Example ​
typescript
import { useSearchBar } from '~/composables/core/components/search/useSearchBar'
const { /* destructured return values */ } = useSearchBar()Related Composables ​
- See Composables Overview for all composables
Related Documentation ​
- Composables Overview - All composables
- Types - TypeScript type definitions
- Components - Components using this composable