Skip to content

Commit f7e6d16

Browse files
authored
Merge pull request #60 from AddSearch/sc-9613/support-new-recommendation-api-endpoint
feat: [sc-9613] Support new recommendation API in Search-UI and Js-Client
2 parents edcfc67 + 6561c6b commit f7e6d16

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

dist/addsearch-js-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "addsearch-js-client",
3-
"version": "0.8.10",
3+
"version": "0.8.11",
44
"description": "AddSearch API JavaScript client",
55
"main": "index.js",
66
"jsdelivr": "./dist/addsearch-js-client.min.js",

src/apifetch.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
146146
}
147147

148148
}
149+
api = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
149150
}
150151

151152
// Suggest
@@ -154,6 +155,7 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
154155
qs = settingToQueryParam(settings.suggestionsSize, 'size') +
155156
settingToQueryParam(settings.lang, 'lang');
156157
kw = settings.suggestionsPrefix;
158+
api = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
157159
}
158160

159161
// Autocomplete
@@ -162,18 +164,20 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
162164
qs = settingToQueryParam(settings.autocomplete.field, 'source') +
163165
settingToQueryParam(settings.autocomplete.size, 'size');
164166
kw = settings.autocomplete.prefix;
167+
api = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
165168
}
166169

167170
else if (type === 'recommend') {
168-
apiPath = 'recommendations';
169-
qs = settingToQueryParam(recommendOptions.itemId, 'itemId');
171+
if (recommendOptions.type === 'RELATED_ITEMS') {
172+
qs = settingToQueryParam(recommendOptions.itemId, 'itemId');
173+
apiPath = 'recommendations/index/' + sitekey + '/block/' + recommendOptions.blockId + '?' + qs;
174+
} else if (recommendOptions.type === 'FREQUENTLY_BOUGHT_TOGETHER') {
175+
qs = settingToQueryParam(recommendOptions.itemId, 'itemId');
176+
apiPath = 'recommendations/' + sitekey + '?configurationKey=' + recommendOptions.configurationKey + qs;
177+
}
178+
api = 'https://' + apiHostname + '/v1/' + apiPath;
170179
}
171180

172-
// Execute API call
173-
api = type === 'recommend' ?
174-
'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?configurationKey=' + recommendOptions.configurationKey + qs :
175-
'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs;
176-
177181
apiInstance.get(api)
178182
.then(function(response) {
179183
var json = response.data;

0 commit comments

Comments
 (0)