From: Adam Dullage Date: Mon, 5 Feb 2024 21:25:35 +0000 (+0000) Subject: Fix bug when searching for phrases. Resolves #152. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=d795bbfa1678e70c0622a296b262bc06eb588da0;p=flatnotes.git Fix bug when searching for phrases. Resolves #152. --- diff --git a/server/notes/file_system/file_system.py b/server/notes/file_system/file_system.py index 0533120..7c39855 100644 --- a/server/notes/file_system/file_system.py +++ b/server/notes/file_system/file_system.py @@ -116,7 +116,7 @@ class FileSystemNotes(BaseNotes): query = Every() else: parser = MultifieldParser( - ["title", "content", "tags"], self.index.schema + self._fieldnames_for_term(term), self.index.schema ) parser.add_plugin(DateParserPlugin()) query = parser.parse(term) @@ -339,6 +339,16 @@ class FileSystemNotes(BaseNotes): tag_matches=tag_matches, ) + def _fieldnames_for_term(self, term: str) -> List[str]: + """Return a list of field names to search based on the given term. If + the term includes a phrase then only search title and content. If the + term does not include a phrase then also search tags.""" + fields = ["title", "content"] + if '"' not in term: + # If the term does not include a phrase then also search tags + fields.append("tags") + return fields + @staticmethod def _get_matched_fields(matched_terms): """Return a set of matched fields from a set of ('field', 'term') "