Armance
Armance

Reputation: 5390

Implementing search with Haystack and Solr issues

I'm trying to implement search to my django based website.

While following the tutorial I found this:

If you’re using the Solr backend, you have an extra step. Solr’s configuration is XML-based, so you’ll need to manually regenerate the schema. You should run ./manage.py build_solr_schema first, drop the XML output in your Solr’s schema.xml file and restart your Solr server.

First, I don't know where to put my schema.xml, after some resarch I figured I'd create a folder inside my project to put it: myprojectname/solr/schema.xml. Is that right?

Second, how do I restart Solr?

UPDATE

I downloaded Solr,unzipped it and I put the schema.xml generated inside example/solr/conf

then I start solr java -jar start.jar

but when I try to build the index : ./manage.py rebuild_index

I get :

WARNING: This will irreparably remove EVERYTHING from your search index.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y

Removing all documents from your index because you said so.
All documents removed.
Indexing 1 News.
Failed to add documents to Solr: [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int    name="QTime">4</int></lst><lst name="error"><str name="msg">ERROR: [doc=news.news.2]   unknown field 'django_id'</str><int name="code">400</int></lst></response>
Indexing 1 entries.

Failed to add documents to Solr: [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int name="QTime">17</int></lst><lst name="error"><str name="msg">ERROR: [doc=zinnia.entry.2] unknown field 'django_id'</str><int name="code">400</int></lst></response>

I verified my schema.xml ,and I do have :

<field name="django_ct" type="string" indexed="true" stored="true" multiValued="false" />
<field name="django_id" type="string" indexed="true" stored="true" multiValued="false" />

P.S. I'm using Django 1.2 and Haystack 1.2.7

Upvotes: 1

Views: 2009

Answers (2)

Rafa
Rafa

Reputation: 3043

I had the same issue, the rebuild task failed. For me the solution was:

  1. Build a new schema.xml and place it in the corresponding folder

  2. Restart Solr

  3. rebuild the index without problems

Upvotes: 0

Francis Yaconiello
Francis Yaconiello

Reputation: 10939

The solr server needs to have a copy of your schema.xml not django. I usually keep a copy of the schema.xml in my django project for version control, but solr can't find it there.

Is you solr server local? Are you using a hosted or remote Solr service? I develop locally then use websolr b/c i dont want to configure solr for production.

For local dev on OSX

I'm assuming this is local development on OSX and that you have homebrew installed (assumptions - give me more info if this isnt the case):

brew install solr

This is going to install Solr at someplace like: /usr/local/Cellar/solr/...

Note: When im developing locally, I like to use fabric for running deployment and some startup tasks.

So in my fabfile.py I have a fabric command to copy my schema.xml into the proper file and start the solr server (I just run fab solr at the cmd line)

def solr() :
    # build a new updated schema.xml (changes to indexes/models may require this so always do it for local testing)
    local('python manage.py build_solr_schema > schema.xml')
    # copy the schema.xml into the proper directory
    local('cp schema.xml /usr/local/Cellar/solr/3.6.0/libexec/example/solr/conf/schema.xml')
    # start the solr server
    local('cd /usr/local/Cellar/solr/3.6.0/libexec/example && java -jar start.jar')

Note: you can run these commands on the command line if you dont use fabric

Upvotes: 1

Related Questions