So been using Sphinx with the UltraSphinx plugin and I came across the requirement to use filters to reject records. Unfortunately in the plugin the filters are hardwired to submit the ‘exclude’ parameter as ‘false’ i.e include. Time for a quick hack I think…….
Very easy to fix, just open up the ‘internals.rb’ file in the UltraSphinx plugin or include the gem using ‘rake gems:unpack GEM=ultrasphinx’ (need to have config.gem “ultrasphinx” set in envrinoment.rb) and then find that file.
Ok, so found the file? On line 97 is this loop:
Array(opts['filters']).each do |field, value|
....
begin
case value
when Integer, Float, BigDecimal, NilClass, Array
# XXX Hack to force floats to be floats
value = value.to_f if type == 'float'
# Just bomb the filter in there
request.filters << Riddle::Client::Filter.new(field, Array(value), false)
when Range
....
end
The ‘Riddle::Client::Filter.new(field, Array(value), false)’ call is the one we need to change (the ‘false’ is the exclude param).
















