I have a microservice I am designing for getting "Book" information, and one of the capabilities is to query Solr and fuse it with some DB results that I queried.
I am looking for, what I am calling a "query maker pattern" something that will generate dynamic solr queries. The idea in my head was a class like
public class Query {
public Attribute[];
}
public class Attribute {
public String type;
public String value;
}
But I'm not sure what the best way to generate dynamic queries in an object oriented way. There is a bad way of having a bunch of functions that append strings like:
public function String addSort(String value, Boolean isAscending){
return value + "+" + (isAscending ? "asc" : "desc");
}
public function String addFacet(String facetName){
etc etc
}
It would be best to have something like a toString() function for the Query object, and then using that as a the request to Solr?