flex-models - Result Extenders

The flex-models gem adds a few extender to the standard extended Flex::Result object (see Result Extenders). They are aware of your models, so you can do, for example:

# search the index
result = MyClass.my_search :my_tag => 'the tag value'

# retrieve the document from the index as usual
collection = result.collection
#=> [ ... the hits array ... ]

# you can load one record at a time
document = result['hits']['hits'][0]
document.load
#=> #<Project id: 167017 ...> # ActiveRecord object loaded from the DB

# or easier
collection.first.load
#=> #<Project id: 167017 ...> # same thing

# or retrieve all the records from your DB in one go
loaded_collection = result.loaded_collection
#=> [ #<Project id: 167017 ...>, #<Comment id: 2342 ...>, ... ]

# notice that record can belong to different models

Flex Model Result Extenders