I have a Rails API I am using as a backend for a Swift iOS app. I want to allow users of the Swift app to search authors and books, and I have API endpoints for "all books" and "all authors."
Do I need to write logic in an API endpoint for search, or is there a standard syntax, something like /api/authors?utf8=✓&q%5Btitle_contains%5D=magic
I have Redis/soulmate installed in the web app for search but not sure how to extend this to an API endpoint.
No. Rails does not have any search utilities built in. Which is due to fact that there are so many possible way to achieve it depending on the requirements.
Simple filtering can be done with params and scoping:
def index
@dogs = Dog.all
@dogs = Dog.where(status: params[:status].to_sym) if params[:status]
end
There are gems which provide full text search with Lucene, Solr, Elasticsearch and many others.