SolrQueryBuilder { public SolrQuery build() { ImmutableSet<String> fqClauses = fqClausesBuilder.build(); ImmutableSet<String> qClauses = qClausesBuilder.build(); ImmutableSet<String> fl = flBuilder.build(); ImmutableSet<String> subFacets = subFacetBuilder.build(); ImmutableList<SortClause> sorts = sortBuilder.build(); return new SolrQuery() .addFilterQuery(fqClauses.toArray(new String[0])) .setQuery( qClauses.isEmpty() ? "*:*" : qClauses.stream().filter(StringUtils::isNotBlank).collect(joining(" AND "))) .setFields( fl.isEmpty() ? "*" : fl.stream().filter(StringUtils::isNotBlank).collect(joining(","))) .setParam("json.facet", GSON.toJson(buildJsonFacetObject(facetField, subFacets))) .setSorts(sorts) .setRows(rows); }  SolrQueryBuilder<T> addFilterFieldByTerm(U field, Collection<String> values); SolrQueryBuilder<T> addFilterFieldByTerm(U field, String value); SolrQueryBuilder<T> addFilterFieldByRangeMin(U field, double min); SolrQueryBuilder<T> addFilterFieldByRangeMax(U field, double max); SolrQueryBuilder<T> addFilterFieldByRangeMinMax(U field,
                                                                                      double min,
                                                                                      double max); SolrQueryBuilder<T> addQueryFieldByTerm(U field, Collection<String> values); SolrQueryBuilder<T> addQueryFieldByTerm(U field, String value); final SolrQueryBuilder<T> setFieldList(Collection<U> fields); final SolrQueryBuilder<T> setFieldList(U field); final SolrQueryBuilder<T> setFacetField(U field); final SolrQueryBuilder<T> setSubFacetList(Collection<U> fields); SolrQueryBuilder<T> sortBy(U field, SolrQuery.ORDER order); SolrQueryBuilder<T> setRows(int rows); SolrQuery build(); static final int SOLR_MAX_ROWS; static final int DEFAULT_ROWS; }
@Test void byDefaultQueryAllAndRetrieveAllFields() { SolrQuery solrQuery = new SolrQueryBuilder<>().build(); assertThat(solrQuery.getFilterQueries()).isEmpty(); assertThat(solrQuery.getQuery()).isEqualTo("*:*"); assertThat(solrQuery.getFields()).isEqualTo("*"); }
@Test @DisplayName("Default number of rows is “big enough”, whatever that means") void defaultNumberOfRows() { assertThat(new SolrQueryBuilder<>().build().getRows()).isGreaterThanOrEqualTo(1000); }