Sunspot search: Searching with negative keyword
Hello I am using sunspot for searching: when I say:
keywords '"India" -"mountain"' do
minimum_match 1 end
It finds all the posts related to "India" keyword and which does not include "mountain" keyword. But when I want all the posts globally which should not include "mountain" keyword how should i do that? When tried with
开发者_开发百科keywords '-"mountain"' do
minimum_match 1 end
It returned 0 results.
Is there any way that we will pass only negative filter value to sunspot and retrieve all the records except the passed keyword?
This seems to be a feature/limitation of solr/sunspot but I have a workaround for this problem.
- Index a field with string data type along with text as well
- Indexing with text will help for keyword searching (as usual)
- Add AND condition in the sunspot solr block which will have without method to escape the unwanted string in the search.
This will search with conditions (keyword specified AND without the escape string)
精彩评论