【问题标题】:In SQLAlchemy, how do I specify a full-text index?在 SQLAlchemy 中,如何指定全文索引?
【发布时间】:2012-03-02 14:20:56
【问题描述】:
class AccountIndexes(Base):
    __tablename__ = 'account_indexes'
    id = Column(Integer, primary_key = True)
    user_id = Column(Integer, nullable=False, unique=True, index=True)
    full_name = Column(String(255), nullable=True)
    __table_args__ = {'mysql_engine':'MyISAM'}

那是我的桌子。如何在 full_name 上创建“全文索引”? (不是正常的索引)

【问题讨论】:

  • 注意:我不需要实际使用查询 API。我只需要定义它并创建索引。 (无论如何我都在使用原始 SQL)

标签: mysql database indexing sqlalchemy


【解决方案1】:

如果您可以检查sqlalchemy.schemaIndex 中的代码,那么他们写道

def __init__(self, name, *columns, **kw):
    """Construct an index object.

    :param name:
      The name of the index

    :param \*columns:
      Columns to include in the index. All columns must belong to the same
      table.

    :param unique:
        Defaults to False: create a unique index.

    :param \**kw:
        Other keyword arguments may be interpreted by specific dialects.

    """
    self.table = None 
    # will call _set_parent() if table-bound column
    # objects are present
    ColumnCollectionMixin.__init__(self, *columns)
    self.name = name 
    self.unique = kw.pop('unique', False)
    self.kwargs = kw 

现在在Index__init__ 中,他们只检查unique。我认为要生成全文索引,您必须使用 sqlalchemy 的DDL 操作功能。

【讨论】:

猜你喜欢
  • 2018-10-30
  • 1970-01-01
  • 2017-07-12
  • 1970-01-01
  • 1970-01-01
  • 2014-01-17
  • 2023-01-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多