Skip to content

Commit

Permalink
Merge pull request #1 from denpolischuk/fix/remove-duplicate-query
Browse files Browse the repository at this point in the history
WIP: remove second instance of "query" in the response "params" for SSR
  • Loading branch information
denpolischuk authored Jun 16, 2020
2 parents 91f2102 + 5f86e67 commit 1eb1479
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@ export default function createInstantSearchManager({
}
}

function removeDuplicateQuery(params) {
let previousIndex = undefined;
const queryParamRegex = /&?query=[^&]*/g;
return params.replace(queryParamRegex, function replacer(match, offset) {
if (previousIndex && offset > previousIndex) {
previousIndex = offset;
return '';
}
previousIndex = offset;
return match;
});
}

function hydrateSearchClient(client, results) {
if (!results) {
return;
Expand Down Expand Up @@ -385,7 +398,7 @@ export default function createInstantSearchManager({
acc.concat(
result.rawResults.map(request => ({
indexName: request.index,
params: request.params,
params: removeDuplicateQuery(request.params),
}))
),
[]
Expand Down Expand Up @@ -414,7 +427,7 @@ export default function createInstantSearchManager({
acc.concat(
result.rawResults.map(request => ({
indexName: request.index,
params: request.params,
params: removeDuplicateQuery(request.params),
}))
),
[]
Expand Down Expand Up @@ -442,7 +455,7 @@ export default function createInstantSearchManager({
args: [
results.rawResults.map(request => ({
indexName: request.index,
params: request.params,
params: removeDuplicateQuery(request.params),
})),
],
},
Expand All @@ -461,7 +474,7 @@ export default function createInstantSearchManager({
const key = `/1/indexes/*/queries_body_${JSON.stringify({
requests: results.rawResults.map(request => ({
indexName: request.index,
params: request.params,
params: removeDuplicateQuery(request.params),
})),
})}`;

Expand Down

0 comments on commit 1eb1479

Please sign in to comment.