2016-10-12 4 views
0

장고 - 건초 더미와 휙을 설치하고 건초 더미 문서를 따라 다듬었지만 검색 대상에 상관없이 항상 "결과가 없습니다"가 표시됩니다. 인덱스가 분명히 OK 임에도 불구하고 검색 페이지에서 ,덤불과 휙휙 어떤 결과도 반환하지 않음

from whoosh.index import open_dir 
ix = open_dir('mysite/whoosh_index') 
from pprint import pprint 
pprint(list(ix.searcher().documents())) 

을 올바르게 12 개 인덱스 자산의 모든 세부 사항을 반환

Indexing 12 assets 
    indexed 1 - 12 of 12 (worker PID: 1234). 

을 그리고 장고 쉘이 실행시 : 실행하는 경우

는 "manage.py rebuild_index는"올바르게 상태 그래서 인덱스가 괜찮은 것처럼 보이지만, 내가 무엇을 검색했는지에 상관없이 어떤 결과도 얻을 수 없으며, "결과를 찾을 수 없습니다"!

저는 StackOverflow (및 Google에서 팝업 된 다른 모든 곳)에 대한 다른 모든 유사한 질문에서 아무런 도움을받지 않고 조언을 따랐습니다.

누구에게 의견이 있습니까?

파일 사용 (간결성을 위해 편집) :

settings.py

INSTALLED_APPS = [ 
.... 
'haystack', 
'assetregister', 
.... 
] 

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

models.py

class Asset(models.Model): 
    asset_id = models.AutoField(primary_key=True) 
    asset_description = models.CharField(max_length=200) 
    asset_details = models.TextField(blank=True) 

search_indexes.py

from haystack import indexes 
from .models import Asset 

class AssetIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 
    asset_description = indexes.CharField(model_attr='asset_description') 

    def get_model(self): 
     return Asset 

    def no_query_found(self): 
     # The .exclude is a hack from another stackoverflow question that prevents it returning an empty queryset 
     return self.searchqueryset.exclude(content='foo') 

    def index_queryset(self, using=None): 
     return self.get_model().objects 

/템플릿/검색/indexes/assetregister/

<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.asset_description }}</a> 
      </p> 
     {% empty %} 
      <p>No results found.</p> 
     {% endfor %} 

    {% else %} 
     {# Show some example queries to run, maybe query syntax, something else? #} 
    {% endif %} 
</form> 

search.html에

urlpatterns = [ 
    url(r'^search/', include('haystack.urls')), 
] 

urls.py

{{ object.asset_description }} 
{{ object.asset_details }} 

asset_text.txt 그리고 단지의 경우 내 "핍 동결", 유용 :

Django==1.9.3 
django-cleanup==0.4.2 
django-haystack==2.5.0 
django-pyodbc-azure==1.9.3.0 
Pillow==3.2.0 
pyodbc==3.0.10 
Whoosh==2.7.4 

답변

0

이 미래의 사람들에게 이익을주기 위해 동일한 문제, 나는 비 전통적인 해결책을 발견했다. ...

그래서 나는 건초 더미 문서에 따라 모든 것을 두 번 확인했다. 한 번 올바르게 설치되면 django admin 인터페이스를 통해 색인을 볼 수있는 "django-haystackbrowser"라는 핍 패키지에 대해 알게되었습니다. 어떤 이유

내가 마지막으로 다시 검색 결과를 받기 시작

python manage.py runserver 

사용하여 서버를 재시작 한 번 나는 관리자 인터페이스에서 인덱스를 조회했다 (그리고 모든 이미 그것이 있어야로했다 확인) 후와!

문제의 원인을 알지 못했지만 그 패키지를 사용하여 색인을 보는 것이 고정되어 있는지는 모르겠지만 지금은 결과를 반환하는 것처럼 보입니다.

+0

나는 이것을 시도했다.처음에는 haystackbrowser가 Django1.10과 호환성 문제를 겪고있었습니다. 나는 응용 프로그램을 포크, 호환성 문제를 해결하고, 그것을 실행합니다. 관리자 패널에서 색인이 생성 된 모든 항목을 표시합니다. 서버를 다시 시작할 수 없으므로 아마도이 이유가 있지만이 응용 프로그램을 설치 한 후에도 결과가 표시되지 않습니다. –

관련 문제