Repository navigation
Search creators by surname when the query starts with a space - #674
Merged
Merged
Conversation
Editors often search for a credit's creator by typing a space and then the surname, e.g. " Cameron". The old autocomplete passed the space through to icontains, so first names were skipped. izaya stripped it, so " Cameron" matched "Cameron Stewart" and even ranked first names above surnames. Use izaya 0.4.0's clean_query hook to keep one leading space in CreatorLookup. With a leading space, search matches only names and aliases where the text follows a space, and puts names that end with it first. Searches without a leading space are unchanged.
- Sort leading-space results by surname match instead of the general rank, which put names starting with the query (found through an alias) ahead of the surname matches - Drop the leading space when fewer than min_length characters follow it, so " Ca" shows the minimum-length message instead of searching - Only treat a plain space as the surname prefix, and accept several leading spaces in search() - Build the filter from search_fields and keep the distinct() guard
- Sort leading-space results by surname match instead of the general rank, which put names starting with the query (found through an alias) ahead of the surname matches - Drop the leading space when fewer than min_length characters follow it, so " Ca" shows the minimum-length message instead of searching - Only treat a plain space as the surname prefix, and accept several leading spaces in search() - Unaccent the query with PostgreSQL's unaccent() for fields searched through __unaccent__, so "Peña" matches "Ana Peña" in every lookup
Search series names through the unaccented field and unaccent the query, matching the '#' path. "Spíder" now finds Spider-Man issues, and the search can use the series name trigram index.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When adding credits on the issue form, editors often search for a creator by typing a space and then the surname, e.g.
Cameron. The old django-htmx-autocomplete widget passed that space toicontains, so first names were skipped. Since the move to izaya (#666), the search view strips the query, soCameronmatched "Cameron Stewart" and ranked it above "Don Cameron".izaya 0.4.0 adds a
clean_queryhook so a lookup can keep whitespace that matters.CreatorLookupnow uses it:clean_querykeeps one leading space and strips the rest. Only a plain space counts, so pasted text with a leading tab or non-breaking space searches normally. The space is dropped when fewer than 3 characters follow it, soCaasks for more text instead of searching.searchonly matches names and aliases where the text comes after a space, and puts names that end with it first.Cameronreturns "Don Cameron" before "Jo Cameron Smith", and leaves out "Cameron Stewart", even when an alias like "John Cameron" makes it match.Accent-insensitive queries
Lookups compared
unaccent(name)with the query as typed, so an accented query never matched:Peñadidn't find "Ana Peña". A newunaccent()helper strips accents from the query with PostgreSQL's ownunaccent(), so both sides follow the same rules. It skips the database call for plain ASCII queries.The new
UnaccentModelLookupbase class applies this to every lookup that searches through__unaccent__. Aliases and alternate names aren't unaccented, so they still get the query as typed. Issue searches without#now search the unaccented series name as well, soSpíderfinds Spider-Man issues, and the search can use the series name trigram index.Changes
comicsdb/lookups.py:clean_queryandsearchtoCreatorLookupunaccent()andUnaccentModelLookup, and use them in the Arc, Character, Creator, Publisher, Series, Team, Universe, Imprint and Issue lookupspyproject.toml,uv.lock: require izaya 0.4.0tests/comicsdb/test_lookups.py: cover query cleaning, surname matching and ordering, alias matching, the minimum length, accented queries and aliases, and the search endpoint