-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix: Return empty dict when no highlight dict is present #5950
Hotfix: Return empty dict when no highlight dict is present #5950
Conversation
Ohhh... I just noticed. |
This should also increase the speed as that func is going through every highlight dict recursively and that too -- doing nothing. |
readthedocs/search/utils.py
Outdated
|
||
return highlight | ||
if logging: | ||
log.debug('API Search highlight: %s', pformat(highlight_dict)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just output it unformatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify this a bit.
readthedocs/search/utils.py
Outdated
|
||
return highlight | ||
if logging: | ||
log.debug('API Search highlight: %s', pformat(highlight_dict)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just output it unformatted.
readthedocs/search/api.py
Outdated
sorted_results = list(utils._get_sorted_results( | ||
results=all_results, | ||
source_key='_source', | ||
logging=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional logging feels weird. Do we ever not want logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably just log outside this function, and remove the logging from this function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
readthedocs/search/utils.py
Outdated
|
||
def _get_sorted_results(results, source_key='_source', logging=False): | ||
"""Sort results according to their score and return a generator expression.""" | ||
sorted_results = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this to be a generator? What is the goal of it versus just using a list? It looks like we're just calling list
on it both times we use it, which means it should probably just return a list :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that returning a generator expression would be efficient than returning a huge list of results?
readthedocs/search/utils.py
Outdated
def _remove_newlines_from_dict(highlight): | ||
""" | ||
Recursively change results to turn newlines into periods. | ||
def _get_inner_hits_highlights(hit, logging=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like maybe we don't even need this function. It's mostly just checking if the hit has a highlight and returning it. We can do that in the parent function itself pretty easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. 👍
Looks good once we fix the conflict 👍 |
I have moved the sorting logic to
search.utils
.