From: Adam Dullage Date: Mon, 5 Sep 2022 17:12:57 +0000 (+0100) Subject: Added rank property to search results X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=635f31530abe60f0946be07fe8fce357dfaad373;p=flatnotes.git Added rank property to search results --- diff --git a/flatnotes/flatnotes.py b/flatnotes/flatnotes.py index 70fc489..edb688b 100644 --- a/flatnotes/flatnotes.py +++ b/flatnotes/flatnotes.py @@ -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 diff --git a/flatnotes/models.py b/flatnotes/models.py index 9798a52..f0d5abf 100644 --- a/flatnotes/models.py +++ b/flatnotes/models.py @@ -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, diff --git a/flatnotes/src/classes.js b/flatnotes/src/classes.js index ecff15a..c5913f3 100644 --- a/flatnotes/src/classes.js +++ b/flatnotes/src/classes.js @@ -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() { diff --git a/flatnotes/src/components/SearchResults.vue b/flatnotes/src/components/SearchResults.vue index 016ae8c..e28e031 100644 --- a/flatnotes/src/components/SearchResults.vue +++ b/flatnotes/src/components/SearchResults.vue @@ -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)); }); } })