本文整理汇总了Python中django.contrib.postgres.search.SearchVectorField方法的典型用法代码示例。如果您正苦于以下问题:Python search.SearchVectorField方法的具体用法?Python search.SearchVectorField怎么用?Python search.SearchVectorField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.postgres.search
的用法示例。
在下文中一共展示了search.SearchVectorField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: as_postgresql
# 需要导入模块: from django.contrib.postgres import search [as 别名]
# 或者: from django.contrib.postgres.search import SearchVectorField [as 别名]
def as_postgresql(self, qn, connection):
source_field = self.lhs.field
model = source_field.model
tsv_column_name = source_field.name + self.tsvector_column_suffix
model_fields = {i.name: i for i in model._meta.fields}
tsv_field = model_fields.get(tsv_column_name)
if tsv_field is None or not isinstance(tsv_field, SearchVectorField):
# raise RuntimeError('Model "{}" should have "{}" field.'.format(model, tsv_column_name))
# fail silently - use insensitive contains search
return IContains(self.lhs, self.rhs).as_sql(qn, connection)
if source_field.name not in getattr(self.lhs.field.model, 'full_text_search_fields', []):
# raise RuntimeError('Model "{}" should have "{}" in "{}" class atribute (List).'.format(
# model, 'full_text_search_fields', tsv_column_name))
# fail silently - use insensitive contains search
return IContains(self.lhs, self.rhs).as_sql(qn, connection)
return self.get_fts_lookup(qn, connection)