Skip to content
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

Use the Wagtail search backend's autocomplete() search method where suitable #140

Open
ababic opened this issue Jan 23, 2023 · 0 comments
Open

Comments

@ababic
Copy link

ababic commented Jan 23, 2023

Models that subclass wagtail.search.index.Indexed very often have the optimal search matching criteria / weighting configured on the model using the search_fields attribute.

If using one of these models with AutocompletePanel, it's difficult to imagine a scenario where you wouldn't just want to reuse this configuration for an admin-facing search too. This would be possible with something like:

from wagtail.search.index import Indexed
from wagtail.search.backends import get_search_backend

@require_POST
def search(request):
    ...
    if issubclass(model, Indexed):
        backend = get_search_backend()
        try:
            matches = backend.autocomplete(search_query, model)
        except NotImplementedError:
            matches = backend.search(search_query, model)
    else:
         # continue with existing behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant