Fix bug when searching for phrases. Resolves #152.
authorAdam Dullage <redacted>
Mon, 5 Feb 2024 21:25:35 +0000 (21:25 +0000)
committerAdam Dullage <redacted>
Mon, 5 Feb 2024 21:25:35 +0000 (21:25 +0000)
server/notes/file_system/file_system.py

index 0533120ef1d09f1bb475fc03a75133f14932c47a..7c39855f34be43d2ca54abd8322ae0e1a0e5a49e 100644 (file)
@@ -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') "
git clone https://git.99rst.org/PROJECT