2015-12-16 1 views
13

Djangoを1.7から1.9にアップデートした後、HaystackとSolrをベースにした検索エンジンが動作を停止しました。これは私が得るものです:Haystackは "SearchResultにモデルが見つかりませんでした"と答えています

./manage.py shell 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
(InteractiveConsole) 
>>> from haystack.query import SearchQuerySet 
>>> sqs = SearchQuerySet().all() 
>>>sqs[0].pk 
u'1' 
>>> sqs[0].text 
u'\u06a9\u0627\u0645\u0631\u0627\u0646 \u0647\u0645\u062a\u200c\u067e\u0648\u0631 \u0648 \u0641\u0631\u0647\u0627\u062f \u0628\u0627\u062f\u067e\u0627\nKamran Hematpour & Farhad Badpa' 
>>> sqs[0].model_name 
u'artist' 
>>> sqs[0].id 
u'mediainfo.artist.1' 
>>> sqs[0].object 
Model could not be found for SearchResult '<SearchResult: mediainfo.artist (pk=u'1')>'. 

私は私のデータベースがempyではなく、私の設定は以下の通りであると言っている:

HAYSTACK_CONNECTIONS ={ 
    'default': { 
     'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 
     'URL': 'http://ahangsolr:8983/solr', 
    }, 
} 

そして、これが私のsearch_indexes.pyです:

import datetime 
from haystack import indexes 
from mediainfo.models import Album 
from mediainfo.models import Artist 
from mediainfo.models import PlayList 
from mediainfo.models import Track 
from mediainfo.models import Lyric 

class AlbumIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 
    artist = indexes.CharField(model_attr='artist', indexed=True) 
    publish_date = indexes.DateTimeField(model_attr='publish_date') 

    def get_model(self): 
     return Album 

    def index_queryset(self, using=None): 
     """Used when the entire index for model is updated.""" 
     return self.get_model().objects.filter(publish_date__lte=datetime.datetime.now()) 


class ArtistIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return Artist 


class PlaylistIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return PlayList 


class TrackIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return Track 


class LyricIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return Lyric 
+0

どのバージョンのHaystackを使用していますか? –

+0

@ThomasOrozco haystack 2.4.1 –

答えて

6

私は、2.4.1リリースにコミットの欠落を含めることで問題を解決できました。この問題を修正しているコミットので、あなたがその特定のコミットまでインストールする

pip install git+ssh://[email protected]/django-haystack/[email protected] 

を行うことができますhttps://github.com/django-haystack/django-haystack/commit/f1ed18313777005dd77ed724ecbfb27c0b03cad8

ました。

+0

ありがとう@elchudi私の答えでしたが、私はいくつかの変更を加えました:pip install git + https://[email protected]/django-haystack/[email protected]マスターは本当に本当にうまくいった –

+1

あなたはgolden_boy615を歓迎しています。マスターはいつも変わるので、私はピップで@masterを追跡しません。そして、django-haystackの新しいリリースまで、あなたが知っている特定のコミットを追跡する方が良いです作品 – elchudi

1

それあなたのモデルを見つけることができることを確認するために、アプリのレジストリをチェックすることをお勧めします。

from django.apps import apps as django_apps 
model = django_apps.get_model('mediainfo.artist') 
model.app_label, model.model_name 
assert model._meta.app_label == 'mediainfo' 
assert model._meta.model_name == 'artist' 

それから私はhaystackが帰国されている情報を確認します。

from haystack.utils.app_loading import haystack_get_model 
haystack_model = haystack_get_model('mediainfo', 'artist') 
haystack_model == model 

それは同じこと(haystack_model = modelを!)返さない場合。さらに掘る必要があります。

ただし、ロードと検索モデルはdjango 1.7.0と1.8.0(非推奨)の間で変更され、django.db.models.loading.get_modelは1.8.2で削除されました。 詳細はdjango-haystack #1206です。

したがって、django-haystackdjango 1.9.0で動作するには、this commitを含むリリースが必要です。つまり、django-haystack>=2.4.0です。

+1

私のhaystackバージョンは2.4.1で、django_apps.get_model( 'mediainfo.artist')はNo error:を返します。この問題の解決に役立つ情報があれば教えてください。 –

+0

haystack_model ==モデルはtrueを返しますが、モデルのapp_label属性とmodel_name属性を使用するとエラーが発生します:AttributeError:typeオブジェクト 'Artist'に 'model_name'属性とAttributeError:typeオブジェクトがありません 'artist'に 'app_label'属性がありません! !! –

+1

もこの問題に直面しています。修正しましたか?私のためにhaystack_model ==モデルとこの問題は持続する –

関連する問題