1

I can't get the PostgreSQL Full Text Search feature to work as I need it.

I have a model Vereinwith a field straße. There are two Verein objects where straße has the value "Uhlandstraße".

What I want to achieve is that a search for "Uhl", "uhl", "nds", "straße" or "andstr" (you get the idea) returns those objects. Instead it does this:

>>> # With missing only 1 char at the end of the word, the search works.
>>> Verein.objects.filter(straße__search='Uhlandstraß')
<QuerySet [<Verein: 1>, <Verein: 2>]>

>>> # With missing more than 1 char at the and of the word, the search does not work.
>>> Verein.objects.filter(straße__search='Uhl')
<QuerySet []>
>>> Verein.objects.filter(straße__search='Uhlandstra')
<QuerySet []>

>>> # Same amount of chars as the working example, but from the end of the word, it does not work
>>> Verein.objects.filter(straße__search='hlandstraße')
<QuerySet []>

Any ideas what I need to change to get it working like explained?

Daniel
  • 3,092
  • 3
  • 32
  • 49
  • 3
    FTS does not shine with compound words. And it is never designed to find matches by part of the words (i.e. by just a few characters). FTS will only find matches when there are matching [lexemes](https://en.wikipedia.org/wiki/Lexeme). F.ex. the document `Uhlandstraße` is a match with a `uhlandstrasse` query (in the `german` configuration). -- If you want to search by only parts of some words, you should use e.g. `col ILIKE '%uhl%'` – pozs Mar 23 '17 at 10:45
  • 1
    @pozs, the thing is, I want to be able to search all fields of my model later on. I was just testing the feature using the easiest approach. – Daniel Mar 23 '17 at 10:49

0 Answers0