QueryFacetsSelectionParametersConverter implements PageParametersConverter<QueryFacetsSelection> { @Override public QueryFacetsSelection fromParameters(PageParameters params) { final String query = params.get(QUERY).toOptionalString(); final List<StringValue> facetSelectionTypes = params.getValues(FILTER_QUERY_TYPE); final List<StringValue> facetValues = params.getValues(FILTER_QUERY); final HashMap<String, FacetSelection> selection = Maps.newLinkedHashMapWithExpectedSize(facetValues.size()); for (StringValue selectionType : facetSelectionTypes) { if (!selectionType.isEmpty()) { applySelectionTypeFromParameter(selectionType, selection); } } for (StringValue facetValue : facetValues) { if (!facetValue.isEmpty()) { applyFacetValueFromParameter(facetValue, selection); } } return new QueryFacetsSelection(query, selection); } QueryFacetsSelectionParametersConverter(Set<String> facetsAllowed);  QueryFacetsSelectionParametersConverter(FacetParameterMapper facetParamMapper, Collection<String> facetsAllowed);  QueryFacetsSelectionParametersConverter(FacetParameterMapper facetParamMapper, Set<String> facetsAllowed); @Override QueryFacetsSelection fromParameters(PageParameters params); @Override PageParameters toParameters(QueryFacetsSelection selection); final static Logger logger; final static Splitter FILTER_SPLITTER; }
@Test public void testFromParameters() { final PageParameters params = new PageParameters(); params.add("q", "query"); params.add("q", "ignored"); params.add("fq", "facet1:valueA"); params.add("fq", "facet1:valueB"); params.add("fq", "facet2:value:C"); params.add("fq", "illegal-no-colon"); params.add("fq", "facet5:valueD"); params.add("fq", ""); params.add("fq", "invalid"); params.add("fqType", "facet1:and"); params.add("fqType", "facet3:not_empty"); params.add("fqType", "facet4:illegaltype"); params.add("fqType", "illegal-no-colon"); final QueryFacetsSelection result = instance.fromParameters(params); assertEquals("query", result.getQuery()); assertEquals(3, result.getFacets().size()); assertThat(result.getFacets(), hasItem("facet1")); assertThat(result.getFacets(), hasItem("facet2")); assertThat(result.getSelectionValues("facet1").getValues(), hasItem("valueA")); assertThat(result.getSelectionValues("facet1").getValues(), hasItem("valueB")); assertThat(result.getSelectionValues("facet2").getValues(), hasItem("value:C")); assertEquals(FacetSelectionType.AND, result.getSelectionValues("facet1").getSelectionType()); assertEquals(FacetSelectionType.OR, result.getSelectionValues("facet2").getSelectionType()); assertEquals(FacetSelectionType.NOT_EMPTY, result.getSelectionValues("facet3").getSelectionType()); }
@Test public void testFromParametersSerializable() { final PageParameters params = new PageParameters(); params.add("q", "query"); params.add("q", "ignored"); params.add("fq", "facet1:valueA"); params.add("fq", "facet1:valueB"); params.add("fq", "facet2:valueC"); params.add("fq", ""); params.add("fq", "invalid"); SerializationUtils.roundtrip(instance.fromParameters(params)); }