1

How to do partial matching on searches with PostgreSQL as search backend?

I'm running wagtail 5.0 and I see the following statements in the documentation

The partial_match option has been deprecated. To index a field for partial matching, use AutocompleteField instead.

However in the autocomplete documentation it states

This method should only be used for real-time autocomplete and actual search requests should always use the search() method.

What is the issue with using the autocomplete method vs search? Functionally the autocomplete method gives me what i want.

>>> UtvalgPostPage.objects.all().live().search("alt")
<SearchResults [<UtvalgPostPage: Demo på alt vi har>]>
>>> UtvalgPostPage.objects.all().live().search("al")
<SearchResults []>
>>> UtvalgPostPage.objects.all().live().autocomplete("al")
<SearchResults [<UtvalgPostPage: Demo på alt vi har>]>
Kippster
  • 11
  • 2

1 Answers1

0

As I understand it, the second note is simply providing guidance on implementing a search interface that behaves in the conventional way: if you're running a search in the classic "submit search term, receive results" way, then you wouldn't want a search for "cat" to return results about caterpillars, but on a search interface that suggests results in real-time as you type, it's legitimate for it to return those results immediately after typing "cat".

However, if the autocomplete method gives you the result you want, there's no problem with using that. The documentation shouldn't really be giving instructions in such absolute terms - I'll open a pull request to update that.

gasman
  • 23,691
  • 1
  • 38
  • 56