So, I'm sure this must have been asked before but I can't seem to find anything. The thing is that when I'm programming search features for web apps, it never feels quite right for me.
I'm using Ruby on Rails, but I guess this is a question that applies to any situation in which you are using a RESTful MVC pattern.
Let's say you have a Resource (e.g. Users, ToDos, …) you want to search through. As soon as the app grows this won't be feasible with simple LIKE-queries anymore and you start using an index (e.g. Solr, ElasticSearch, Lucene, …). The indexed resource also tends to be compound data from the Resource and it's associated objects (a User's location, the ToDos creator, …).
How do we best represent this?
- Is it a GET to /resources (Resource#index)? It is a selective list of the main resource, but then again it's actually this compound thing and if the search functionality is extensive it really tends to bloat up the Model's code.
- Is it a POST to /searches (Search#create)? We are creating a search but are not saving it. Instead it kind of gets transformed into a set of SearchResults
- So, is it a GET to a SearchResult (SearchResult#show)? But it doesn't have an ID. I guess the SearchIndex is kind of the Database for that model, but you wouldn't really create a SearchResult, right? It's more of a Search#create that ends in a SearchResult#show but that also feels wonky to me.
Aucun commentaire:
Enregistrer un commentaire