我想改变搜索排名与三角相似性,但我得到了这个错误
/search/ function similarity(character varying,unknown)does not exist行1:...ows_show”.“description”,'')),'B'))AS“search”,SIMILARITY...^提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型强制转换。
我的代码:
def search_content(query: str) -> QuerySet | None:
if query:
search_vector = SearchVector("name", weight="A") + SearchVector("description", weight="B")
shows = (
Show.objects.annotate(
search=search_vector, similarity=TrigramSimilarity('name', query),
)
.filter(similarity__gt=0.4)
.values("id", "name", "baner", "release_date", "search", "similarity")
)
movies = (
Movie.objects.annotate(
search=search_vector, similarity=TrigramSimilarity('name', query),
)
.filter(similarity__gt=0.4)
.values("id", "name", "baner", "release_date", "search", "similarity")
)
episodes = (
Episode.objects.annotate(
search=search_vector, similarity=TrigramSimilarity('name', query),
)
.filter(similarity__gt=0.4)
.values("id", "name", "baner", "release_date", "search", "similarity")
)
qs = shows.union(movies, episodes).order_by("-similarity")
return qs
else:
return None
1条答案
按热度按时间lmvvr0a81#
似乎你的数据库中没有包含该函数的扩展。问题a
select * from pg_extension;
如果没有出现一个名为pg_trgm的文件,则使用
create extension pg_trgm;
在官方文档中使用django与trigram相似