gpt4 book ai didi

python - 搜索后端错误 : No fields were found in any search_indexes

转载 作者:行者123 更新时间:2023-11-28 21:57:33 26 4
gpt4 key购买 nike

我正在尝试使用 whoosh 作为引擎来设置 django-haystack。我的问题是在按照说明构建我的第一个索引时发生的 here .

鉴于我的 staff/models.py:

class Person(models.Model):
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)

def __unicode__(self):
return '%s %s' % ( self.first_name, self.last_name)

我写了我的 staff/indexes.py:

from haystack import indexes
from staff.models import Person


class PersonIndex(indexes.SearchIndex, indexes.Indexable):
first_name = indexes.CharField(model_attr='first_name')
last_name = indexes.CharField(document=True, model_attr='last_name')

def get_model(self):
return Person

然后我将以下配置添加到我的 mycms/settings.py 中,以使用 whoosh 作为引擎:

import os
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}

后者是逐字取自the tutorial .然后我为我的索引添加了一个简单的文本模板,mycms/templates/search/indexes/staff/person_text.txt

{{ object.first_name }}
{{ object.last_name }}

...更新了我的 urlconf:

(r'^search/', include('haystack.urls')),

...并创建了我的初始搜索模板,该模板是从 the tutorial 复制的:

{% extends 'base.html' %}

{% block content %}
<h2>Search</h2>

<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>

{% if query %}
<h3>Results</h3>

{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}

{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}

最后,按照教程中的步骤,我尝试了build my first index .然后是当我收到以下错误时:

$ python manage.py rebuild_index
/home/roberto/.virtualenvs/ve_master/local/lib/python2.7/site-packages/mptt/models.py:305: DeprecationWarning: Implicit manager CMSPlugin.tree will be removed in django-mptt 0.6. Explicitly define a TreeManager() on your model to remove this warning.
DeprecationWarning


WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
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.
SearchBackendError: No fields were found in any search_indexes. Please correct this before attempting to search.

我一直在寻找解决方案,但 results似乎相当过时。有什么帮助吗?

更新:

Django          - 1.5.5        - active
Whoosh - 2.5.4 - active
django-haystack - 2.1.0 - active

最佳答案

haystack 模块查找名为 search_indexes 的文件,因此它不会在不更改默认行为的情况下找到您的 indexes 模块。

关于python - 搜索后端错误 : No fields were found in any search_indexes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19686971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com