从现在开始,你可以使用Algolia的建议 从InstantSearch,简化你的整合 两个图书馆!
学习如何随行迁徙 升级指南。 。 。 .
import instantsearch from 'instantsearch.js';
import {
frequentlyBoughtTogether,
relatedProducts,
} from 'instantsearch.js/es/widgets';
import algoliasearch from 'algoliasearch/lite';
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
instantsearch({
// No need for a recommendClient anymore
searchClient,
indexName,
}).addWidgets([
frequentlyBoughtTogether({
container: '#frequentlyBoughtTogether',
objectIDs: [currentObjectID],
}),
relatedProducts({
container: '#relatedProducts',
objectIDs: [currentObjectID],
}),
]);
@algolia/recommend-js
JavaScript 软件包 阿尔戈利亚建议。 。 。 .
安装
所有推荐软件包均可在 无 登记.
yarn add @algolia/recommend-js
# or
npm install @algolia/recommend-js
使用量
要开始,需要有一个容器供你的建议进入——在这个指南中,一个用于经常共同购买,一个用于相关产品。 如果你还没有容器,你可以把它们插入你的标记:
<div id="frequentlyBoughtTogether"></div>
<div id="relatedProducts"></div>
然后,插入你的建议,即: frequentlyBoughtTogether 函数和提供 container它可能是一个 CSS 选择器 或一个 元素。 。 。 .
过程是相同的 relatedProducts。 。 。 .
/** @jsx h */
import { h } from 'preact';
import {
frequentlyBoughtTogether,
relatedProducts,
} from '@algolia/recommend-js';
import recommend from '@algolia/recommend';
const recommendClient = recommend('YourApplicationID', 'YourSearchOnlyAPIKey');
const indexName = 'YOUR_INDEX_NAME';
const currentObjectID = '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>
);
},
});
继续读我们 开始 向导.
文档
这个 文档 提供一些了解建议图书馆的方法:
- 跟着 构建您的推荐 UI 指南 在您的网站上显示推荐.
- 参见 API 参考 为综合参数和选项清单.