QueryFacetsSelectionParametersConverter implements PageParametersConverter<QueryFacetsSelection> { @Override public PageParameters toParameters(QueryFacetsSelection selection) { final PageParameters params = new PageParameters(); final String query = selection.getQuery(); if (query != null) { params.add(QUERY, query); } for (Entry<String, FacetSelection> facetSelectionEntry : selection.getSelection().entrySet()) { final String facet = facetSelectionEntry.getKey(); final FacetSelection facetSelection = facetSelectionEntry.getValue(); if (facetSelection.getSelectionType() != FacetSelectionType.AND) { params.add(FILTER_QUERY_TYPE, String.format("%s:%s", facet, facetSelection.getSelectionType().toString().toLowerCase())); } for (String value : facetSelection.getValues()) { final boolean negated = facetSelection.getQualifier(value) == FacetSelectionValueQualifier.NOT; params.add(FILTER_QUERY, String.format(negated ? "-%s:%s" : "%s:%s", facet, value)); } } return params; } 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 testToParameters() { final String query = "query"; final Map<String, FacetSelection> map = Maps.newHashMapWithExpectedSize(3); map.put("facet1", new FacetSelection(FacetSelectionType.OR, Arrays.asList("valueA", "valueB"))); map.put("facet2", new FacetSelection(FacetSelectionType.AND, Collections.singleton("value:C"))); map.put("facet3", new FacetSelection(FacetSelectionType.NOT_EMPTY)); QueryFacetsSelection selection = new QueryFacetsSelection(query, map); PageParameters result = instance.toParameters(selection); assertThat(result.get("q"), equalTo(StringValue.valueOf("query"))); final List<StringValue> fq = result.getValues("fq"); assertNotNull(fq); assertThat(fq, hasItem(StringValue.valueOf("facet1:valueA"))); assertThat(fq, hasItem(StringValue.valueOf("facet1:valueB"))); assertThat(fq, hasItem(StringValue.valueOf("facet2:value:C"))); final List<StringValue> fqType = result.getValues("fqType"); assertNotNull(fqType); assertThat(fqType, hasItem(StringValue.valueOf("facet1:or"))); assertThat(fqType, hasItem(StringValue.valueOf("facet3:not_empty"))); }