这里完全是菜鸟....
https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/search/#postgresql -fts-search-configuration
嗨@gotexis。 django-filter 基本上做了两件事:
如果没有Filter
类来构造您要查找的查询,您有两个选择:
Filter.method
功能。如果您可以概括查询,编写自定义Filter
将更可重用,但是Filter.method
对于一次性实例很有用。 你会写这样的东西:
from django.contrib.postgres.search import SearchQuery, SearchVector
from djanog_filters import FilterSet, CharFilter
class F(FilterSet):
# The model `field_name` is the field you want to search on and is passed to your `method`.
# The `method` argument is the name of the method to call to perform filtering.
search = CharFilter(field_name='body_text', method='search_fulltext')
def search_fulltext(self, queryset, field_name, value):
return queryset \
.annotate(search=SearchVector(field_name)) \
.filter(search=SearchQuery(value))
哇谢谢你的帮助@rpkilby ,请给我更多的时间来消化这段代码......
现在我正在用与 django-filters 集成的 graphene-django 敲我的头。
我希望(理想情况下)用 GraphQL 实现这个
请注意,graphene-django 如何包装 django-filter 可能存在一些问题。 例如,见#927
@rpkilby是的,先生
看起来确实是有堆给予比节点不受欢迎的Python + GraphQL如何成为石墨烯的问题,再加上笔者放弃了这个项目,你不同意:)
最近的一个,也与 django-filter 相关,是他们的 DjangoFilterConnectionField 不适用于预取,导致大量查询。 一直调试失败,不知道大家有没有经验分享:)
最有用的评论
嗨@gotexis。 django-filter 基本上做了两件事:
如果没有
Filter
类来构造您要查找的查询,您有两个选择:Filter.method
功能。如果您可以概括查询,编写自定义
Filter
将更可重用,但是Filter.method
对于一次性实例很有用。 你会写这样的东西: