Search code examples
pythondjangodjango-haystackdivio

How to rebuild_index in Django Haystack


I'm using Aldryn Search - a plugin for Django CMS that uses Haystack.

I've read both documenations up and down and I don't understand how to properly run manage.py rebuild_index. If I run it as normal I get:

SolrError: Failed to connect to server at 'http://127.0.0.1:8000/update/?commit=true', are you sure that URL is correct?

So I'm guessing it's because my server is not running. But I can't run this command while my server is running. I try opening a new tab in terminal and run the command while my server is running in the other tab and I get a 403 forbidden error.

Such a simple thing is not explained. Also does this command have to be reran every time a page changes content or a new page or blog post gets created? I see this as being a huge problem in production.


Solution

  • This is because your django development server is not running.

    In order to keep both servers running (solr and Django), run solr in the background and then run Django dev server. So, assuming that the solr server is inside your home dir then run it first:

    cd ~/solr-version/example/

    java -jar start.jar --daemon &

    HINT: If you want to kill the background solr server do: ps aux | grep java and you should get something like this

    username 3432 134 1.1 2431016 93196 Sl 09:52 0:06 java -jar start.jar --daemon username 3466 0.0 0.0 11744 932 S+ 09:52 0:00 grep --colour=auto java

    The second column marks the pid of the process, so to kill it, do:

    kill 3432

    Now you can run Django dev server by going to the root of your project and ./manage.py runserver

    As for your second question: No it doesn't need to be rerun every time code changes assuming you are using django-haystack RealTimeSignalProcessor. It is very very simple. Each time a model is updated (i.e an entry is added, changed, deleted) the index will be update automatically!

    Hope this helps you!