본문 바로가기

Dev/web

python, django,haystack, elasticsearch 장고 엘라스틱서치 연동 - 4(haystack 검색 자동완성 기능)

Auto-complete Functionality 


class ProjectIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='user')
title = indexes.CharField(model_attr='title')
pub_date = indexes.DateTimeField(model_attr='created_at')
suggestions = indexes.FacetCharField()
text_auto = indexes.NgramField(model_attr='title')

서치인덱스에 마지막줄 추가해봄



auto_complete = SearchQuerySet().autocomplete(text_auto='검색하고싶은거여기에')
print("auto_complete:",auto_complete)

이렇게 사용하면 됨