Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Basic components
Search Result
Official extension
Version: 3.59.0
Latest version: 3.130.2

This page is about version 3.59.0 of the app, which is not the most recent version. The latest stable version is 3.130.2.

{"base64":"  ","img":{"width":110,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square"}}

VTEX Search Result app is responsible for handling the result fetched by the VTEX Search API and displaying it to users.

The app therefore exports all store blocks expected in a search results page, such as the filters and the product gallery.

{"base64":"  ","img":{"width":2878,"height":1578,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":746685,"url":"https://user-images.githubusercontent.com/52087100/77557721-d96b6580-6e98-11ea-9178-77c8c4a6408e.png"}}

Configuration

Step 1 - Adding the Search Result app to your theme's dependencies

In your theme's manifest.json, add the Search Result app as a dependency:


_10
"dependencies": {
_10
"vtex.search-result": "3.x"
_10
}

Now, you are able to use all the blocks exported by the search-result app. Check out the full list below:

Block nameDescription
search-result-layout
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Layout block that enables you to build the search result page using its 3 children blocks: search-result-layout.desktop, search-result-layout.mobile and search-not-found-layout . It must be used in the store.search template since it uses the context provided by the VTEX Search API.
search-result-layout.customQuery
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Used instead of search-result-layout in scenarios in which the search result will be declared in a template that doesn't fetch Search context, such as Home. It accepts a querySchema prop that executes search custom queries. It also supports three children blocks: search-result-layout.desktop, search-result-layout.mobile and search-not-found-layout .
search-result-layout.desktop
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Builds the search result page structure for desktop mode.
search-result-layout.mobileBuilds the search result page structure for mobile mode. If the search-result-layout.mobile is not provided, the search-result-layout.desktop will be used instead.
search-layout-switcherEnables mobile users to switch between the available layout modes.
search-not-found-layoutBuilds the whole search result page structure for scenarios in which no result was fetched. It is rendered whenever users search for a term that doesn't return a product.
gallery
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Displays the gallery with all the products found in the search.
not-foundBlock containing a text and a description for the page that was not found in the search. It must be declared as a child of search-not-found-layout.
search-content
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Decides, behind the scenes, which block will be displayed: either the gallery block (if products are found) or the not-found block (if the selected filters lead to an empty search results page). This means that both gallery and not-found must be declared as search-content children.
store.not-found#searchWhen configured, it displays a 404 error message whenever the server is not able to return what the browser request was or when it is configured to not handle that request.
search-products-count-per-pageDisplays the total number of products being displayed in the search results page.
search-products-progress-barDisplays a progress bar of products being displayed in the search results page.
order-by.v2Allows users to choose the product ordination in the search results page.
filter-navigator.v3Allows users to apply different filters to the search. On mobile, renders a button that, when clicked on, displays all available filters in a sidebar.
total-products.v2Displays the total amount of products found for that search.
search-title.v2Displays a title for the search that was done.
search-fetch-moreDisplays the "Show More" button. This button isn't rendered when the user is on the last page.
search-fetch-previousDisplays the "Show Previous" button. This button isn't rendered when the user is on the first page.
search-products-count-per-pageDisplays the quantity of products currently on the page.
sidebar-close-buttonDisplays an X button on the filter sidebar on mobile.
search-title.v2Displays a title for the search that was done.

:information_source: The Search Result app data may be displayed on search pages (store.search) or any other desired page. When added to the search page, the block that is used must be the search-result-layout, since it fetches data provided by the template's current search context. If you want to add the app to another page, the block that must be used is the search-result-layout.customQuery.

Step 2 - Adding the Search Result to page templates

According to the desired store page, add the search-result-layout block or the search-result-layout.customQuery to the correct template blocks list. For example:


_10
"store.search": {
_10
"blocks": ["search-result-layout"]
_10
}

or


_10
"store.home": {
_10
"blocks": [
_10
"carousel#home",
_10
"shelf#home",
_10
+ "search-result-layout.customQuery#home"
_10
]
_10
}

Now, before declaring all desired blocks for your search result layout, your first need to define how you want the search results to be fetched.

:warning: Remember: on the home page, you define these results through a custom query. On the search template, you just need to use the already provided context.

Step 3 - Defining how the search query data should be fetched

According to your store's scenario, define how the search query data should be fetched using props.

If you are using a search-result-layout, the blocks will define the data that is fetched from the context. If what you are using is a search-result-layout.customQuery, the props should be sent through the querySchema to configure the custom query.

For example:


_11
{
_11
"store.search": {
_11
"blocks": ["search-result-layout"],
_11
"props": {
_11
"context": {
_11
"skusFilter": "FIRST_AVAILABLE",
_11
"simulationBehavior": "skip"
_11
}
_11
}
_11
}
_11
}

or


_17
{
_17
"store.home": {
_17
"blocks": [
_17
"carousel#home",
_17
"shelf#home",
_17
"search-result-layout.customQuery#home"
_17
]
_17
},
_17
"search-result-layout.customQuery#home": {
_17
"props": {
_17
"querySchema": {
_17
"skusFilter": "FIRST_AVAILABLE",
_17
"simulationBehavior": "skip"
_17
}
_17
}
_17
}
_17
}

:warning: You must define the query for the following search pages: brand, department, category and subcategory. This will allow you to define custom behaviors for each of your store's possible search pages. For example:


_47
{
_47
"store.search": {
_47
"blocks": ["search-result-layout"],
_47
"props": {
_47
"context": {
_47
"skusFilter": "FIRST_AVAILABLE",
_47
"simulationBehavior": "skip"
_47
}
_47
}
_47
},
_47
"store.search#category": {
_47
"blocks": ["search-result-layout"],
_47
"props": {
_47
"context": {
_47
"skusFilter": "FIRST_AVAILABLE",
_47
"simulationBehavior": "skip"
_47
}
_47
}
_47
},
_47
"store.search#brand": {
_47
"blocks": ["search-result-layout"],
_47
"props": {
_47
"context": {
_47
"skusFilter": "FIRST_AVAILABLE",
_47
"simulationBehavior": "skip"
_47
}
_47
}
_47
},
_47
"store.search#department": {
_47
"blocks": ["search-result-layout"],
_47
"props": {
_47
"context": {
_47
"skusFilter": "FIRST_AVAILABLE",
_47
"simulationBehavior": "skip"
_47
}
_47
}
_47
},
_47
"store.search#subcategory": {
_47
"blocks": ["search-result-layout"],
_47
"props": {
_47
"context": {
_47
"skusFilter": "FIRST_AVAILABLE",
_47
"simulationBehavior": "skip"
_47
}
_47
}
_47
}
_47
}

Below you may find all available props to configure your search data (be it by using a context or a custom query through the querySchema block):

Prop nameTypeDescriptionDefault value
maxItemsPerPagenumberMaximum number of items per search page. The maximum value of this prop is 50, if a larger number is passed, the query will fail.10
orderByFieldEnumDecides which order products must follow when displayed. The possible values are named after the order type: OrderByTopSaleDESC, OrderByReleaseDateDESC, OrderByBestDiscountDESC, OrderByPriceDESC, OrderByPriceASC, OrderByNameASC, OrderByNameDESC or OrderByScoreDESC (relevance score). ASC and DESC stand for ascending order and descending order, respectively.OrderByScoreDESC
hideUnavailableItemsbooleanWhether the search result should display unavailable items (true) or not (false).false
facetsBehaviorstringDefines the behavior filters will have. When set to dynamic, it restricts the results according to the filters that user have already selected. If set to Static, all filters will continue to be displayed to the user, even is no results exist.Static
skusFilterEnumControls SKUs returned for each product in the query. The less SKUs needed to be returned, the more performant your shelf query will be. Available value options: FIRST_AVAILABLE (returns only the first available SKU), ALL_AVAILABLE (only returns available SKUs) and ALL (returns all product's SKUs).ALL_AVAILABLE
simulationBehaviorEnumDefines whether the search data will be up-to-date (default) or fetched using the Cache (skip). The last option should be used only if you prefer faster queries over no having the most up-to-date prices or inventory.default
installmentCriteriaEnumControls what price should be shown when there are different installments options for it. Possible values are: MAX_WITHOUT_INTEREST (displayes the maximum installment option with no interest attached) or MAX_WITH_INTEREST (displayes the maximum installment option whether it has interest attached or not)."MAX_WITHOUT_INTEREST"

Now it is time to structure the search-result-layout block (or the search-result-layout.customQuery). They both necessarily require a child: the search-result-layout.desktop. But you can also provide others, such as the search-result-layout.mobile and the search-not-found-layout.

Since these are layout blocks, you can use Flex Layout blocks to build your search results page.

Step 4 - Defining your search results page layouts and behavior

Structure the search-result-layout or the search-result-layout.customQuery, according to your store's scenario, by declaring their children and then configuring them using Flex Layout blocks and their props. For example:


_19
{
_19
"search-result-layout": {
_19
"blocks": [
_19
"search-result-layout.desktop",
_19
"search-result-layout.mobile",
_19
"search-not-found-layout"
_19
]
_19
},
_19
"search-result-layout.desktop": {
_19
"children": [
_19
"flex-layout.row#searchbread",
_19
"flex-layout.row#searchtitle",
_19
"flex-layout.row#result"
_19
],
_19
"props": {
_19
"preventRouteChange": true
_19
}
_19
}
_19
}

Available props for search-result-layout.desktop, search-result-layout.mobile and search-not-found-layout:

Prop nameTypeDescriptionDefault value
hiddenFacetsObjectIndicates which filters should be hidden. Possible props and their respective values can be found below.undefined.
showFacetQuantitybooleanWhether the result amount in each filter should appear besides its name on the filter-navigator.v3 block as (true) or (false)false
blockClassstringUnique block ID to be used in CSS customizationundefined
trackingIdstringID to be used in Google Analytics to track store metrics based on the Search Result block.Search result
mobileLayoutObjectControls how the search results page will be displayed to users when using the mobile layout. Possible props and their respective values can be found below.undefined
  • mobileLayout Object:
Prop nameTypeDescriptionDefault value
mode1EnumDefines the default layout for the mobile search results page. Possible values are: normal, small or inline.normal
mode2EnumDefines which layout will be set for the mobile search results page when users click on the layout selector button. Possible values also are: normal, small or inline.small
  • HiddenFacets Object:
Prop nameTypeDescriptionDefault value
brandsbooleanWhether Brand filters should be hidden (true) or not (false).false
categoriesbooleanWhether Category filters should be hidden (true) or not (false).false
priceRangebooleanWhether Price filters should be hidden (true) or not (false).false
specificationFiltersObjectIndicates which Specification filters should be hidden.undefined
  • SpecificationFilters Object:
Prop nameTypeDescriptionDefault value
hideAllbooleanWhether specification filters should be hidden (true) or not (false).false
hiddenFilters[string]String array of specification filters that should be hidden.undefined
  • HiddenFilters String array:
Prop nameTypeDescriptionDefault value
namestringName of the specification filter that you want to hide.undefined

Step 5 - Using the Flex Layout to build your search results page

From Flex Layout, you will build your search results page using the other blocks that were exported by the Search Result app, such as: gallery, filter-navigator.v3, etc.

Therefore, don't forget to check out the Flex Layout documentation for more on how to configure your search results page.

Below you can find the existing props for each of the blocks, in addition to the the rules that govern them.

  • gallery block

The gallery block does not have its own props, but it has its own inner block structure that must be configured using a product-summary-shelf.

This means that any gallery block implementation created must have a product-summary-shelf that in turn must also have its own inner block structure that can be configured.

Check out the Product Summary documentation.

  • filter-navigator.v3 block
Prop nameTypeDescriptionDefault value
layoutEnumWhether the Filter Navigator layout should be responsive (responsive) or not (desktop). You may use desktop when the Filter Navigator was configured to be displayed in a drawer.responsive
maxItemsDepartmentnumberMaximum number of departments to be displayed before the See More button is triggered.8
maxItemsCategorynumberMaximum number of category items to be displayed before the See More button is triggered.8
initiallyCollapsedBooleanMakes the search filters start out collapsed (true) or open (false).false
  • order-by block
Prop nameTypeDescriptionDefault value
hiddenOptions[string]Indicates which sorting options will be hidden. (e.g. ["OrderByNameASC", "OrderByNameDESC"])undefined

The sorting options are:

Sort optionValue
Relevance"OrderByScoreDESC"
Top Sales Descending"OrderByTopSaleDESC"
Release Date Descending"OrderByReleaseDateDESC"
Best Discount Descending"OrderByBestDiscountDESC"
Price Descending"OrderByPriceDESC"
Price Ascending"OrderByPriceASC"
Name Ascending"OrderByNameASC"
Name Descending"OrderByNameDESC"
  • search-fetch-more block The "Show More" button that is used to load the results of the next search page. This block is not rendered if there is no next page. Does not need any prop.
  • search-fetch-previous block The "Show Previous" button that is used to load the results of the previous search page. This block is not rendered if there is no previous page. Does not need any prop.
  • search-products-count-per-page block Shows the product count per search page. Does not need any prop.
  • search-products-progress-bar block Shows a progress bar of search results. Does not need any prop.
  • sidebar-close-button block Close button rendered on the top right of the mobile filter sidebar.
Prop nameTypeDescriptionDefault value
sizenumberThe size of the button icon30
typestringThe type of the button iconline

Customization

In order to apply CSS customization in this and other blocks, follow the instructions given in the recipe on Using CSS Handles for store customization.

CSS handles
accordionFilterItemActive
accordionFilterItemBox
accordionFilterItemHidden
accordionFilterItemIcon
accordionFilterItemOptions
accordionFilterItemTitle
accordionFilterItem
accordionFilter
border
breadcrumb
buttonShowMore
categoriesContainer
categoryGroup
categoryParent
container
dropdownMobile
filter
filterAccordionBreadcrumbs
filterAccordionItemBox
filterApplyButtonWrapper
filterAvailable
filterButtonsBox
filterClearButtonWrapper
filterContainer-- + FACET_TYPE
filterContainer--b
filterContainer--c
filterContainer--priceRange
filterContainer--selectedFilters
filterContainer--title
filterContainer
filterIcon
filterItem-- + FACET_VALUE
filterItem--selected
filterItem
filterMessage
filterPopup
filterPopupArrowIcon
filterPopupButton
filterPopupContent
filterPopupContentContainer
filterPopupContentContainerOpen
filterPopupFooter
filterPopupOpen
filterPopupTitle
filterSelected
filtersWrapper
filtersWrapperMobile
filterTemplateOverflow
filterTitle
footerButton
galleryItem
galleryTitle
gallery
layoutSwitcher
loadingOverlay
loadingSpinnerInnerContainer
loadingSpinnerOuterContainer
orderByButton
orderByDropdown
orderByOptionItem
orderByOptionsContainer
orderByText
orderBy
progressBarContainer
progressBar
progressBarFiller
resultGallery
searchNotFoundInfo
searchNotFoundOops
searchNotFoundTerm
searchNotFoundTextListLine
searchNotFoundWhatDoIDo
searchNotFoundWhatToDoDotsContainer
searchNotFoundWhatToDoDots
searchNotFound
searchResultContainer
selectedFilterItem
showingProductsContainer
showingProductsCount
showingProducts
switch
totalProductsMessage
totalProducts
See also
VTEX App Store
VTEX IO Apps