SQLAlchemy可搜索:全文搜索中的“函数tsq_parse不存在”

问题描述 投票:0回答:1

我正在尝试使用SQLAlchemy-searchable在模型列上启用全文搜索。我按照他们的quickstart guide上的说明并应用了this github issue中指定的修复程序,因为我正在使用Flask。此外,我已经创建并应用了Alembic Migrations docs部分中指定的迁移。但是,引发了以下异常:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) function 
tsq_parse(unknown, unknown) does not exist

LINE 3: WHERE quote.qt_search_vector @@ tsq_parse('pg_catalog.englis...
                                    ^
HINT:  No function matches the given name and argument types. You might need
to add explicit type casts. [SQL: 'SELECT quote.id AS quote_id, quote.song_id AS
quote_song_id, quote.stanza_id AS quote_stanza_id, quote.popularity_count AS
quote_popularity_count, quote.quote_text AS quote_quote_text,
quote.qt_search_vector AS quote_qt_search_vector \nFROM quote \nWHERE
quote.qt_search_vector @@ tsq_parse(%(tsq_parse_1)s, %(tsq_parse_2)s) \n
LIMIT %(param_1)s'] [parameters: {'tsq_parse_1': 'pg_catalog.english',
'tsq_parse_2': '"ipsum"', 'param_1': 10}]
(Background on this error at: http://sqlalche.me/e/f405)

我错过了什么吗?

__init__.朋友

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_searchable import make_searchable

Base = declarative_base()
make_searchable(Base.metadata)

... more code ...

模型

class QuoteQuery(BaseQuery, SearchQueryMixin):
    pass


class Quote(db.Model):
    query_class = QuoteQuery
    __table_args__ = (
        db.UniqueConstraint('song_id', 'stanza_id', 'quote_text'),)

    id = db.Column(db.Integer, primary_key=True)
    song_id = db.Column(
        db.Integer, db.ForeignKey('song.id'), nullable=False)
    stanza_id = db.Column(
        db.Integer, db.ForeignKey('stanza.id'), nullable=True)
    popularity_count = db.Column(
        db.BigInteger, unique=False, nullable=False, server_default='1')
    quote_text = db.Column(db.Text, unique=False, nullable=False)
    qt_search_vector = db.Column(TSVectorType('quote_text'))

询问

term = 'lorem'
Quote.query.search('"' + term + '"').all()
python sqlalchemy
1个回答
0
投票

这是我提供make_searchable函数的元数据的问题。修复了make_searchable调用:

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy_searchable import make_searchable

db = SQLAlchemy()
make_searchable(db.metadata)

在此之后,我调用了db.create_all()并且全文搜索开始按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.