fix: dont hardcode search fields
FullTextSearch uses name and content WebsiteSearch uses title and content Tests were failing because of hardcoded fieldnames which can't be overridden by inheriting class without rewriting search function. Made a separate function for defining search fields.
This commit is contained in:
parent
56f5b3d1f3
commit
4ef4ecdf01
2 changed files with 7 additions and 1 deletions
|
|
@ -23,6 +23,9 @@ class FullTextSearch:
|
|||
def get_schema(self):
|
||||
return Schema(name=ID(stored=True), content=TEXT(stored=True))
|
||||
|
||||
def get_fields_to_search(self):
|
||||
return ["name", "content"]
|
||||
|
||||
def get_id(self):
|
||||
return "name"
|
||||
|
||||
|
|
@ -121,7 +124,7 @@ class FullTextSearch:
|
|||
out = []
|
||||
|
||||
with ix.searcher() as searcher:
|
||||
parser = MultifieldParser(["title", "content"], ix.schema, termclass=FuzzyTermExtended)
|
||||
parser = MultifieldParser(self.get_fields_to_search(), ix.schema, termclass=FuzzyTermExtended)
|
||||
parser.remove_plugin_class(FieldsPlugin)
|
||||
parser.remove_plugin_class(WildcardPlugin)
|
||||
query = parser.parse(text)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ class WebsiteSearch(FullTextSearch):
|
|||
title=TEXT(stored=True), path=ID(stored=True), content=TEXT(stored=True)
|
||||
)
|
||||
|
||||
def get_fields_to_search(self):
|
||||
return ["title", "content"]
|
||||
|
||||
def get_id(self):
|
||||
return "path"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue