-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Refactor language search autocomplete and add inner word matching #8160
Refactor language search autocomplete and add inner word matching #8160
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.
General logic lgtm! A few code reorg suggestions.
44879a2
to
604e926
Compare
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.
language
is a dict...
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
@cdrini I think this is good to merge now. I thought there was a problem with case matching, but I think that was just some form of response caching when I tested it locally. Testing this with the full language data in the staging env would be good. |
381d58a
to
84f4649
Compare
84f4649
to
5d6b799
Compare
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.
Ok lgtm! Team effort on this one thank you both @sbwhitt and @hornc ! Thanks for your patience, I was having trouble determining the refactor needed here, but I think I got it.
I did a refactor to remove the _matches_lang_name
method since that was making this rather difficult for me to follow. The method was introducing a confusing bit of misdirection in the logic. I instead introduced a more general method, word_prefix_match
and a more specific method, get_names_to_try
, for getting the various language names to try.
Appears to be working like a charm!
Closes #8146
Refactor the current autocomplete_languages util function to include a limit parameter as well as add prefix matching of inner language name words. For example, '/languages/_autocomplete?q=greek' will match with 'Ancient Greek', 'Modern Greek', and 'Greek' rather than just 'Greek' as it does now.
Technical
Consolidates existing match checks into a more generic matching function that allows for optional translation id.
A limit parameter was also added which controls how many results will be added to the returned iterator. Previously autocomplete_languages would return the total number of matches then was truncated down to a default limit of 5 when called in autocomplete.py. This default limit is preserved, but now it is possible to request more than 5 language matches.
Additionally, a small change was made to the supporting get_languages function which adds an optional limit parameter that defaults to the previous hard-coded value of 1000. This should clarify that a limit is being used within that function without changing any existing behavior.
Testing
Go to /languages/_autocomplete and attempt to search with queries like ?q=greek&limit=10. Verify that at least one inner word of the returned language names match the prefix given (q=greek). Also verify that the limit param accurately controls how many languages are returned.
Screenshot
Stakeholders
@cdrini @tfmorris