Module: Lycra::Search::Scoping
- Defined in:
- lib/lycra/search/scoping.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #aggregate(agg = nil) ⇒ Object (also: #aggregation)
- #aggregations ⇒ Object
- #filter(fltr = nil) ⇒ Object
- #filter_by(attr, vals) ⇒ Object
- #filters ⇒ Object
- #find(id) ⇒ Object
- #find_by(*args) ⇒ Object
- #post_filter(fltr = nil) ⇒ Object
- #post_filters ⇒ Object
- #query_filter(fltr = nil) ⇒ Object
- #query_filters ⇒ Object
- #reaggregate(agg) ⇒ Object
- #refilter(fltr) ⇒ Object
- #repost_filter(fltr) ⇒ Object
- #requery_filter(fltr) ⇒ Object
- #resort(srt = nil) ⇒ Object
- #sort(srt = nil) ⇒ Object
- #sorter ⇒ Object
- #where(*args) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/lycra/search/scoping.rb', line 4 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#aggregate(agg = nil) ⇒ Object Also known as: aggregation
12 13 14 15 |
# File 'lib/lycra/search/scoping.rb', line 12 def aggregate(agg=nil) aggregations << agg unless agg.nil? self end |
#aggregations ⇒ Object
8 9 10 |
# File 'lib/lycra/search/scoping.rb', line 8 def aggregations @aggregations ||= Lycra::Search::Aggregations.new end |
#filter(fltr = nil) ⇒ Object
27 28 29 30 |
# File 'lib/lycra/search/scoping.rb', line 27 def filter(fltr=nil) filters << fltr unless fltr.nil? self end |
#filter_by(attr, vals) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/lycra/search/scoping.rb', line 79 def filter_by(attr, vals) return self if vals.nil? || vals.empty? attr_filter = { bool: { must: [{ or: vals.map { |val| {term: {attr.to_sym => val}} } }] } } filter(filter << attr_filter) self end |
#filters ⇒ Object
23 24 25 |
# File 'lib/lycra/search/scoping.rb', line 23 def filters @filters ||= Lycra::Search::Filters.new end |
#find(id) ⇒ Object
108 109 110 |
# File 'lib/lycra/search/scoping.rb', line 108 def find(id) find_by(id: id).first end |
#find_by(*args) ⇒ Object
104 105 106 |
# File 'lib/lycra/search/scoping.rb', line 104 def find_by(*args) unfiltered.offset(0).limit(1).where(*args).first end |
#post_filter(fltr = nil) ⇒ Object
55 56 57 58 |
# File 'lib/lycra/search/scoping.rb', line 55 def post_filter(fltr=nil) post_filters << fltr unless fltr.nil? self end |
#post_filters ⇒ Object
51 52 53 |
# File 'lib/lycra/search/scoping.rb', line 51 def post_filters @post_filters ||= Lycra::Search::Filters.new end |
#query_filter(fltr = nil) ⇒ Object
41 42 43 44 |
# File 'lib/lycra/search/scoping.rb', line 41 def query_filter(fltr=nil) query.filter fltr self end |
#query_filters ⇒ Object
37 38 39 |
# File 'lib/lycra/search/scoping.rb', line 37 def query_filters query.filters end |
#reaggregate(agg) ⇒ Object
18 19 20 21 |
# File 'lib/lycra/search/scoping.rb', line 18 def reaggregate(agg) @aggregations = Lycra::Search::Aggregations.new aggregate agg end |
#refilter(fltr) ⇒ Object
32 33 34 35 |
# File 'lib/lycra/search/scoping.rb', line 32 def refilter(fltr) @filters = Lycra::Search::Filters.new filter fltr end |
#repost_filter(fltr) ⇒ Object
60 61 62 63 |
# File 'lib/lycra/search/scoping.rb', line 60 def repost_filter(fltr) @post_filters = Lycra::Search::Filters.new post_filter fltr end |
#requery_filter(fltr) ⇒ Object
46 47 48 49 |
# File 'lib/lycra/search/scoping.rb', line 46 def requery_filter(fltr) query.refilter fltr self end |
#resort(srt = nil) ⇒ Object
74 75 76 77 |
# File 'lib/lycra/search/scoping.rb', line 74 def resort(srt=nil) @sorter = Lycra::Search::Sort.new sort srt end |
#sort(srt = nil) ⇒ Object
69 70 71 72 |
# File 'lib/lycra/search/scoping.rb', line 69 def sort(srt=nil) sorter << srt unless srt.nil? self end |
#sorter ⇒ Object
65 66 67 |
# File 'lib/lycra/search/scoping.rb', line 65 def sorter @sorter ||= Lycra::Search::Sort.new end |
#where(*args) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/lycra/search/scoping.rb', line 95 def where(*args) args..each do |attr, vals| vals = [vals] unless vals.is_a?(Array) filter_by(attr, vals) end self end |