Skip to content

Fix: Sort language autocomplete results alphabetically with prefix ma…#11929

Merged
RayBB merged 2 commits intointernetarchive:masterfrom
Saad259:fix-language-autocomplete-sort
Feb 26, 2026
Merged

Fix: Sort language autocomplete results alphabetically with prefix ma…#11929
RayBB merged 2 commits intointernetarchive:masterfrom
Saad259:fix-language-autocomplete-sort

Conversation

@Saad259
Copy link
Copy Markdown
Contributor

@Saad259 Saad259 commented Feb 25, 2026

Closes #10765

The autocomplete_languages function in utils.py was yielding results in the order they were iterated from get_languages() rather than in a meaningful order. This PR collects all matches into a list first, then sorts them so that names starting with the search prefix rank above names that merely contain it elsewhere, with alphabetical ordering within each group.

Note: locale-aware collation (for correctly sorting translated language names for non-English users) is a known limitation. Implementing it safely in a concurrent web server would require a thread-safe i18n library like babel, which is not currently a dependency. This could be addressed as a separate issue. The docstring has also been updated to reflect the new correct output order.

Technical

Testing

  1. Navigate to http://localhost:8080/languages/_autocomplete?q=eng&limit=10
  2. Confirm "English" appears before "English, Middle", "English, Old", and "Creoles and Pidgins, English-based"
  3. Test with other prefixes such as fr and ar to confirm consistent behaviour.

Screenshot

Not applicable, no UI changes to the autocomplete dropdown itself. JSON output before and after is documented in the linked issue.

Stakeholders

@RayBB

@github-project-automation github-project-automation bot moved this to Waiting Review/Merge from Staff in Ray's Project Feb 25, 2026
Copy link
Copy Markdown
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! The change itself is solid and works well.

However, please avoid opening pull requests for issues that have already been offered to another contributor. In the future, wait until you are formally assigned the issue or have confirmed it is still available. This helps us avoid overlapping work and ensures a fair process for everyone.

Since this was a simple fix, we’ll move forward with it this time, but please follow this protocol for your next contribution.

@RayBB RayBB merged commit dde520d into internetarchive:master Feb 26, 2026
4 checks passed
@github-project-automation github-project-automation bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project Feb 26, 2026
RayBB pushed a commit that referenced this pull request Feb 26, 2026
Fix: Sort language autocomplete results alphabetically with prefix ma…
@Saad259
Copy link
Copy Markdown
Contributor Author

Saad259 commented Feb 26, 2026

@RayBB Thank you for the feedback and my apologies for overlooking that. I will ensure I remember to wait to be assigned next time onwards.

bhardwajparth51 pushed a commit to bhardwajparth51/openlibrary that referenced this pull request Mar 3, 2026
…tocomplete-sort

Fix: Sort language autocomplete results alphabetically with prefix ma…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Language drop down out of order

2 participants