我正在使用Haystack和Whoosh構建網站的搜索引擎部分。在我的情況下,Whoosh運行得非常好,但是我需要從我的視圖中顯示額外的信息取決於搜索的結果。使用Whoosh自定義視圖
在我的Django的觀點我用這樣的事情,在虛擬的信息顯示:
dummy = "dummy"
return render_to_response('images/ib_large_image.html', {'dummy': dummy},
context_instance=RequestContext(request))
所以,基本上我要進行個性化搜索的視圖我的變量顯示在搜索模板。
這裏有一些配置:
設置:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
'DEFAULT_OPERATOR': 'AND',
'SITECONF': 'search_sites',
'SEARCH_RESULTS_PER_PAGE': 20
},
}
search_sites.py:
import haystack
haystack.autodiscover()
搜索>指標> imageboard> image_text.txt:
{{ object.name }}
{{ object.description }}
imageboard> search_indexes.py:
import datetime
from haystack import indexes
from imageboard.models import Image
class ImageIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
return Image
def index_queryset(self):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(uploaded_date__lte=datetime.datetime.now())
imageboard> urls.py:
urlpatterns = patterns('imageboard.views',
(r'^search/', include('haystack.urls')),
)
我配置我的看法是這樣,但它不工作:
imageboard > views.py:
from haystack.views import SearchView
def search(request):
return SearchView(template='search.html')(request)
任何想法??
您可以擴展'它不起作用'嗎? – Spacedman 2012-02-19 21:49:02
嗯,我解決了我的問題。我重構了我的模型,不需要觸摸搜索引擎。不管怎麼說,還是要謝謝你。 – 2012-02-19 21:49:25