diff --git a/django_mongodb/query.py b/django_mongodb/query.py index 7b86360..70ffaee 100644 --- a/django_mongodb/query.py +++ b/django_mongodb/query.py @@ -194,7 +194,33 @@ def _get_mongo_search(self, compiler, connection) -> dict: query = [expression.value for expression in lhs_expressions] # weight = lhs.weight # config = lhs.config - search_query = {"wildcard": {"path": columns, "query": query}} + auto_complete_columns = [ + key + for key, value in self.mongo_meta["search_fields"].items() + if "autocomplete" in value + ] + query_columns = [ + key + for key, value in self.mongo_meta["search_fields"].items() + if "string" in value and key not in auto_complete_columns + ] + search_query = dict() + if auto_complete_columns and query_columns: + search_query = { + "compound": { + "should": [ + {"wildcard": {"path": columns, "query": query}}, + *[ + {"autocomplete": {"path": column, "query": query}} + for column in auto_complete_columns + ], + ] + } + } + elif auto_complete_columns: + search_query = {"autocomplete": {"path": auto_complete_columns, "query": query}} + elif query_columns: + search_query = {"wildcard": {"path": columns, "query": query}} return search_query diff --git a/pyproject.toml b/pyproject.toml index 5d723c3..550dd7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ classifiers = [ "Intended Audience :: Developers", "Operating System :: OS Independent", ] -version = "0.24" +version = "0.24.1" description = "" authors = ["gersmann"] readme = "README.md"