Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

postgresql - Django SearchVector postgres searchvector not saving correct strings

The postgres SearchVector in Django seems to be shortening my strings, I dont understand why. Ive shortened the code below to show what is happening.

I am querying a person object with a lastname that is added to the SearchVector.

from django.contrib.postgres.search import SearchVector
    self.model.objects.annotate(
                        search=SearchVector(
                            "last_name"
                        )
                ).filter(search__icontains="hjer").first().search

reults in: "'hjerp':1"

But the last_name is actually:

self.model.objects.annotate(
                    search=SearchVector(
                        "last_name"
                    )
                ).filter(search__icontains="hjer").first().last_name

'Hjerpe'

Why is the e not present in the search string? I would expect search above to show: "'hjerpe:1'"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This was due to the setting beeing sent in to the SearchVector, i changed:

self.model.objects.annotate(
                    search=SearchVector(
                        "last_name"
                    )

to

self.model.objects.annotate(
                    search=SearchVector(
                        "last_name", config="simple"
                    )

And the simple config does not do the smart stemming that the standard SearchVector does.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share

1.2m questions

2.1m answers

5 comments

56.5k users

...