Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Questions About Using Solr and Haystack

So I did pip install django-haystack or whatever the command was in my project virtualenv folder, and I also have solr installed, but now i'm slightly confused as to what to do.

I keep getting an error saying that the solr backend requires the installation of pysolr? and i'm confused as to where I run this command? "./manage.py build_solr_schema"

i've been trying to refer to the haystack guide but it is a little bit vague. Help me please!! Thanks

like image 436
swedishfished Avatar asked Nov 09 '22 21:11

swedishfished


1 Answers

Supposing you have Solr 4.10.4 and you use the example directory which contains a ready to use Solr configuration.

To install haystack if you're using a virtualenv you activate it first and then run

pip install django-haystack

and to use the Solr backend, you also need to install the pysolr module in your virtualenv

pip install pysolr

Than you have to add haystack to your INSTALLED_APPS in settings.py file

INSTALLED_APPS = (
    # ...
    'haystack',
)

And you have to set - in your settings.py ifle - the search engine backend for haystack to use:

HAYSTACK_CONNECTIONS = {
    'default': {
    'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
    'URL': 'http://127.0.0.1:8983/solr/the_core_you_created'
   },
}

the_core_you_created is the Solr core you've created for your app.

Now in order to build a search schema you have to register the models you want to store in the serach engine, so you have to create SearchIndexes. Once you've created search indexes you can build the search schema, run:

python manage.py build_solr_schema

and copy the result in solr/the_core_you_created/conf/schema.xml

Now you have to rebuild the index:

python manage.py rebuild_index

then create a search view and a search template.

You can find the detailed steps in haystack docs and - more concise - in Django by example book.

like image 137
doru Avatar answered Nov 14 '22 22:11

doru