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
else None
)
+ @property
+ def rank(self):
+ return self._rank
+
@property
def title_highlights(self):
return self._title_highlights
class SearchResultModel(CamelCaseBaseModel):
+ rank: int
title: str
last_modified: int
title_highlights: Optional[str]
@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,
}
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() {
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));
});
}
})