Collection search page
Since December 31, 2023, apps can’t modify the code of Shopify themes. For more information, see The Asset API resource in the Shopify documentation. As an alternative, the Algolia AI Search and Discovery app comes with Shopify App Embed and App Blocks to integrate Autocomplete and InstantSearch. To get started, see Quickstart and Algolia configuration.
With the Algolia AI Search & Discovery app for Shopify, you can enhance your collection pages with real-time search.
Collection search pages list products from a collection.
Usually, they have URLs with the following pattern: /collection/<collection-name>
.
When you modify a collection, all products from the collection are reindexed. Enabling the collection search feature increases the number of indexing operations.
Shopify’s /collections/all
Page
Shopify automatically creates a page at /collections/all
that lists all your products.
To enable InstantSearch on this collection list page, you must create a collection called all
in the Shopify Admin.
Turn on Algolia on collection pages
You can enable Algolia on your Collections in one click. To get started, go to the Collection pages tab and click Enable.
Once the feature is enabled, all your products and collections will be reindexed to ensure that all required data is available.
Once the reindexing is done, InstantSearch will be enabled on your Collection pages. You can now configure how it behaves.
Configure Algolia on collection pages
Enabling the InstantSearch on collection pages
To enable the InstantSearch collections pages:
- Add the Algolia Search App Embed to your theme
- Add Algolia App Blocks. App Embed must first be enabled before the App Block will work.
Products to be displayed
The number of products to show per page for your collections.
Sort orders
In this section, you can choose which sort orders you want to activate for your collections, how you want to call them, and which ones you want to display first.
Ranking happens at indexing time. This means that for each sort order, a new index is created that contains as many records as the main one.
Please make sure that an increased record count won’t exceed your plan’s quota.
You can read the full guide on sorting for more detail.
On the Collection pages, the manual order defined in the Shopify admin won’t apply.
To customize the order, you can use the visual merchandising tool.
Facets
In this section, you can choose which facets to activate for your collections, how you want to call them, and which ones you want to display first.
Facets are primarily used to refine searches.
Configure to merchandise with Merchandising Studio
By default the Shopify category pages use the collection_ids
attribute as a category page identifier.
To create a more accessible interface to merchandise your categories, we advise changing the category page identifier to collections
.
-
Add a facet:
Add a custom facet called ‘collections’ with the Shopify-Algolia integration and set it as hidden and searchable:
-
Change the category page identifier:
You can configure the category page identifier on your Merchandising studio settings. To do this, go to Merchandising Studio > Settings > Category Page Identifiers and change the Category Page Identifier to
collections
. -
Change your frontend code:
Add a custom hook to your Shopify theme to update the search filter using the
beforeInstantSearchFiltersString
hook:Copy1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
document.addEventListener('algolia.hooks.initialize', function() { algoliaShopify.hooks.registerHook('beforeInstantSearchFiltersString', function(defaultFilter) { if (defaultFilter && defaultFilter.includes("collection_ids")) { const collectionIDFilterRegex = /collection_ids:"\w+"/g; const matches = window.location.pathname.match(/\/collections\/([^/]+)/i); const collectionHandle = (matches && matches.length === 2) ? matches[1] : null; if (collectionHandle) { return defaultFilter.replace( collectionIDFilterRegex, "collections:" + collectionHandle ); } } return defaultFilter; }); });
Then, on your collection pages you should be able to see this filter being applied:
Turn off Algolia on collection pages
To turn off Algolia on Collection pages, head to the section at the bottom of the page and click Disable. Your Collection pages will revert to their default layout, and InstantSearch will no longer show up.