简体   繁体   English

在solr上使用haystack(django)在结果中搜索

[英]Search within results using haystack (django) on solr

I'm trying to search within a previous search on my site. 我正在尝试在我网站上的上一个搜索中进行搜索。

It would be like "sky", and then after getting the results, I'd hit the radio button for 'Search within results'. 就像“天空”,然后在获得结果后,我点击了“在结果内搜索”单选按钮。 Then I would type in "blue" (assuming the search bar is now empty). 然后,我将输入“ blue”(假设搜索栏现在为空)。 Thus, I would search on "sky blue". 因此,我将搜索“天蓝色”。

I've been looking around quite a bit for solutions to this, but nothing seems to have been posted in this explicivity. 我一直在寻找很多解决方案,但是似乎没有任何公开。

I'm passing the form to a custom form, but I've been unable to access the radio box. 我正在将表单传递给自定义表单,但无法访问单选框。 I would LIKE to just save the original query, and then if I've selected to search within, I would just make an append. 我希望仅保存原始查询,然后如果选择在其中进行搜索,则将添加一个追加。

Any ideas? 有任何想法吗?

Thanks. 谢谢。

Do you mean using a checkbox? 您的意思是使用复选框吗? Assuming you are clearing your search field after a form request. 假设您在表单请求后清除搜索字段。 I'm not sure how much of the django form you are using but at a basic level, after an initial search, you can push the value from the view to the template in its own variable: 我不确定您使用的是django表单的多少,但在基本级别上,在进行初步搜索后,您可以将视图中的值推入其自己的变量中的模板:

initial_keyword = 'sky'  # default to empty if none entered

In the template, insert the following within your html form tags: 在模板中,将以下内容插入html表单标签:

<input type="hidden" name="initial_keyword" value="{{ initial_keyword }}" />

Check the values of request.GET , you should see initial_keyword and maybe your checkbox. 检查request.GET的值,您应该看到initial_keyword以及您的复选框。 From there, if checkbox is checked, combine initial_keyword and the newly entered value. 从那里开始,如果选中了复选框,则将initial_keyword和新输入的值组合在一起。

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

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