Skip to content
Draft
Changes from 4 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
54 changes: 54 additions & 0 deletions implementing-nosto/implement-search/search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,58 @@ Tracking product clicks is fundamental for understanding user interaction. Use `

In case of an SPA based integration the `api.recordSearchClick` calls should be complemented with Session API or `api.createRecommendationRequest()` usage to couple the search analytics events to generic Nosto events for accurate attribution.

## Fallback mechanism

For JS API integrations, there is no built-in fallback functionality. Merchants need to build this themselves to ensure a robust search experience.

### When to implement fallbacks

You should implement fallback mechanisms in the following scenarios:

* **Search query errors**: When the search API returns an error response
* **Timeout scenarios**: When the search query takes longer than 1 second to return results

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention that JS API based Search requests timeout after 5 seconds

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the timeout scenario to mention that JS API based Search requests timeout after 5 seconds as requested. The line now provides accurate information about the actual API timeout behavior. Changes committed in b9c4f21.

* **Network connectivity issues**: When there are network problems preventing API calls

### Implementation considerations

* **Error handling**: Always wrap Nosto search calls in try-catch blocks
* **Timeout management**: Implement reasonable timeout values (recommended: 1 second)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the timeout management line as requested. The bullet point about "recommended: 1 second" has been removed from Implementation considerations. Changes committed in b9c4f21.

* **User experience**: Ensure seamless transition to fallback without visible errors
* **Analytics**: Track fallback usage to monitor search performance

### Category merchandising fallbacks
Copy link

@timowestnosto timowestnosto Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot drop the "Category merchandising fallbacks" section

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the "Category merchandising fallbacks" section as requested. The section and its content have been completely removed. Changes committed in a7d4f85.


The same fallback principles apply to category merchandising implementations. When using the search API for category pages, implement similar timeout and error handling:

```javascript

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this code snippet

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the JavaScript code snippet as requested. The getCategoryProductsWithFallback() function example has been removed. Changes committed in a7d4f85.

async function getCategoryProductsWithFallback(categoryId, options = {}) {
try {
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error('Category search timeout')), 1000);
});

const categoryPromise = new Promise((resolve, reject) => {
nostojs(api => {
api.search({
products: {
categoryId: categoryId,
fields: ['name', 'url', 'price'],
size: options.size || 24
}
}, {
track: 'category'
}).then(resolve).catch(reject);
});
});

return await Promise.race([categoryPromise, timeoutPromise]);

} catch (error) {
console.warn('Nosto category search failed, falling back:', error);
// Fallback to native category page logic
return await executeNativeCategoryFallback(categoryId, options);
}
}
```

***