From bd4729144e7c782d58d9e1d6257df6103bb8f447 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 5 Jul 2018 12:11:48 +0100 Subject: [PATCH] Minor python optimisation --- wagtail/contrib/postgres_search/backend.py | 9 +++++---- wagtail/search/backends/db.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wagtail/contrib/postgres_search/backend.py b/wagtail/contrib/postgres_search/backend.py index 1c5fa0cfe7..422888b27e 100644 --- a/wagtail/contrib/postgres_search/backend.py +++ b/wagtail/contrib/postgres_search/backend.py @@ -189,6 +189,10 @@ class Index: class PostgresSearchQueryCompiler(BaseSearchQueryCompiler): DEFAULT_OPERATOR = 'and' + OPERATORS = { + 'and': AND, + 'or': OR, + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -237,10 +241,7 @@ class PostgresSearchQueryCompiler(BaseSearchQueryCompiler): if isinstance(query, PlainText): self.check_boost(query, boost=boost) - operator = { - 'and': AND, - 'or': OR, - }[query.operator] + operator = self.OPERATORS[query.operator] return operator([ PostgresSearchQuery(unidecode(term), config=config) diff --git a/wagtail/search/backends/db.py b/wagtail/search/backends/db.py index c3909bcf5c..d1bd065088 100644 --- a/wagtail/search/backends/db.py +++ b/wagtail/search/backends/db.py @@ -13,6 +13,10 @@ from wagtail.search.utils import AND, OR class DatabaseSearchQueryCompiler(BaseSearchQueryCompiler): DEFAULT_OPERATOR = 'and' + OPERATORS = { + 'and': AND, + 'or': OR, + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -64,10 +68,7 @@ class DatabaseSearchQueryCompiler(BaseSearchQueryCompiler): if isinstance(query, PlainText): self.check_boost(query, boost=boost) - operator = { - 'and': AND, - 'or': OR, - }[query.operator] + operator = self.OPERATORS[query.operator] return operator([ self.build_single_term_filter(term)