class Elasticity::Search::Facade
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.
Attributes
Public Class Methods
Creates a new facade for the given search definition, providing a set of helper methods to trigger different type of searches and results interpretation.
# File lib/elasticity/search.rb, line 50 def initialize(client, search_definition) @client = client @search_definition = search_definition end
Public Instance Methods
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.
# File lib/elasticity/search.rb, line 82 def active_records(relation) ActiveRecordProxy.new(@client, @search_definition, relation) end
Performs the search using the default search type and returning an iterator that will yield hash representations of the documents.
# File lib/elasticity/search.rb, line 57 def document_hashes(search_args = {}) return @document_hashes if defined?(@document_hashes) @document_hashes = LazySearch.new(@client, @search_definition, search_args) end
Performs the search using the default search type and returning an iterator that will yield each document, converted using the provided mapper
# File lib/elasticity/search.rb, line 64 def documents(mapper, search_args = {}) return @documents if defined?(@documents) @documents = LazySearch.new(@client, @search_definition, search_args) do |hit| mapper.(hit) end end
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
# File lib/elasticity/search.rb, line 75 def scan_documents(mapper, **options) return @scan_documents if defined?(@scan_documents) @scan_documents = ScanCursor.new(@client, @search_definition, mapper, **options) end