Method: Chewy::Search::Request#first
- Defined in:
- lib/chewy/search/request.rb
#first ⇒ Chewy::Index #first(limit) ⇒ Array<Chewy::Index>
Return first wrapper object or a collection of first N wrapper objects if the argument is provided. Tries to use cached results of possible. If the amount of cached results is insufficient - performs a new request.
891 892 893 894 895 896 897 898 899 900 |
# File 'lib/chewy/search/request.rb', line 891 def first(limit = UNDEFINED) request_limit = limit == UNDEFINED ? 1 : limit if performed? && (terminated_early? || request_limit <= size || size == total) limit == UNDEFINED ? wrappers.first : wrappers.first(limit) else result = except(EXTRA_STORAGES).limit(request_limit).to_a limit == UNDEFINED ? result.first : result end end |