UserConfigRequestQueryConverter extends AbstractConverterAware<UserConfigRequest, SolrQuery> { @Override public SolrQuery convert(UserConfigRequest userConfigRequest) { SolrQuery userConfigQuery = new SolrQuery(); userConfigQuery.setQuery("*:*"); int startIndex = StringUtils.isNotEmpty(userConfigRequest.getStartIndex()) && StringUtils.isNumeric(userConfigRequest.getStartIndex()) ? Integer.parseInt(userConfigRequest.getStartIndex()) : 0; int maxRows = StringUtils.isNotEmpty(userConfigRequest.getPageSize()) && StringUtils.isNumeric(userConfigRequest.getPageSize()) ? Integer.parseInt(userConfigRequest.getPageSize()) : 10; SolrQuery.ORDER order = userConfigRequest.getSortType() != null && SolrQuery.ORDER.desc.equals(SolrQuery.ORDER.valueOf(userConfigRequest.getSortType())) ? SolrQuery.ORDER.desc : SolrQuery.ORDER.asc; String sortBy = StringUtils.isNotEmpty(userConfigRequest.getSortBy()) ? userConfigRequest.getSortBy() : FILTER_NAME; String filterName = StringUtils.isBlank(userConfigRequest.getFilterName()) ? "*" : "*" + userConfigRequest.getFilterName() + "*"; userConfigQuery.addFilterQuery(String.format("%s:%s", ROW_TYPE, userConfigRequest.getRowType())); userConfigQuery.addFilterQuery(String.format("%s:%s", FILTER_NAME, SolrUtil.makeSearcableString(filterName))); userConfigQuery.setStart(startIndex); userConfigQuery.setRows(maxRows); SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(sortBy, order); List<SolrQuery.SortClause> sort = new ArrayList<>(); sort.add(sortOrder); userConfigQuery.setSorts(sort); SolrUtil.addListFilterToSolrQuery(userConfigQuery, CLUSTER, userConfigRequest.getClusters()); return userConfigQuery; }  @Override SolrQuery convert(UserConfigRequest userConfigRequest);  }
@Test public void testConvert() { UserConfigRequest request = new UserConfigRequest(); request.setRowType("myRowType"); request.setFilterName("myFilterName"); request.setClusters("cl1,cl2"); SolrQuery queryResult = underTest.convert(request); assertEquals("?q=*%3A*&fq=rowtype%3AmyRowType&fq=filtername%3A*myFilterName*&fq=cluster%3A%28cl1+OR+cl2%29&start=0&rows=10&sort=filtername+asc", queryResult.toQueryString()); }