0

スタートガイドに従っていますが、実行するmanage.py rebuild_indexと、どのモデルもインデックスに登録されていないようです。

/ searchで検索しようとすると、結果が得られず、ログに次のように表示されます。

Problem accessing /solr/select/. Reason: no field name specified in query and no defaultSearchField defined in schema.xml

これが私のアプリですsearch_indexes.py。ガイドのモデルよりも少し複雑なので、おそらくそれが機能しない理由です。

import datetime

from myproject.apps.lead import Lead, Opportunity

from haystack import site
from haystack.indexes import *

class LeadIndex(SearchIndex):
    text = CharField(document=True, use_template=True)

    company = CharField(model_attr='company__name')

    contact_name = MultiValueField()
    contact_city = MultiValueField()
    contact_state = MultiValueField()
    contact_postcode = MultiValueField()
    contact_email = MultiValueField()
    contact_phone = MultiValueField()

    product = CharField(model_attr='product__name')
    campaign = CharField(model_attr='campaign__name')

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return Lead.objects.filter(pub_date__lte=datetime.datetime.now())

    def prepare_contact_name(self, obj):
        return [contact.name for contact in obj.contact_set.order_by('name')]

    def prepare_contact_city(self, obj):
        return [contact.city for contact in obj.contact_set.order_by('city')]

    def prepare_contact_state(self, obj):
        return [contact.state for contact in obj.contact_set.order_by('state')]

    def prepare_contact_postcode(self, obj):
        return [contact.postcode for contact in obj.contact_set.order_by('postcode')]

    def prepare_contact_email(self, obj):
        return [contact.email for contact in obj.contact_set.order_by('email')]

    def prepare_contact_phone(self, obj):
        return [contact.phone for contact in obj.contact_set.order_by('phone')]

site.register(Lead, LeadIndex)

そして私/templates/search/indexes/lead/lead_text.txtはただ

{{ object.company__name }}

私は何が欠けていますか?

前もって感謝します。

4

1 に答える 1

0

インデックス クラスは と の両方 indexes.SearchIndexから継承する必要がありindexes.Indexableます。

class LeadIndex(indexes.SearchIndex, indexes.Indexable):
    ...

ワイルドカード インポート ( ) は使用しないでください*。これは非常に悪い形式であり、名前空間の汚染につながります。

于 2012-07-05T15:18:40.370 に答える