From 9594c1812fed415b65c0256556f32ddce1e84436 Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Mon, 27 Feb 2023 15:05:39 +0000
Subject: [PATCH] enable algolia search #98
---
assets/js/search/variables.js | 38 +++++++++++++++++---------------------
1 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/assets/js/search/variables.js b/assets/js/search/variables.js
index 80b12cc..758829c 100644
--- a/assets/js/search/variables.js
+++ b/assets/js/search/variables.js
@@ -2,6 +2,8 @@
const empty_string = '';
const search_field_class = '.search_field';
const search_class = '.search';
+let search_term = empty_string;
+const search_field = elem(search_field_class);
// defined in i18n / translation files
const quick_links = '{{ T "quick_links" }}';
@@ -21,26 +23,20 @@
other_searchable_fields = [];
}
+const search_page_element = elem('#searchpage');
+
+// Fuse specific
+let search_keys = ['body', 'title', 'link', 'section', 'id',];
+search_keys = search_keys.concat(other_searchable_fields);
+
+const search_options = {
+ ignoreLocation: true,
+ findAllMatches: true,
+ includeScore: true,
+ shouldSort: true,
+ keys: search_keys,
+ threshold: 0.1
+};
+
// Algolia specific
const algolia_config = JSON.parse(`{{ partialCached "functions/getAlgoliaConfig" . }}`);
-
-function initAlgoliaSearch() {
- const algolia_client = algoliasearch(algolia_config.id, algolia_config.key);
- const algolia_index = algolia_client.initIndex(algolia_config.index);
-
- // Fuse specific
-
- // Search for "query string" in the index "contacts"
- algolia_index.search('custom css').then(({ hits }) => {
- console.log(hits);
- });
-
- // Perform the same search, but only retrieve 50 results
- // Return only the attributes "firstname" and "lastname"
- algolia_index.search('query string', {
- attributesToRetrieve: ['firstname', 'lastname'],
- hitsPerPage: 50,
- }).then(({ hits }) => {
- console.log(hits);
- });
-}
--
Gitblit v1.10.0