Added rank property to search results
authorAdam Dullage <redacted>
Mon, 5 Sep 2022 17:12:57 +0000 (18:12 +0100)
committerAdam Dullage <redacted>
Mon, 5 Sep 2022 17:12:57 +0000 (18:12 +0100)
flatnotes/flatnotes.py
flatnotes/models.py
flatnotes/src/classes.js
flatnotes/src/components/SearchResults.vue

index 70fc4893f27502fb7de57c210e45209089788fd1..edb688b84dd34d78367ac92e8235ba6d9fea1593 100644 (file)
@@ -105,7 +105,7 @@ class SearchResult(Note):
         super().__init__(flatnotes, strip_ext(hit["filename"]))
 
         self._matched_fields = self._get_matched_fields(hit.matched_terms())
-
+        self._rank = hit.rank
         self._title_highlights = (
             hit.highlights("title", text=self.title)
             if "title" in self._matched_fields
@@ -125,6 +125,10 @@ class SearchResult(Note):
             else None
         )
 
+    @property
+    def rank(self):
+        return self._rank
+
     @property
     def title_highlights(self):
         return self._title_highlights
index 9798a52e67de3ca11626b543df61c17cedc8e291..f0d5abfeca8971cdc5a62932fd651bf3b351fe56 100644 (file)
@@ -30,6 +30,7 @@ class NotePatchModel(CamelCaseBaseModel):
 
 
 class SearchResultModel(CamelCaseBaseModel):
+    rank: int
     title: str
     last_modified: int
     title_highlights: Optional[str]
@@ -39,6 +40,7 @@ class SearchResultModel(CamelCaseBaseModel):
     @classmethod
     def dump(self, search_result: SearchResult) -> Dict:
         return {
+            "rank": search_result.rank,
             "title": search_result.title,
             "lastModified": search_result.last_modified,
             "titleHighlights": search_result.title_highlights,
index ecff15a5b09597cb6cb2d3a896ca6e5beb624beb..c5913f38edf689367a8786fa2bb39fdf7aa4a48f 100644 (file)
@@ -21,11 +21,12 @@ class Note {
 }
 
 class SearchResult extends Note {
-  constructor(title, lastModified, titleHighlights, contentHighlights, tagMatches) {
-    super(title, lastModified);
-    this.titleHighlights = titleHighlights;
-    this.contentHighlights = contentHighlights;
-    this.tagMatches = tagMatches;
+  constructor(searchResult) {
+    super(searchResult.title, searchResult.lastModified);
+    this.rank = searchResult.rank;
+    this.titleHighlights = searchResult.titleHighlights;
+    this.contentHighlights = searchResult.contentHighlights;
+    this.tagMatches = searchResult.tagMatches;
   }
 
   get titleHighlightsOrTitle() {
index 016ae8cdbf636076c7b5f7982333fa73aa09fade..e28e031e1f4f222356154e65abbc4b02c3865d64 100644 (file)
@@ -128,16 +128,8 @@ export default {
             parent.searchFailedMessage = "No Results";
             parent.searchFailed = true;
           } else {
-            response.data.forEach(function (result) {
-              parent.searchResults.push(
-                new SearchResult(
-                  result.title,
-                  result.lastModified,
-                  result.titleHighlights,
-                  result.contentHighlights,
-                  result.tagMatches
-                )
-              );
+            response.data.forEach(function (searchResult) {
+              parent.searchResults.push(new SearchResult(searchResult));
             });
           }
         })
git clone https://git.99rst.org/PROJECT