The search I use aaf for defaults to excluding inactive people.
Person.find_by_contents(keyword, {}, { :conditions => { :inactive => false } })
The app needs to know if a search filtered out any results. Eg: the index returns 6 people, and the inactivity filter takes 1 out. I've added an all_hits accessor to the SearchResults? class to make this number available (index_hits may be a better name).
Here's the diff I applied to the copy of the plugin I was working with, I haven't bothered creating a patch file because it's only a couple of lines:
Index: /trunk/rails/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb
===================================================================
--- /trunk/rails/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb (revision 966)
+++ /trunk/rails/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb (revision 1003)
@@ -80,8 +80,9 @@
# decorator that adds a total_hits accessor to search result arrays
class SearchResults
- attr_reader :total_hits
- def initialize(results, total_hits)
+ attr_reader :total_hits, :all_hits
+ def initialize(results, total_hits, all_hits)
@results = results
@total_hits = total_hits
+ @all_hits = all_hits
end
def method_missing(symbol, *args, &block)
Index: /trunk/rails/vendor/plugins/acts_as_ferret/lib/class_methods.rb
===================================================================
--- /trunk/rails/vendor/plugins/acts_as_ferret/lib/class_methods.rb (revision 966)
+++ /trunk/rails/vendor/plugins/acts_as_ferret/lib/class_methods.rb (revision 1003)
@@ -62,7 +62,7 @@
# set (e.g. :num_docs and some :conditions).
def find_by_contents(q, options = {}, find_options = {})
- total_hits, result = find_records_lazy_or_not q, options, find_options
+ total_hits, all_hits, result = find_records_lazy_or_not q, options, find_options
logger.debug "Query: #{q}\ntotal hits: #{total_hits}, results delivered: #{result.size}"
- return SearchResults.new(result, total_hits)
+ return SearchResults.new(result, total_hits, all_hits)
end
@@ -151,5 +151,5 @@
def ar_find_by_contents(q, options = {}, find_options = {})
result_ids = {}
- total_hits = find_id_by_contents(q, options) do |model, id, score, data|
+ all_hits = total_hits = find_id_by_contents(q, options) do |model, id, score, data|
# stores ids, index of each id for later ordering of
# results, and score
@@ -173,5 +173,5 @@
end
- [ total_hits, result ]
+ [ total_hits, all_hits, result ]
end