Skip to content

Instantly share code, notes, and snippets.

@NuckChorris
Last active December 28, 2015 05:50
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 NuckChorris/414c22e69ca4c3252d9b to your computer and use it in GitHub Desktop.
Save NuckChorris/414c22e69ca4c3252d9b to your computer and use it in GitHub Desktop.
class AnimeResource < JSONAPI::Resource
# Specify the Chewy index class to utilize for search queries
index MediaIndex::Anime
# Queries are extracted from params[:filter] and used to form an ElasticSearch query
# If there are no query filters in the params, skips the entire ES query step
query :season, verify: -> (values, _ctx) { values.in? Anime::SEASONS }
query :year
# Filters will often be unnecessary, since most things Postgres can do, Elastic can too.
# However, any filters declared will be applied after internal conversion from ElasticSearch to ActiveModel
filter :slug, apply: -> (records, value, _options) { records.by_slug(value) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment