Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"files": [
{
"path": "packages/algoliasearch-helper/dist/algoliasearch.helper.js",
"maxSize": "43 kB"
"maxSize": "43.25 kB"
},
{
"path": "packages/algoliasearch-helper/dist/algoliasearch.helper.min.js",
"maxSize": "13.75 kB"
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.production.min.js",
"maxSize": "121.25 kB"
"maxSize": "121.5 kB"
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.development.js",
Expand Down
15 changes: 15 additions & 0 deletions packages/algoliasearch-helper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,21 @@ declare namespace algoliasearchHelper {
_rawResults: Array<SearchResponse<T>>;
_state: SearchParameters;

/**
* The feed identifier, present when this result comes from a multifeed composition response.
*/
feedID?: string;

/**
* Map of feed ID to SearchResults, populated when the composition response contains multiple feeds.
*/
_feedResults?: Record<string, SearchResults>;

/**
* Ordered list of feed IDs matching the composition response order.
*/
_feedOrder?: string[];

/**
* Marker which can be added to search results to identify them as created without a search response.
* This is for internal use, e.g., avoiding caching in infinite hits, or delaying the display of these results.
Expand Down
36 changes: 29 additions & 7 deletions packages/algoliasearch-helper/src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,8 @@ AlgoliaSearchHelper.prototype._runComposition = function () {

states.push({
state: derivedState,
queriesCount: derivedStateQueries.length,
// Infinity so splice grabs all feed results from a multifeed composition response
queriesCount: Infinity,
helper: derivedHelper,
});

Expand Down Expand Up @@ -1884,12 +1885,33 @@ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
return;
}

helper.lastResults = new SearchResults(
state,
specificResults,
self._searchResultsOptions
);
if (rawContent !== undefined) helper.lastResults._rawContent = rawContent;
// Multifeed composition: build per-feed SearchResults map
if (specificResults.length > 0 && specificResults[0].feedID) {
var feedResults = {};
var feedOrder = specificResults.map(function (r) {
return r.feedID;
});
specificResults.forEach(function (r) {
var sr = new SearchResults(state, [r], self._searchResultsOptions);
if (rawContent !== undefined) sr._rawContent = rawContent;
feedResults[r.feedID] = sr;
});
helper.lastResults = new SearchResults(
state,
[specificResults[0]],
self._searchResultsOptions
);
if (rawContent !== undefined) helper.lastResults._rawContent = rawContent;
helper.lastResults._feedResults = feedResults;
helper.lastResults._feedOrder = feedOrder;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not overly sold on putting this behind _ keys that we then need to explicitly handle in the implementation. It's ok bu have you considered helper.feeds = feedResults (as an array) directly? then still setting lastResults to the main one. that way it feels like more of a proper implementation rather than an add on.

also why is there the results and the order needed separately? could it be just a single array that in case you have a feature of displaying just a single feed it just does find in the array.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

as discussed I went with helper.lastResults.feeds so that feeds are automatically serialised when SSR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

since its now one property only I added back feeds on to SearchResults (with dedicated extended typing).
let me know if that works for you

} else {
helper.lastResults = new SearchResults(
state,
specificResults,
self._searchResultsOptions
);
if (rawContent !== undefined) helper.lastResults._rawContent = rawContent;
}

helper.emit('result', {
results: helper.lastResults,
Expand Down
Loading
Loading