Class: Elasticity::Search::Facade
- Inherits:
-
Object
- Object
- Elasticity::Search::Facade
- Defined in:
- lib/elasticity/search.rb
Overview
Elasticity::Search::Facade provides a simple interface for defining a search and provides different ways of executing it against Elasticsearch. This is usually the main entry point for search.
Instance Attribute Summary collapse
-
#search_definition ⇒ Object
Returns the value of attribute search_definition.
Instance Method Summary collapse
-
#active_records(relation) ⇒ Object
Performs the search only fetching document ids using it to load ActiveRecord objects from the provided relation.
-
#document_hashes ⇒ Object
Performs the search using the default search type and returning an iterator that will yield hash representations of the documents.
-
#documents(mapper) ⇒ Object
Performs the search using the default search type and returning an iterator that will yield each document, converted using the provided mapper.
-
#initialize(client, search_definition) ⇒ Facade
constructor
Creates a new facade for the given search definition, providing a set of helper methods to trigger different type of searches and results interpretation.
-
#scan_documents(mapper, **options) ⇒ Object
Performs the search using the scan search type and the scoll api to iterate over all the documents as fast as possible.
Constructor Details
#initialize(client, search_definition) ⇒ Facade
Creates a new facade for the given search definition, providing a set of helper methods to trigger different type of searches and results interpretation.
47 48 49 50 |
# File 'lib/elasticity/search.rb', line 47 def initialize(client, search_definition) @client = client @search_definition = search_definition end |
Instance Attribute Details
#search_definition ⇒ Object
Returns the value of attribute search_definition.
43 44 45 |
# File 'lib/elasticity/search.rb', line 43 def search_definition @search_definition end |
Instance Method Details
#active_records(relation) ⇒ Object
Performs the search only fetching document ids using it to load ActiveRecord objects from the provided relation. It returns the relation matching the objects found on ElasticSearch.
79 80 81 |
# File 'lib/elasticity/search.rb', line 79 def active_records(relation) ActiveRecordProxy.new(@client, @search_definition, relation) end |
#document_hashes ⇒ Object
Performs the search using the default search type and returning an iterator that will yield hash representations of the documents.
54 55 56 57 |
# File 'lib/elasticity/search.rb', line 54 def document_hashes return @document_hashes if defined?(@document_hashes) @document_hashes = LazySearch.new(@client, @search_definition) end |
#documents(mapper) ⇒ Object
Performs the search using the default search type and returning an iterator that will yield each document, converted using the provided mapper
61 62 63 64 65 66 |
# File 'lib/elasticity/search.rb', line 61 def documents(mapper) return @documents if defined?(@documents) @documents = LazySearch.new(@client, @search_definition) do |hit| mapper.(hit) end end |
#scan_documents(mapper, **options) ⇒ Object
Performs the search using the scan search type and the scoll api to iterate over all the documents as fast as possible. The sort option will be discarded.
More info: www.elasticsearch.org/guide/en/elasticsearch/guide/current/scan-scroll.html
72 73 74 75 |
# File 'lib/elasticity/search.rb', line 72 def scan_documents(mapper, **) return @scan_documents if defined?(@scan_documents) @scan_documents = ScanCursor.new(@client, @search_definition, mapper, **) end |