You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ki...@apache.org on 2023/04/07 11:09:36 UTC

[jena-site] 03/03: Display score, tweak search parameters, more comments

This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena-site.git

commit dd32b8a44ec71ba8bc94424da9e55d2b82b5f12e
Author: Bruno P. Kinoshita <ki...@users.noreply.github.com>
AuthorDate: Sun Feb 12 18:05:10 2023 +0100

    Display score, tweak search parameters, more comments
---
 layouts/_default/baseof.html |  1 +
 layouts/_default/search.html | 59 ++++++++++++++++++++++++++++----------------
 2 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 497ee4b2c..df7a90076 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -185,6 +185,7 @@
 <script type="text/javascript">
 (function() {
     'use strict'
+    // Active menu items.
     /*
      * Find the link in the menu that corresponds to the currently open page.
      * NOTE: We call .querySelectorAll because we may have more than one link
diff --git a/layouts/_default/search.html b/layouts/_default/search.html
index ba98c9870..191b5e04e 100644
--- a/layouts/_default/search.html
+++ b/layouts/_default/search.html
@@ -7,7 +7,8 @@
   <script id="search-result-template" type="text/x-js-template">
     <div id="summary-${key}">
       <h3><a href="${link}">${title}</a></h3>
-      <p>${snippet}</p>
+      <p class="pb-0 mb-0">${snippet}</p>
+      <p class="opacity-50 pt-0 mt-0"><small>Score: ${score}</small></p>
       <p>
         <small>
           ${ isset tags }Tags: ${tags}<br>${ end }
@@ -23,35 +24,51 @@
       const summaryInclude = 180;
       // See: https://fusejs.io/api/options.html
       const fuseOptions = {
-        // Whether to sort the result list, by score.
-        shouldSort: true,
+        // Indicates whether comparisons should be case sensitive.
+        isCaseSensitive: false,
+        // Whether the score should be included in the result set.
+        // A score of 0 indicates a perfect match, while a score of 1 indicates a complete mismatch.
+        includeScore: true,
         // Whether the matches should be included in the result set.
         // When true, each record in the result set will include the indices of the matched characters.
         // These can consequently be used for highlighting purposes.
         includeMatches: true,
-        // Whether the score should be included in the result set.
-        // A score of 0 indicates a perfect match, while a score of 1 indicates a complete mismatch.
-        includeScore: true,
-        // Determines approximately where in the text is the pattern expected to be found.
-        location: 0,
-        // Determines how close the match must be to the fuzzy location (specified by location).
-        // An exact letter match which is distance characters away from the fuzzy location would
-        // score as a complete mismatch.
-        // A distance of 0 requires the match be at the exact location specified.
-        // A distance of 1000 would require a perfect match to be within 800 characters of the
-        // location to be found using a threshold of 0.8.
-        distance: 100,
         // Only the matches whose length exceeds this value will be returned.
         // (For instance, if you want to ignore single character matches in the result, set it to 2).
         minMatchCharLength: 2,
+        // Whether to sort the result list, by score.
+        shouldSort: true,
         // List of keys that will be searched.
         // This supports nested paths, weighted search, searching in arrays of strings and objects.
         keys: [
-          {name: "title", weight: 0.5},
-          {name: "contents", weight: 0.4},
-          {name: "tags", weight: 0.95},
-          {name: "categories", weight: 0.05}
+          {name: "title", weight: 0.8},
+          {name: "contents", weight: 0.7},
+          // {name: "tags", weight: 0.95},
+          // {name: "categories", weight: 0.05}
         ],
+        // --- Fuzzy Matching Options
+        // Determines approximately where in the text is the pattern expected to be found.
+        location: 0,
+        // At what point does the match algorithm give up.
+        // A threshold of 0.0 requires a perfect match (of both letters and location),
+        // a threshold of 1.0 would match anything.
+        threshold: 0.2,
+        // Determines how close the match must be to the fuzzy location (specified by location).
+        // An exact letter match which is distance characters away from the fuzzy location would
+        // score as a complete mismatch. A distance of 0 requires the match be at the exact
+        // location specified. A distance of 1000 would require a perfect match to be within 800
+        // characters of the location to be found using a threshold of 0.8.
+        distance: 100,
+        // When true, search will ignore location and distance, so it won't matter where in
+        // the string the pattern appears.
+        //
+        // NOTE: These settings are used to calculate the Fuzziness Score (Bitap algorithm) in Fuse.js.
+        //       It calculates threshold (default 0.6) * distance (default (100), which gives 60 by
+        //       default, meaning it will search for the query-term within 60 characters from the location
+        //       (default 0). Since Jena docs may have very long text that includes the query term anywhere
+        //       we disable it with ignoreLocation: true.
+        //       For more: https://fusejs.io/concepts/scoring-theory.html#scoring-theory
+        ignoreLocation: true,
       };
 
       // =============================
@@ -106,7 +123,6 @@
         const templateDefinition = document.getElementById("search-result-template").innerHTML;
 
         results.forEach(function (value, key) {
-
           const contents = value.item.contents;
           let snippet = "";
           const snippetHighlights = [];
@@ -128,7 +144,8 @@
             link: value.item.permalink,
             tags: tags,
             categories: value.item.categories,
-            snippet: snippet
+            snippet: snippet,
+            score: value.score
           });
           searchResults.innerHTML += output;