Module: ActiveSearch
- Defined in:
- lib/activesearch/base.rb,
lib/activesearch/proxy.rb,
lib/activesearch/result.rb,
lib/activesearch/algolia.rb,
lib/activesearch/mongoid.rb,
lib/activesearch/version.rb,
lib/activesearch/mongoid/index.rb,
lib/activesearch/algolia/client.rb,
lib/activesearch/elastic_search.rb,
lib/activesearch/mongoid/full_text_search_query.rb
Defined Under Namespace
Modules: Algolia, Base, ElasticSearch, Mongoid
Classes: Proxy, Result
Constant Summary
collapse
- VERSION =
'0.3.1'
Class Method Summary
collapse
Class Method Details
.search(text) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/activesearch/algolia.rb', line 8
def self.search(text, conditions = {}, options = {})
locale = options[:locale] || I18n.locale
conditions[:locale] ||= locale
Proxy.new(text, conditions, options) do |text, conditions|
Algolia::Client.new.query(text, { tags: conditions_to_tags(conditions) }, options)["hits"].map! do |hit|
if hit["_tags"]
hit["_tags"].each do |tag|
_segments = tag.split(':')
unless _segments.empty? || _segments[1..-1].empty?
hit[_segments.first] = _segments[1..-1].join(':')
end
end
hit.delete("_tags")
end
hit
end
end
end
|
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/activesearch/base.rb', line 4
def self.strip_tags(value)
case value
when String
value.gsub(/<\/?[^>]*>/, '')
when Hash
value.each_with_object({}) { |(k,v),h| h[k] = strip_tags(v) }
when Array
value.map { |v| strip_tags(v) }
else
value
end
end
|