Class: Noiseless::MultiSearch
- Inherits:
-
Object
- Object
- Noiseless::MultiSearch
- Defined in:
- lib/noiseless/multi_search.rb
Instance Method Summary collapse
- #aggregation(name, type) ⇒ Object
- #facet_sample_slope(value) ⇒ Object
- #filter(field, value) ⇒ Object
- #geo_distance(field, lat:, lon:, distance:) ⇒ Object
-
#initialize(models: nil, indexes: nil, connection: nil) ⇒ MultiSearch
constructor
A new instance of MultiSearch.
- #limit(size) ⇒ Object
-
#match(field, value) ⇒ Object
Delegate query building methods to the internal builder.
- #multi_match(query, fields) ⇒ Object
- #offset(from) ⇒ Object
- #paginate(page, per_page) ⇒ Object
- #pinned_hits(value) ⇒ Object
- #remove_duplicates(value: true) ⇒ Object
- #search {|@builder| ... } ⇒ Object
- #sort(field, direction = :asc) ⇒ Object
Constructor Details
#initialize(models: nil, indexes: nil, connection: nil) ⇒ MultiSearch
Returns a new instance of MultiSearch.
5 6 7 8 9 10 |
# File 'lib/noiseless/multi_search.rb', line 5 def initialize(models: nil, indexes: nil, connection: nil) @models = resolve_models(models) @indexes = resolve_indexes(indexes) @connection = connection || Noiseless.config.default_connection @builder = QueryBuilder.new(nil) end |
Instance Method Details
#aggregation(name, type) ⇒ Object
78 79 80 81 |
# File 'lib/noiseless/multi_search.rb', line 78 def aggregation(name, type, **) @builder.aggregation(name, type, **) self end |
#facet_sample_slope(value) ⇒ Object
93 94 95 96 |
# File 'lib/noiseless/multi_search.rb', line 93 def facet_sample_slope(value) @builder.facet_sample_slope(value) self end |
#filter(field, value) ⇒ Object
53 54 55 56 |
# File 'lib/noiseless/multi_search.rb', line 53 def filter(field, value, **) @builder.filter(field, value, **) self end |
#geo_distance(field, lat:, lon:, distance:) ⇒ Object
83 84 85 86 |
# File 'lib/noiseless/multi_search.rb', line 83 def geo_distance(field, lat:, lon:, distance:, **) @builder.geo_distance(field, lat: lat, lon: lon, distance: distance, **) self end |
#limit(size) ⇒ Object
63 64 65 66 |
# File 'lib/noiseless/multi_search.rb', line 63 def limit(size) @builder.limit(size) self end |
#match(field, value) ⇒ Object
Delegate query building methods to the internal builder
43 44 45 46 |
# File 'lib/noiseless/multi_search.rb', line 43 def match(field, value, **) @builder.match(field, value, **) self end |
#multi_match(query, fields) ⇒ Object
48 49 50 51 |
# File 'lib/noiseless/multi_search.rb', line 48 def multi_match(query, fields, **) @builder.multi_match(query, fields, **) self end |
#offset(from) ⇒ Object
68 69 70 71 |
# File 'lib/noiseless/multi_search.rb', line 68 def offset(from) @builder.offset(from) self end |
#paginate(page, per_page) ⇒ Object
73 74 75 76 |
# File 'lib/noiseless/multi_search.rb', line 73 def paginate(page, per_page) @builder.paginate(page: page, per_page: per_page) self end |
#pinned_hits(value) ⇒ Object
98 99 100 101 |
# File 'lib/noiseless/multi_search.rb', line 98 def pinned_hits(value) @builder.pinned_hits(value) self end |
#remove_duplicates(value: true) ⇒ Object
88 89 90 91 |
# File 'lib/noiseless/multi_search.rb', line 88 def remove_duplicates(value: true) @builder.remove_duplicates(value: value) self end |
#search {|@builder| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/noiseless/multi_search.rb', line 12 def search(&block) yield(@builder) if block client = Noiseless.connections.client(@connection) ast = @builder.to_ast # Override indexes in AST with our multi-model indexes ast_with_indexes = AST::Root.new( indexes: @indexes, bool: ast.bool, sort: ast.sort, paginate: ast.paginate, vector: ast.vector, collapse: ast.collapse, search_after: ast.search_after, aggregations: ast.aggregations, hybrid: ast.hybrid, pipeline: ast.pipeline, image_query: ast.image_query, conversation: ast.conversation, joins: ast.joins, remove_duplicates: ast.remove_duplicates, facet_sample_slope: ast.facet_sample_slope, pinned_hits: ast.pinned_hits ) raw_response = client.search(ast_with_indexes) MultiSearchResponse.new(raw_response, @models, @indexes) end |
#sort(field, direction = :asc) ⇒ Object
58 59 60 61 |
# File 'lib/noiseless/multi_search.rb', line 58 def sort(field, direction = :asc, **) @builder.sort(field, direction, **) self end |