lib/activesearch/algolia.rb in activesearch-0.0.13 vs lib/activesearch/algolia.rb in activesearch-0.0.14
- old
+ new
@@ -1,22 +1,28 @@
require "activesearch/algolia/client"
require "activesearch/base"
require "activesearch/proxy"
module ActiveSearch
- def self.search(text)
- Proxy.new(text) do |text|
- Algolia::Client.new.query(text)["hits"].map! do |hit|
+ def self.search(text, conditions = {})
+ Proxy.new(text, conditions) do |text, conditions|
+
+ Algolia::Client.new.query(text, tags: conditions_to_tags(conditions))["hits"].map! do |hit|
if hit["_tags"]
hit["_tags"].each do |tag|
k, v = tag.split(':')
hit[k] = v
end
hit.delete("_tags")
end
hit
end
end
+ end
+
+ protected
+ def self.conditions_to_tags(conditions)
+ conditions.map { |c| c.join(':') }.join(',')
end
module Algolia
def self.included(base)
base.class_eval do
\ No newline at end of file