Class: Gum::Search
Class Method Summary collapse
- .inherited(klass) ⇒ Object
- .order_by(*args) ⇒ Object
- .query(attr) ⇒ Object
- .scope(&block) ⇒ Object
- .searchable(*attrs) ⇒ Object
- .use(type) ⇒ Object
Instance Method Summary collapse
-
#initialize(params) ⇒ Search
constructor
A new instance of Search.
- #search ⇒ Object
- #to_query ⇒ Object
Methods included from Filters
Constructor Details
#initialize(params) ⇒ Search
Returns a new instance of Search.
42 43 44 45 |
# File 'lib/gum/search.rb', line 42 def initialize(params) @params = params @q = params[query_param] end |
Class Method Details
.inherited(klass) ⇒ Object
12 13 14 15 16 |
# File 'lib/gum/search.rb', line 12 def self.inherited(klass) klass.fields = Set.new klass.filters = [] klass.orders = [] end |
.order_by(*args) ⇒ Object
36 37 38 39 40 |
# File 'lib/gum/search.rb', line 36 def self.order_by(*args) Factory.build(Gum::OrderBy, args) do |order| orders.push order end end |
.query(attr) ⇒ Object
32 33 34 |
# File 'lib/gum/search.rb', line 32 def self.query(attr) self.query_param = attr end |
.scope(&block) ⇒ Object
24 25 26 |
# File 'lib/gum/search.rb', line 24 def self.scope(&block) self.scope = block end |
.searchable(*attrs) ⇒ Object
28 29 30 |
# File 'lib/gum/search.rb', line 28 def self.searchable(*attrs) self.fields += attrs.flatten end |
.use(type) ⇒ Object
19 20 21 22 |
# File 'lib/gum/search.rb', line 19 def self.use(type) raise ArgumentError, 'type must be a Chewy::Type' unless type < Chewy::Type self.type = type end |
Instance Method Details
#search ⇒ Object
51 52 53 54 55 56 |
# File 'lib/gum/search.rb', line 51 def search to_query.load(scope: scope) rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e @error = e..match(/QueryParsingException\[([^;]+)\]/).try(:[], 1) type.none end |
#to_query ⇒ Object
47 48 49 |
# File 'lib/gum/search.rb', line 47 def to_query type.query(query).filter(compile_filters).order(compile_orders) end |