python - django haystack 没有索引

标签 python django tomcat solr

我正在使用 Ubuntu 13 和 Django 1.4.5,我已经安装了 solr、tomcat6、(sudo apt-get install solr-tomcat) djangohaystack 等,它们似乎工作正常。但我无法创建索引。

搜索索引.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).

有人知道我哪里出错了吗?

谢谢

最佳答案

我已经安装了 haystack 2.0.0 beta,现在可以使用了。

关于python - django haystack 没有索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16480489/

相关文章:

python - python函数的基本解释

python - 如何检索 Pandas 数据框中的 k 个最大值?

python - Django 模板 : get many-to-many value in formset

纯 http tomcat 的 Apache ssl 前端提供不安全的内容

python - 枕头错误(Python)无法打开共享对象文件

python - 在管理应用程序中显示模型的文档字符串

python - 在两个用户之间共享临时数据的正确方法

java - tomcat/其他应用服务器中 session 超时的响应代码是什么?

java - 隐藏Red5 tomcat版本——减少信息泄露请求

python - tf.contrib.framework 函数的预期用途是什么?