์ฌ๊ธฐ ์์ ๋ ธ์ผ....
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 ๋ค ์ ์๋
์ค์ ๋ก ๋
ธ๋์ ๋นํด ์ธ๊ธฐ๊ฐ์๋ ํ์ด์ฌ + GraphQL์์ด ์ผ๋ง๋ ์ฃผ์ด์ง ๊ทธ๋ ํ ๋ฌธ์ ๋ก ์ธํด์ด ํ์ ๊ฒ ๊ฐ์ต๋๋ค ํ๋ฌ์ค ์ ์๋ ๋น์ ์ด ๋์ํ์ง ์์ ๊ฒ์ด๋ค,์ด ํ๋ก์ ํธ์ ํฌ๊ธฐํ๋ค :)
django-filter์ ๊ด๋ จ๋ ๊ฐ์ฅ ์ต๊ทผ ๊ฒ ์ค ํ๋๋ DjangoFilterConnectionField๊ฐ ํ๋ฆฌํ์นญ๊ณผ ํจ๊ป ์๋ํ์ง ์์ ์๋ง์ ์ฟผ๋ฆฌ๊ฐ ๋ฐ์ํ๋ค๋ ๊ฒ์ ๋๋ค. ๋๋ฒ๊น ์ ์คํจํ์ต๋๋ค. ๊ณต์ ํ ๊ฒฝํ์ด ์๋์ง ๊ถ๊ธํฉ๋๋ค. :)
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ ํ์ธ์ @gotexis์ ๋๋ค. django-filter๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ ๊ฐ์ง ์์ ์ ์ํํฉ๋๋ค.
์ฐพ๊ณ ์๋ ์ฟผ๋ฆฌ๋ฅผ ๊ตฌ์ฑํ๋
Filter
ํด๋์ค๊ฐ ์๋ ๊ฒฝ์ฐ ๋ ๊ฐ์ง ์ต์ ์ด ์์ต๋๋ค.Filter.method
๊ธฐ๋ฅ์ ์ฌ์ฉํ์ธ์.์ฟผ๋ฆฌ๋ฅผ ์ผ๋ฐํํ ์ ์๋ค๋ฉด ์ฌ์ฉ์ ์ ์
Filter
์์ฑํ๋ ๊ฒ์ด ๋ ์ฌ์ฌ์ฉํ ์ ์์ง๋งFilter.method
๋ ์ผํ์ฑ ์ธ์คํด์ค์ ์ ์ฉํฉ๋๋ค. ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ ์ ์์ต๋๋ค.