I have a field-based search (+F1:…, +F2:…), and a global search
(which queries all fields with the given terms). Both of them works ok,
but I would like to exclude a term from the global search (though it
should remain indexed to support the field-based search), is it
possible?
Of course, the thread topic should be ‘Excluding a FIELD on a search’.
I’m sorry…
Raul M. wrote:
Hi there,
I have a model with indexed fields (F1, F2, F3…).
I have a field-based search (+F1:…, +F2:…), and a global search
(which queries all fields with the given terms). Both of them works ok,
but I would like to exclude a term from the global search (though it
should remain indexed to support the field-based search), is it
possible?
I have a field-based search (+F1:…, +F2:…), and a global search
(which queries all fields with the given terms). Both of them works ok,
but I would like to exclude a term from the global search (though it
should remain indexed to support the field-based search), is it
possible?
Hi Raul,
You probably want to do something like this;
require 'rubygems'
require 'ferret'
i = Ferret::I.new(:default_field => [:f1, :f2, :f3])
i << {:f1 => "hello"}
i << {:f2 => "hello"}
i << {:f3 => "hello"}
i << {:f4 => "hello"}
puts "global"
i.search_each("hello") {|d, s| puts "#{d}"}
puts "field"
i.search_each("f4:hello") {|d, s| puts "#{d}"}
This should print this out;
global
0
1
2
field
3
This should be pretty simple to do through acts_as_ferret too.
Cheers,
Dave
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.