r/learnprogramming•
mixuhd

Question about repository pattern with searching by user input..

I have this Java web application where users can search, lets say Products with an quite complicated search form with lots of fields, so the query string that gets sent to the database will be complicated to build. I'm using repository pattern and a MVC framework.

Here comes my main problem: Where should I build the query string (Could be a SQL query string, ElasticSearch query string, .... so I need it to be decoupled from a specific database)

  1. Should the repository's search method accept a Map<String,String> of the form and build the query string (Where? In a private method?)

  2. Should the repository accept the raw query string, so the query would be built in the controller (Again, where? In the controller in a private method)

At the moment I'm using the 2nd way.. I have Util class with a String formToQueryString(ProductSearchForm psf) I know this is not the best way to do this. If anyone has any ideas, or even better examples to show me please do! What design patterns and resources should I look into?

Posted Mar 16, 2016, 1:07 PM UTC

10
Loading comments…