简体   繁体   English

如何使用Haystack和Whoosh搜索所有django模型?

[英]How to search in all django models with Haystack and Whoosh?

I'm using django and haystack with whoosh and I have several questions about them: 我正在将jango和haystack与whoosh一起使用,并且我对它们有几个问题:

1) When I attempt to search smth I should select all models which has indexed in whoosh. 1)当我尝试搜索某物时,我应该选择所有已在whoosh中建立索引的模型。 How can I set system to find values everywhere (on all models)? 如何设置系统以在任何地方(在所有型号上)查找值?

2) I have search input box but it doesn't work with haystack urls. 2)我有搜索输入框,但不适用于干草堆网址。 So my template (I'm using bootstrap): 所以我的模板(我正在使用引导程序):

<form  method="get" action="/search/" class="navbar-search pull-left">
   <input type="text" class="search-query" placeholder="Search">
</form>

And I have search url like in tutorial: 我有像教程中一样的搜索URL:

(r'^search/', include('haystack.urls')),

How say this form to start search immidiately and sends data to haystack? 怎么说这个表格立即开始搜索并将数据发送到干草堆?

For part 2, 对于第2部分,

since haystack uses ?q= to get queries, you should put name="q" into the input field, 由于haystack使用?q =来获取查询,因此您应该在输入字段中输入name =“ q”,

<form  method="get" action="/search/" class="navbar-search pull-left">
    <input name="q" type="text" class="search-query" placeholder="Search">
</form>

For part 1, 对于第1部分,

you can put in search_indexes.py into each model folder. 您可以将search_indexes.py放入每个模型文件夹中。 Not sure if there is more efficient method. 不知道是否有更有效的方法。 You can use ModelSearchView if you want to give users a choice to search which models. 如果要让用户选择搜索哪些模型,可以使用ModelSearchView。

You need to create RealTimeSearchIndex classes in your search_index.py file in the project root, and register these indexes with haystack. 您需要在项目根目录的search_index.py文件中创建RealTimeSearchIndex类,然后在haystack中注册这些索引。

Then you need to reindex your data using the haystack manage.py reindex command. 然后,您需要使用haystack manage.py reindex命令重新索引数据。

Then you need to provide a template for the search page that haystack will generate. 然后,您需要为haystack生成的搜索页面提供模板。

Keep reading the docs, it's all there. 继续阅读文档,一切都在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM