From feea8f97baf2210d3815690fba91f8d942cc8e13 Mon Sep 17 00:00:00 2001
From: Gabriela Bittencourt <gabrielabittencourt00@gmail.com>
Date: Sun, 28 Mar 2021 20:29:23 +0200
Subject: [PATCH] Add priority in search query and add word expansion

Chosen priority: title > keywords > description. The chosen weights
(boost parameters) were chosen arbitrarily based on manual iterations
and could be improved.

Word expansion was enabled in title and keywords fields to allow
matching of parts of a word.
---
 pd/nw/dialog_search.html | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/pd/nw/dialog_search.html b/pd/nw/dialog_search.html
index c882574b6..0d49f09f6 100644
--- a/pd/nw/dialog_search.html
+++ b/pd/nw/dialog_search.html
@@ -858,7 +858,13 @@ function doc_search() {
     clear_results();
     text_elem.blur();
     toc_bookmark_status(false);
-    results = index.search(search_text);
+    results = index.search(search_text, {
+        fields: {
+            title: {boost: 64, expand: true},
+            keywords: {boost: 8, expand: true},
+            description: {boost: 1}
+        }
+    });
     for (i = 0; i < results.length; i++) {
         doc = index.documentStore.getDoc(results[i].ref);
         display_doc(doc);
-- 
GitLab