internetarchive / openlibrary

One webpage for every book ever published!
https://openlibrary.org
GNU Affero General Public License v3.0
5.08k stars 1.32k forks source link

Expand language autocomplete to also prefix match inner words #8146

Closed tfmorris closed 3 weeks ago

tfmorris commented 1 year ago

Currently the language autocomplete endpoint is restricted to prefix matches which means that if a user types "gre" it won't return either "Ancient Greek" or "Modern Greek."

It should return all substring matches, with the prefix matches ranked highest in the list.

The auto-complete should then be able to find it as an option when someone types "greek".

Originally posted by @seabelis in https://github.com/internetarchive/openlibrary/issues/8145#issuecomment-1658690051

The function autocomplete_languages needs to be updated with the desired functionality. It may also make sense to refactor it to pass in the limit parameter so that it has all the knowledge it needs. https://github.com/internetarchive/openlibrary/blob/dc35977560ae0ca752eda36017769fdd82f15daa/openlibrary/plugins/upstream/utils.py#L717-L750

sbwhitt commented 1 year ago

@tfmorris @cdrini Working on this at the moment. Will put up a PR draft soon along with any questions about implementation.

cdrini commented 1 year ago

Awesome, thank you @sbwhitt !