开发者

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.

  1. Index a field with string data type along with text as well
  2. Indexing with text will help for keyword searching (as usual)
  3. 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜