-
-
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
[Fix #2328 #2013] Refresh search index and test for case insensitive search #4277
[Fix #2328 #2013] Refresh search index and test for case insensitive search #4277
Conversation
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.
Looks good, but I'd like to make the test a bit easier to read. It took me a couple minutes to realize what it was doing!
|
||
It tests with uppercase, lowercase and camelcase | ||
""" | ||
query = get_search_query_from_project_file(project_slug=project.slug)\ |
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.
Stray slash at the end of this line.
""" | ||
query = get_search_query_from_project_file(project_slug=project.slug)\ | ||
|
||
cased_query = getattr(query, case) |
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.
This feels really magical. I think there is a better way to write this code so that it's more obvious what it is doing. Perhaps by calling the function reference that is returned here, instead of just passing it in below.
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.
Perhaps by calling the function reference that is returned here, instead of just passing it in below.
Do you mean something like
if case == 'lower':
query = query.lower()
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.
Or even just:
case_function = getattr(query, case)
query = case_function()
Something that shows that the return is a function & we're calling it.
cc4da57
to
49f4287
Compare
readthedocs/search/documents.py
Outdated
# Its a model instance. | ||
queryset = self.get_queryset() | ||
obj = queryset.filter(pk=thing.pk) | ||
if not obj.exists(): | ||
return None | ||
|
||
return super(PageDocument, self).update(thing=thing, refresh=None, action='index', **kwargs) | ||
return super(PageDocument, self).update(thing=thing, refresh=refresh, action=action, **kwargs) |
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.
My fault while fixing lint! 😢
if isinstance(thing, HTMLFile): | ||
# Moreover, do not need to check if its a delete action | ||
# Because while delete action, the object is already remove from database | ||
if isinstance(thing, HTMLFile) and action != 'delete': |
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 did not consider delete case. While a object gets deleted, it calls update
with delete
action.
@ericholscher I have fixed the issue #2013 . My assumption was wrong as there was a edge case which I did not handle in the |
49f4287
to
c1b2770
Compare
# Its a model instance. | ||
queryset = self.get_queryset() | ||
obj = queryset.filter(pk=thing.pk) | ||
if not obj.exists(): | ||
return None | ||
|
||
return super(PageDocument, self).update(thing=thing, refresh=None, action='index', **kwargs) | ||
return super(PageDocument, self).update(thing=thing, refresh=refresh, |
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.
My fault while fixing lint! 😢
def test_page_search_not_return_removed_page(self, client, project): | ||
"""Check removed page are not in the search index""" | ||
query = get_search_query_from_project_file(project_slug=project.slug) | ||
# Delete all the HTML files of the project |
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 should confirm that the query returns a result here, so that we know that then it doesn't return later it's a direct result of the deletion of the file.
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.
@ericholscher Good point. Fixed it in latest commit
@ericholscher Fixed! |
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.
Looks good!
[Fix readthedocs#2328 readthedocs#2013] Refresh search index and test for case insensitive search
[Fix readthedocs#2328 readthedocs#2013] Refresh search index and test for case insensitive search
#4211 made the search case insensitive. This PR adds tests for it so it does not get broken while implementing #4266
This fix #2328 #2013
@ericholscher r?