Changeset 4968


Ignore:
Timestamp:
04/14/14 12:57:31 (10 years ago)
Author:
Twan Goosen
Message:

implemented encoding of selection type into query parameters
(note: previous commit was actually decoding)

Location:
vlo/branches/vlo-3.0/vlo-web-app/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/QueryFacetsSelectionParametersConverter.java

    r4967 r4968  
    102102
    103103        // put all selections in 'fq' parameters
    104         for (Entry<String, FacetSelection> facetSelection : selection.getSelection().entrySet()) {
    105             //Assuming AND           
    106             //TODO: encode NOT,OR
    107             for (String value : facetSelection.getValue().getValues()) {
    108                 params.add(FILTER_QUERY, String.format("%s:%s", facetSelection.getKey(), value));
     104        for (Entry<String, FacetSelection> facetSelectionEntry : selection.getSelection().entrySet()) {
     105            final String facet = facetSelectionEntry.getKey();
     106            final FacetSelection facetSelection = facetSelectionEntry.getValue();
     107            // put a parameter for the selection type (unless it is AND which is default)
     108            if (facetSelection.getSelectionType() != FacetSelectionType.AND) {
     109                params.add(FILTER_QUERY_TYPE, String.format("%s:%s", facet, facetSelection.getSelectionType().toString().toLowerCase()));
     110            }
     111            for (String value : facetSelection.getValues()) {
     112                //TODO: Encode?
     113                params.add(FILTER_QUERY, String.format("%s:%s", facet, value));
    109114            }
    110115        }
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/QueryFacetsSelectionParametersConverterTest.java

    r4967 r4968  
    110110        final String query = "query";
    111111        final Map<String, FacetSelection> map = Maps.newHashMapWithExpectedSize(3);
    112         map.put("facet1", new FacetSelection(Arrays.asList("valueA", "valueB")));
    113         map.put("facet2", new FacetSelection(Collections.singleton("valueC")));
     112        map.put("facet1", new FacetSelection(FacetSelectionType.OR, Arrays.asList("valueA", "valueB")));
     113        map.put("facet2", new FacetSelection(FacetSelectionType.AND, Collections.singleton("valueC")));
     114        map.put("facet3", new FacetSelection(FacetSelectionType.NOT_EMPTY));
    114115
    115116        QueryFacetsSelection selection = new QueryFacetsSelection(query, map);
     
    123124        assertThat(fq, hasItem(StringValue.valueOf("facet1:valueB")));
    124125        assertThat(fq, hasItem(StringValue.valueOf("facet2:valueC")));
     126
     127        final List<StringValue> fqType = result.getValues("fqType");
     128        assertNotNull(fqType);
     129        assertThat(fqType, hasItem(StringValue.valueOf("facet1:or")));
     130        //facet 2 is AND, which is default and should not be encoded
     131        assertThat(fqType, hasItem(StringValue.valueOf("facet3:not_empty")));
    125132    }
    126133
Note: See TracChangeset for help on using the changeset viewer.