我正在使用 Ubuntu 13 和 Django 1.4.5,我已经安装了 solr、tomcat6、(sudo apt-get install solr-tomcat) djangohaystack 等,它们看起来工作正常。但我无法制作索引。
search_indexes.py
from haystack import indexes, site
from firms_api.models import Company
class CompanyNameIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
company_name = indexes.CharField(model_attr='company_name')
def get_model(self):
return Company
def __unicode__(self):
return self.Company.company_name
def index_queryset(self, using=None):
return self.get_model().objects.all()
site.register(Company, CompanyNameIndex)
设置文件:
HAYSTACK_SITECONF = 'api'
HAYSTACK_SEARCH_ENGINE = 'solr'
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'djangobb_index')
HAYSTACK_SOLR_URL = "http://solrserver.com/solr"
比我做的:
python manage.py build_solr_schema -f schema.xml
sudo mv schema.xml /etc/solr/conf/schema.xml
sudo /etc/init.d/tomcat6 restart
* Stopping Tomcat servlet engine tomcat6 [ OK ]
* Starting Tomcat servlet engine tomcat6 [ OK ]
python manage.py rebuild_index
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.
python manage.py haystack_info
Loaded URLconf to initialize SearchSite...
Main site registered 0 index(es).
当我尝试在 solr 上进行搜索时,出现此错误:
HTTP Status 400 - no field name specified in query and no defaultSearchField defined in schema.xml
type Status report
message no field name specified in query and no defaultSearchField defined in schema.xml
description The request sent by the client was syntactically incorrect (no field name specified in query and no defaultSearchField defined in schema.xml).
有人知道我在哪里犯了错误吗?
谢谢