2015-12-16 28 views
13

Po zaktualizowaniu Django od 1,7 do 1,9, wyszukiwarka, która opiera się na stogu siana i Solr, przestał działać. To jest to, co mam:Stóg mówi „modelu nie można było znaleźć na wynik wyszukiwania”

./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')>'. 

muszę powiedzieć, moja baza danych nie jest empy i moja konfiguracja jest następująca:

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

a to mój 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

Jakiej wersji Haystack używasz? –

+0

@ThomasOrozco stóg_siana 2.4.1 –

Odpowiedz

6

udało mi się rozwiązać ten problem, tym brakującym zobowiązać się do wydania 2.4.1. Commit że stała ta kwestia była https://github.com/django-haystack/django-haystack/commit/f1ed18313777005dd77ed724ecbfb27c0b03cad8

więc można zrobić

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

zainstalować aż że specyficzny popełnić.

+0

Dzięki @elchudi to była moja odpowiedź, ale dodaje do niego kilka zmian: pip install git + https: //[email protected]/django-haystack/[email protected] opanować to naprawdę rzeczywiście prace –

+1

jesteś mile widziany golden_boy615, nie będę śledzić @master w pip ponieważ mistrz zmienia się cały czas, a do nowej wersji django stogu siana to lepiej po prostu śledzić specyficzny zobowiązują się, że o tym wiesz Prace – elchudi

1

To Byłoby dobrze, aby rozpocząć sprawdzanie rejestru aplikacji, aby upewnić się, że może znaleźć swój model (aby być pewnym).

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' 

Następnie chciałbym sprawdzić, co powraca haystack.

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

Jeśli nie wraca to samo (haystack_model = model!); wtedy będziesz musiał dalej kopać.

Jednak ładowanie i wyszukiwanie modeli zmieniło się między django 1.7.0 i 1.8.0 (wycofanie), a django.db.models.loading.get_model został usunięty w 1.8.2. Szczegółowe informacje na temat django-haystack #1206.

Dlatego dla django-haystack do pracy z django 1.9.0 potrzebujesz wersji zawierającej this commit; to znaczy django-haystack>=2.4.0.

+1

moja wersja to 2.4.1 i stóg django_apps.get_model ('mediainfo.artist') powraca z nr błędu: . Coś jeszcze, co mogę podać, aby uzyskać więcej informacji, aby pomóc w rozwiązaniu tego problemu? –

+0

haystack_model == modelu zwraca True, ale nie ma tu błędu podczas korzystania app_label i atrybut MODEL_NAME modelu: AttributeError: typ obiektu „Wykonawca” ma atrybut „MODEL_NAME” i AttributeError: typ obiektu „Wykonawca” ma atrybut „app_label”! !! –

+1

również ten problem - czy otrzymałeś poprawkę? dla mnie haystack_model == modelu i ten problem nie ustąpi –