Haystack-Whoosh Django搜索引擎在本地运行但不在生产中

时间:2016-06-07 14:35:49

标签: django django-haystack whoosh

使用Whosh 2.7.4和Django-Haystack版本2.5.dev1。

我们有类似的设置:

settings.py

WHOOSH_INDEX = os.path.join(PROJECT_ROOT, 'whoosh_index/')

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': WHOOSH_INDEX,
        'INCLUDE_SPELLING': True,
    },
}

ajax.js

$(function(){

        $('#search').keyup(function() {

            $.ajax({
                type: "POST",
                url: "/search/",
                data: { 
                    'search_text' : $('#search').val(),
                    'csrfmiddlewaretoken' : $("input[name=csrfmiddlewaretoken]").val()
                },
                success: searchSuccess,
                dataType: 'html'
            });

        });

    });

    function searchSuccess(data, textStatus, jqXHR)
    {
        $('#search-results').html(data);
    }

views.py

def search_titles(request):
    txt = request.POST.get('search_text', '')
    if txt:
        articles = SearchQuerySet().autocomplete(content_auto=txt)
    # if the post request is empty, return nothing
    # this prevents internal server error with jquery
    else:
        articles = []
    return render_to_response('ajax_search.html', {'articles': articles})


def articles(request):
    language = 'en-gb'
    session_language = 'en-gb'

    if 'lang' in request.COOKIES:
        language = request.COOKIES['lang']

    if 'lang' in request.session:
        session_language = request.session['lang']

    args = {}
    args.update(csrf(request))

    args['articles'] = Article.objects.all()
    args['language'] = language
    args['session_language'] = session_language

    return render_to_response('index.html', args)

我们已尝试通过manage.py重建和更新索引,但未提供任何结果。我们还确保Django-Haystack和whoosh模块的生产和本地版本是相同的。

有什么想法吗?任何形式的帮助将不胜感激! :)

0 个答案:

没有答案