Skip to content

Commit 8c38c3c

Browse files
fix: search page results
1 parent 13b9eb1 commit 8c38c3c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/_includes/assets/js/search-results.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
document.addEventListener('DOMContentLoaded', async () => {
2+
const { liteClient } = window['algoliasearch/lite'];
3+
4+
const searchClient = liteClient(
5+
'{{ secrets.algoliaAppId }}',
6+
'{{ secrets.algoliaAPIKey }}'
7+
);
28
const urlParams = new URLSearchParams(window.location.search);
39
const queryStr = urlParams.get('query') || '';
410
const postFeed = document.querySelector('.post-feed');
@@ -18,16 +24,18 @@ document.addEventListener('DOMContentLoaded', async () => {
1824
return mockHits;
1925
}
2026

21-
// eslint-disable-next-line no-undef
22-
return index
23-
.search({
27+
const response = await searchClient.search([
28+
{
29+
indexName: '{{ secrets.algoliaIndex }}',
2430
query: queryStr,
25-
hitsPerPage: postsPerPage,
26-
page: pageNo
27-
})
28-
.then(({ hits } = {}) => {
29-
return hits;
30-
});
31+
params: {
32+
hitsPerPage: postsPerPage,
33+
page: pageNo
34+
}
35+
}
36+
]);
37+
38+
return response?.results[0]?.hits;
3139
} catch (err) {
3240
console.log(err);
3341
err.debugData ? console.log(err.debugData) : '';

0 commit comments

Comments
 (0)