Skip to content

Repository files navigation

🙌 From now on you can use Algolia Recommend from InstantSearch, simplifying your integration between the two libraries!

Learn how to migrate following the upgrade guide for JS or for React.

importinstantsearchfrom'instantsearch.js';import{frequentlyBoughtTogether,relatedProducts,}from'instantsearch.js/es/widgets';importalgoliasearchfrom'algoliasearch/lite';constsearchClient=algoliasearch('YourApplicationID','YourSearchOnlyAPIKey');instantsearch({// No need for a recommendClient anymore
searchClient,
indexName,}).addWidgets([frequentlyBoughtTogether({container: '#frequentlyBoughtTogether',objectIDs: [currentObjectID],}),relatedProducts({container: '#relatedProducts',objectIDs: [currentObjectID],}),]);
import{InstantSearch,FrequentlyBoughtTogether,RelatedProducts,}from'react-instantsearch';importalgoliasearchfrom'algoliasearch/lite';constsearchClient=algoliasearch('YourApplicationID','YourSearchOnlyAPIKey');functionApp(){return(<InstantSearchsearchClient={searchClient}indexName={indexName}><FrequentlyBoughtTogetherobjectIDs={[currentObjectID]}/><RelatedProductsobjectIDs={[currentObjectID]}/></InstantSearch>);}



Recommend

VersionMIT License

Recommend is the repository packaging the UI components for Algolia Recommend, available for Vanilla JavaScript and React.

Installation

All Recommend packages are available on the npm registry.

yarn add @algolia/recommend-js
# or
npm install @algolia/recommend-js

For React

yarn add @algolia/recommend-react
# or
npm install @algolia/recommend-react

Usage

To get started, you need a container for your recommendations to go in—in this guide, one for Frequently Bought Together, and one for Related Products. If you don't have containers already, you can insert them into your markup:

<divid="frequentlyBoughtTogether"></div><divid="relatedProducts"></div>

Then, insert your recommendations by calling the frequentlyBoughtTogether function and providing the container. It can be a CSS selector or an Element.

The process is the same for relatedProducts.

/** @jsx h */import{h}from'preact';import{frequentlyBoughtTogether,relatedProducts,}from'@algolia/recommend-js';importrecommendfrom'@algolia/recommend';constrecommendClient=recommend('YourApplicationID','YourSearchOnlyAPIKey');constindexName='YOUR_INDEX_NAME';constcurrentObjectID='YOUR_OBJECT_ID';frequentlyBoughtTogether({container: '#frequentlyBoughtTogether',
recommendClient,
indexName,objectIDs: [currentObjectID],itemComponent({ item }){return(<pre><code>{JSON.stringify(item)}</code></pre>);},});relatedProducts({container: '#relatedProducts',
recommendClient,
indexName,objectIDs: [currentObjectID],itemComponent({ item }){return(<pre><code>{JSON.stringify(item)}</code></pre>);},});

For React

Import the FrequentlyBoughtTogether and RelatedProducts and use them in your parent component.

importReactfrom'react';import{FrequentlyBoughtTogether,RelatedProducts,}from'@algolia/recommend-react';importrecommendfrom'@algolia/recommend';constrecommendClient=recommend('YourApplicationID','YourSearchOnlyAPIKey');constindexName='YOUR_INDEX_NAME';functionApp({ currentObjectID }){// ...return(<div><FrequentlyBoughtTogetherrecommendClient={recommendClient}indexName={indexName}objectIDs={[currentObjectID]}itemComponent={({ item })=>{return(<pre><code>{JSON.stringify(item)}</code></pre>);}}/><RelatedProductsrecommendClient={recommendClient}indexName={indexName}objectIDs={[currentObjectID]}itemComponent={({ item })=>{return(<pre><code>{JSON.stringify(item)}</code></pre>);}}/></div>);}

Continue reading our Getting Started guide.

Documentation

The documentation offers a few ways to learn about the Recommend library:

You can find more on the documentation.

Support

Packages

License

MIT

About

A UI library for Algolia Recommend, available for Vanilla JavaScript and React.

Topics

Resources

Code of conduct

Stars

28 stars

Watchers

41 watching

Forks

Packages

Used by

Contributors

Languages