Skip to content

Instantly share code, notes, and snippets.

@krisleech
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/858bd0bfc6dca0c60752 to your computer and use it in GitHub Desktop.
Save krisleech/858bd0bfc6dca0c60752 to your computer and use it in GitHub Desktop.
Search wrapper

Low level search

Updating the index

When a resource is CRUD'd it must update the Search index:

Search.put(:study, attributes) # create, update
Search.rm(:study, id) # delete

If the resource has an attributes method you can pass the resource directly instead of a hash:

Search.put(:study, study) # create, update

In fact why not just pass the object and use its class as the namespace:

Search.put(study)

Searching

Search.get(:study, { 'organisation_id_in' => [12,16,72] }) # => [1,2,3]

Returns an array of ids.

To get a collection pass a repository object instead. The object must have a find method which accepts an array of ids.

Search.get(Study, { 'organisation_id_in' => [12,16,72] }) # => [Study(id: 1), Study(id: 2), Study(id: 3)]

Adapters

Internally the work is delegated to an adapter which wraps an indexer such as Elastic Search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment