Skip to content

Commit

Permalink
feat: add arg and setting to trigger more complete search log
Browse files Browse the repository at this point in the history
we don't want to trigger logging on every single ES search
or force logging into other courseware search uses, so
arg + setting just for courseware search
  • Loading branch information
ashultz0 committed Nov 15, 2023
1 parent 4ef312e commit ba8ee78
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def perform_course_search(
)
if not searcher:
raise NoSearchEngineError("No search engine specified in settings.SEARCH_ENGINE")
log_search_params = getattr(settings, "SEARCH_COURSEWARE_CONTENT_LOG_PARAMS", False)

results = searcher.search(
query_string=search_term,
Expand All @@ -70,6 +71,7 @@ def perform_course_search(
exclude_dictionary=exclude_dictionary,
size=size,
from_=from_,
log_search_params=log_search_params,
)

# post-process the result
Expand Down
4 changes: 4 additions & 0 deletions search/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def search(self,
aggregation_terms=None,
exclude_ids=None,
use_field_match=False,
log_search_params=False,
**kwargs): # pylint: disable=arguments-differ, unused-argument
"""
Implements call to search the index for the desired content.
Expand Down Expand Up @@ -653,6 +654,9 @@ def search(self,
if aggregation_terms:
body["aggs"] = _process_aggregation_terms(aggregation_terms)

if log_search_params:
log.info(f"full elastic search body {body}")

try:
es_response = self._es.search(index=self._prefixed_index_name, body=body, **kwargs)
except exceptions.ElasticsearchException as ex:
Expand Down
1 change: 1 addition & 0 deletions search/search_engine_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def search(self,
filter_dictionary=None,
exclude_dictionary=None,
aggregation_terms=None,
log_search_params=False,
**kwargs): # pylint: disable=too-many-arguments
"""
Search for matching documents within the search index.
Expand Down
1 change: 1 addition & 0 deletions search/tests/mock_search_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def search(self,
filter_dictionary=None,
exclude_dictionary=None,
aggregation_terms=None,
log_search_params=False,
**kwargs): # pylint: disable=too-many-arguments
"""
Perform search upon documents within index.
Expand Down

0 comments on commit ba8ee78

Please sign in to comment.