Last active
December 28, 2015 05:50
-
-
Save NuckChorris/414c22e69ca4c3252d9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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