0
我要在我正在工作的网站上实现搜索引擎,我发现haystack似乎是最好的Django库,因此我使用elasticsearch实现了它。用干草堆和elasticsearch搜索口音在Django
该应用程序的语言是西班牙语,所以你们很多人都知道有这么多口音的单词(á,é,í,ó,ú,),我需要干草堆才能找到“canción”if用户输入“cancion”(没有重音)。
这里是我的搜索视图(我使用的jQuery插件预输入草垛的自动完成功能)
import json
from django.shortcuts import render
from django.http import HttpResponse
from haystack.query import SearchQuerySet
def autocomplete(request):
sqs = SearchQuerySet().autocomplete(content_auto=request.GET.get('q', ''))[:5]
suggestions = [{'title': result.title, 'url': result.object.get_absulute_url()} for result in sqs]
# Make sure you return a JSON object, not a bare list.
# Otherwise, you could be vulnerable to an XSS attack.
the_data = json.dumps(suggestions)
return HttpResponse(the_data, content_type='application/json')
没有什么特别在我的设置,但草垛的正常配置。
的可能的复制[Django的草垛:搜索与不口音项(http://stackoverflow.com /问题/ 2240880/Django的草垛搜索换一个长期与 - 和 - 不 - 重音) – laffuste 2015-12-08 07:33:41