SolrFacetQueryFactoryImpl extends AbstractSolrQueryFactory implements SolrFacetQueryFactory { @Override public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, List<String> facets, int facetValueLimit) { final SolrQuery query = getBaseQuery(facets); addQueryFacetParameters(query, queryFacetsSelections); query.setFacetLimit(facetValueLimit); return query; } SolrFacetQueryFactoryImpl(); @Override SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, List<String> facets, int facetValueLimit); @Override synchronized SolrQuery createCountFacetsQuery(List<String> facets);  }
@Test public void testCreateFacetQueryNoFacets() { QueryFacetsSelection selection = new QueryFacetsSelection(); SolrQuery query = instance.createFacetQuery(selection, FACET_FIELDS, 20); assertEquals("*:*", query.getQuery()); assertEquals(1, query.getFilterQueries().length); assertEquals(20, query.getFacetLimit()); }
@Test public void testCreateFacetQueryNoSelection() { Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() { { put("facet1", new FacetSelection(FacetSelectionType.AND, Collections.<String>emptySet())); put("facet2", new FacetSelection(FacetSelectionType.AND, Collections.<String>emptyList())); } }; SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection), FACET_FIELDS, 20); assertEquals("*:*", query.getQuery()); assertEquals(1, query.getFilterQueries().length); assertEquals(20, query.getFacetLimit()); }
@Test public void testCreateFacetQuerySelection() { Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() { { put("facet1", new FacetSelection(FacetSelectionType.AND, Arrays.asList("valueA"))); put("facet2", new FacetSelection(FacetSelectionType.AND, Arrays.asList("valueB", "valueC"))); put("facet3", new FacetSelection(FacetSelectionType.AND, Collections.<String>emptyList())); } }; SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection), FACET_FIELDS, 20); assertEquals("*:*", query.getQuery()); assertEquals(4, query.getFilterQueries().length); assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet1:\"valueA\"")); assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet2:\"valueB\"")); assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet2:\"valueC\"")); assertEquals(20, query.getFacetLimit()); }
@Test public void testCreateFacetQuerySelectionAndQuery() { Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() { { put("facet1", new FacetSelection(FacetSelectionType.AND, Arrays.asList("value A"))); } }; SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection("query string", selection), FACET_FIELDS, 20); assertEquals("query string", query.getQuery()); assertEquals(2, query.getFilterQueries().length); assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet1:\"value\\ A\"")); assertEquals(20, query.getFacetLimit()); }