1

I'm implementing haystack with the whoosh search engine. When I run 'rebuild_index' I get the following error in my terminal.

 File "/home/dilts/installingDJANGO/ENV/lib/python3.5/site-packages/django/template/loader.py", line 74, in select_template
    raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: search/indexes/submit_app/incident_text.txt

And this error in my browser.

reduce() of empty sequence with no initial value
incidents = SearchQuerySet().autocomplete(content_auto=request.POST.get(title, ''))
return clone.filter(six.moves.reduce(operator.__and__, query_bits)) 

My generic file structure looks like the following...

project
|--------submit_app
|--------search_app (uses a submit_app model called Incident)
|--------templates (where I put search/indexes/search_app/incident_text.txt)

From what I've read online, I believed my structure was correct, but from the error, I'm not so sure anymore. I feel like there might be some confusion with the shared model, but I don't know.

settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
WHOOSH_INDEX = os.path.join(BASE_DIR,'whoosh/')

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

views.py

from django.shortcuts import render
from .forms import IncidentsSearchForm
from django.contrib.auth.decorators import login_required
from haystack.query import SearchQuerySet

@login_required(login_url='/login/')
def incidents(request):

    if request.method == 'POST': # If the form has been submitted...
        form = IncidentsSearchForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            title = form.cleaned_data['title']

            ## this piece isn't working at I had hoped
            incidents = SearchQuerySet().autocomplete(content_auto=request.POST.get(title, ''))

    else:
        form = IncidentsSearchForm() # An unbound form
        title = ''
        incidents = ''

    return render(request, 'search.html',
        {
        'form': form, 
        'title': title,
        'incidents' : incidents,
        }
    )
user1807271
  • 946
  • 3
  • 13
  • 32

2 Answers2

0

when you include('haystack.urls'), it will look search/search.html by default. Are you have a search.html file ?

/templates/search/search.html

views.py

return render(request, 'search/search.html',
        {
        'form': form, 
        'title': title,
        'incidents' : incidents,
        }
0

I had the same issue with rebuild_index. It seems that Haystack looks for the txt template inside the model's app folder. In your case you should put the index in

templates/search/indexes/submit_app/incident_text.txt

submit_app not search_app

vladimir.gorea
  • 641
  • 1
  • 8
  • 27