Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/demo/src/routes/ProductPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export const ProductPage: React.FC = () => {
? [`brand:${selectedFacetValue}`]
: [],
}}
fallbackParameters={{
facetFilters: [`brand:${selectedProduct.brand}`],
}}
view={({ itemComponent, items }) => (
<BundleView
currentItem={selectedProduct}
Expand Down
3 changes: 3 additions & 0 deletions examples/js-demo/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ function renderRecommendations(selectedProduct: ProductHit) {
analytics: true,
clickAnalytics: true,
},
fallbackParameters: {
facetFilters: [`brand:${selectedProduct.brand}`],
},
fallbackComponent() {
return (
relatedProducts<ProductHit>({
Expand Down
12 changes: 10 additions & 2 deletions packages/recommend-core/src/getFrequentlyBoughtTogether.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { FrequentlyBoughtTogetherQuery } from '@algolia/recommend';
import {
FrequentlyBoughtTogetherQuery,
RecommendationsQuery,
} from '@algolia/recommend';

import { RecommendationsProps } from './getRecommendations';
import { ProductRecord } from './types';
Expand All @@ -10,18 +13,23 @@ import { version } from './version';
export type GetFrequentlyBoughtTogetherProps<
TObject
> = RecommendationsProps<TObject> &
Omit<FrequentlyBoughtTogetherQuery, 'objectID'>;
Omit<FrequentlyBoughtTogetherQuery, 'objectID'> & {
// add fallback parameters manually as it is not supported in @algolia/recommend v4
fallbackParameters?: RecommendationsQuery['fallbackParameters'];
};

export function getFrequentlyBoughtTogether<TObject>({
objectIDs,
recommendClient,
transformItems = (x) => x,
fallbackParameters,
indexName,
maxRecommendations,
queryParameters,
threshold,
}: GetFrequentlyBoughtTogetherProps<TObject>) {
const queries = objectIDs.map((objectID) => ({
fallbackParameters,
indexName,
maxRecommendations,
objectID,
Expand Down