Changeset 4963


Ignore:
Timestamp:
04/14/14 11:37:03 (10 years ago)
Author:
Twan Goosen
Message:

Refactored QueryFacetSelection?: instead of a collection of strings, it now has a 'FacetSelection?' object for each facet which holds a collection as well as a selection type (which can be AND (default), OR, NOT, or NOT EMPTY).

Location:
vlo/branches/vlo-3.0/vlo-web-app/src
Files:
5 added
17 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/QueryFacetsSelection.java

    r4787 r4963  
    1717package eu.clarin.cmdi.vlo.pojo;
    1818
    19 import com.google.common.collect.Lists;
    2019import com.google.common.collect.Maps;
    2120import java.io.Serializable;
     
    3332
    3433    private String queryString;
    35     private final Map<String, Collection<String>> selection;
     34    private final Map<String, FacetSelection> selection;
    3635
    3736    /**
     
    3938     */
    4039    public QueryFacetsSelection() {
    41         this(null, Maps.<String, Collection<String>>newHashMap());
     40        this(null, Maps.<String, FacetSelection>newHashMap());
    4241    }
    4342
     
    4847     */
    4948    public QueryFacetsSelection(String query) {
    50         this(query, Maps.<String, Collection<String>>newHashMap());
     49        this(query, Maps.<String, FacetSelection>newHashMap());
    5150    }
    5251
     
    5655     * @param selection facet values selection map
    5756     */
    58     public QueryFacetsSelection(Map<String, Collection<String>> selection) {
     57    public QueryFacetsSelection(Map<String, FacetSelection> selection) {
    5958        this(null, selection);
    6059    }
     
    6665     * @param selection facet values selection map (can be null)
    6766     */
    68     public QueryFacetsSelection(String query, Map<String, Collection<String>> selection) {
     67    public QueryFacetsSelection(String query, Map<String, FacetSelection> selection) {
    6968        this.queryString = query;
    7069        if (selection == null) {
    71             this.selection = new HashMap<String, Collection<String>>();
     70            this.selection = new HashMap<String, FacetSelection>();
    7271        } else {
    7372            this.selection = selection;
     
    7978     * @return a facet -> values map representing the current selection
    8079     */
    81     public Map<String, Collection<String>> getSelection() {
     80    public Map<String, FacetSelection> getSelection() {
    8281        return selection;
    8382    }
     
    9695     * @return the selected values for the specified facet. Can be null.
    9796     */
    98     public Collection<String> getSelectionValues(String facet) {
     97    public FacetSelection getSelectionValues(String facet) {
    9998        return selection.get(facet);
    10099    }
     
    112111    }
    113112
    114     public void selectValues(String facet, Collection<String> values) {
    115         if (values == null || values.isEmpty()) {
     113    public void selectValues(String facet, FacetSelection values) {
     114        if (values == null) {
    116115            selection.remove(facet);
    117116        } else {
     
    119118                selection.put(facet, values);
    120119            } else {
    121                 selection.put(facet, Lists.newArrayList(values));
     120                selection.put(facet, values);
    122121            }
    123122        }
     
    130129
    131130    public QueryFacetsSelection getCopy() {
    132         final Map<String, Collection<String>> selectionClone = new HashMap<String, Collection<String>>(selection.size());
    133         for (Entry<String, Collection<String>> entry : selection.entrySet()) {
    134             selectionClone.put(entry.getKey(), Lists.newArrayList(entry.getValue()));
     131        final Map<String, FacetSelection> selectionClone = new HashMap<String, FacetSelection>(selection.size());
     132        for (Entry<String, FacetSelection> entry : selection.entrySet()) {
     133            selectionClone.put(entry.getKey(), entry.getValue().getCopy());
    135134        }
    136135        return new QueryFacetsSelection(queryString, selectionClone);
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/AbstractSolrQueryFactory.java

    r4889 r4963  
    1717package eu.clarin.cmdi.vlo.service.solr.impl;
    1818
    19 import com.google.common.base.Joiner;
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2020import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2121import java.util.ArrayList;
     
    4242            query.setQuery("\"" + ClientUtils.escapeQueryChars(queryString) + "\"");
    4343        }
    44         final Map<String, Collection<String>> selections = queryFacetsSelections.getSelection();
     44        final Map<String, FacetSelection> selections = queryFacetsSelections.getSelection();
    4545        if (selections != null) {
    4646            final List<String> encodedQueries = new ArrayList(selections.size()); // assuming every facet has one selection, most common scenario
    47             for (Map.Entry<String, Collection<String>> selection : selections.entrySet()) {
    48                 final String facetName = selection.getKey();
    49                 final Collection<String> values = selection.getValue();
    50                 if (values != null) {
    51                     for (String value : values) {
    52                         encodedQueries.add(createFilterQuery(facetName, value));
     47            for (Map.Entry<String, FacetSelection> selectionEntry : selections.entrySet()) {
     48                final String facetName = selectionEntry.getKey();
     49                final FacetSelection selection = selectionEntry.getValue();
     50                if (selection != null) {
     51                    switch (selection.getSelectionType()) {
     52                        case NOT_EMPTY:
     53                            //TODO: test
     54                            encodedQueries.add(String.format("%s:['' TO *]", facetName));
     55                            break;
     56                        case AND:
     57                            for (String value : selection.getValues()) {
     58                                encodedQueries.add(createFilterQuery(facetName, value));
     59                            }
     60                            break;
     61                        default:
     62                            //TODO: support OR,NOT
     63                            throw new UnsupportedOperationException("Unsupported selection type: " + selection.getSelectionType());
    5364                    }
    5465                }
     
    6071    protected final String createFilterQuery(String facetName, String value) {
    6172        // escape value and wrap in quotes to make literal query
     73        //TODO: encode value
    6274        return String.format("%s:\"%s\"", facetName, ClientUtils.escapeQueryChars(value));
    6375    }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/QueryFacetsSelectionParametersConverter.java

    r4730 r4963  
    1717package eu.clarin.cmdi.vlo.service.solr.impl;
    1818
    19 import com.google.common.collect.ArrayListMultimap;
    2019import com.google.common.collect.HashMultimap;
    2120import com.google.common.collect.Lists;
    2221import com.google.common.collect.Maps;
    2322import com.google.common.collect.Multimap;
     23import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2424import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2525import eu.clarin.cmdi.vlo.service.PageParametersConverter;
     
    2828import java.util.HashMap;
    2929import java.util.List;
     30import java.util.Map;
    3031import java.util.Map.Entry;
    3132import org.apache.wicket.request.mapper.parameter.PageParameters;
     
    4142    @Override
    4243    public QueryFacetsSelection fromParameters(PageParameters params) {
     44        // Assuming AND. TODO: decode NOT,OR,not empty. Abandon multimap stategy?
    4345        // Get query string from params
    4446        final String query = params.get("q").toOptionalString();
     
    6062        // Facet selection expects a mutable and serializable map, so first convert
    6163        // back to ordinary map, then insert serializable values
    62         final HashMap<String, Collection<String>> selection = multimapToSerializableCollectionMap(selectionMap);
     64        final HashMap<String, FacetSelection> selection = multimapToSerializableCollectionMap(selectionMap);
    6365
    6466        // Facet selection expects a mutable and serializable map, so first convert
     
    7779
    7880        // put all selections in 'fq' parameters
    79         for (Entry<String, Collection<String>> facetSelection : selection.getSelection().entrySet()) {
    80             for (String value : facetSelection.getValue()) {
     81        for (Entry<String, FacetSelection> facetSelection : selection.getSelection().entrySet()) {
     82            //Assuming AND           
     83            //TODO: encode NOT,OR
     84            for (String value : facetSelection.getValue().getValues()) {
    8185                params.add("fq", String.format("%s:%s", facetSelection.getKey(), value));
    8286            }
     
    9195     * @return a fully serializable map with collection values
    9296     */
    93     private HashMap<String, Collection<String>> multimapToSerializableCollectionMap(final Multimap<String, String> selectionMap) {
    94         final HashMap<String, Collection<String>> selection = Maps.newHashMapWithExpectedSize(selectionMap.size());
     97    private HashMap<String, FacetSelection> multimapToSerializableCollectionMap(final Multimap<String, String> selectionMap) {
     98
     99        final HashMap<String, FacetSelection> selection = Maps.newHashMapWithExpectedSize(selectionMap.size());
    95100        for (Entry<String, Collection<String>> entry : selectionMap.asMap().entrySet()) {
    96             final Collection<String> value = entry.getValue();
     101            final FacetSelection value = new FacetSelection(entry.getValue());
    97102            if (value instanceof Serializable) {
    98103                // keep serializable collection value
     
    100105            } else {
    101106                // copy to a serializable collection
    102                 selection.put(entry.getKey(), Lists.newArrayList(value));
     107                selection.put(entry.getKey(), value);
    103108            }
    104109        }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldSelectionModel.java

    r4962 r4963  
    1818
    1919import eu.clarin.cmdi.vlo.pojo.FacetFieldSelection;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2122import java.util.Collection;
     
    2829
    2930/**
    30  * Model for FacetFieldSelection that simply wraps a QueryFacetsSelection model and
    31  * 'filters' for the specified facet
     31 * Model for FacetFieldSelection that simply wraps a QueryFacetsSelection model
     32 * and 'filters' for the specified facet
    3233 *
    3334 * @author twagoo
     
    5657    public List<String> getFacetValues() {
    5758        final String facetName = getFacetField().getName();
    58         final Collection<String> selectionValues = getSelection().getSelectionValues(facetName);
    59         if (selectionValues == null) {
     59        final FacetSelection selection = getSelection().getSelectionValues(facetName);
     60        if (selection == null) {
    6061            return Collections.emptyList();
    6162        } else {
    62             return new CopyOnWriteArrayList<String>(selectionValues);
     63            final Collection<String> selectionValues = selection.getValues();
     64            if (selectionValues == null) {
     65                return Collections.emptyList();
     66            } else {
     67                return new CopyOnWriteArrayList<String>(selectionValues);
     68            }
    6369        }
    6470    }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/AllFacetValuesPage.java

    r4872 r4963  
    1717package eu.clarin.cmdi.vlo.wicket.pages;
    1818
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    1920import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2021import eu.clarin.cmdi.vlo.service.PageParametersConverter;
     
    8687
    8788            @Override
    88             protected void onValuesSelected(String facet, Collection<String> values, AjaxRequestTarget target) {
     89            protected void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target) {
    8990                // Create updated selection state
    9091                final QueryFacetsSelection newSelection;
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/BreadCrumbPanel.java

    r4943 r4963  
    1717package eu.clarin.cmdi.vlo.wicket.panels;
    1818
    19 import eu.clarin.cmdi.vlo.wicket.provider.FacetSelectionProvider;
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2020import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2121import eu.clarin.cmdi.vlo.service.PageParametersConverter;
    2222import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel;
    2323import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage;
     24import eu.clarin.cmdi.vlo.wicket.provider.FacetSelectionProvider;
    2425import java.util.Collection;
    2526import java.util.Iterator;
    2627import java.util.Locale;
    2728import java.util.Map;
    28 import org.apache.wicket.Application;
    2929import org.apache.wicket.AttributeModifier;
    3030import org.apache.wicket.markup.html.WebMarkupContainer;
     
    9191        // create a provider that lists the facet name -> values entries
    9292        final FacetSelectionProvider facetSelectionProvider = new FacetSelectionProvider(model);
    93         facetsContainer.add(new DataView<Map.Entry<String, Collection<String>>>("facet", facetSelectionProvider) {
     93        facetsContainer.add(new DataView<Map.Entry<String, FacetSelection>>("facet", facetSelectionProvider) {
    9494
    9595            @Override
    96             protected void populateItem(Item<Map.Entry<String, Collection<String>>> item) {
    97                 final IModel<Map.Entry<String, Collection<String>>> selectionModel = item.getModel();
     96            protected void populateItem(Item<Map.Entry<String, FacetSelection>> item) {
     97                final IModel<Map.Entry<String, FacetSelection>> selectionModel = item.getModel();
    9898                // add a label for the selected facet value(s)
    9999                final Label valueLabel = new Label("value", new PropertyModel(selectionModel, "value")) {
     
    135135
    136136        final String queryString = getModelObject().getQuery();
    137         final Map<String, Collection<String>> selection = getModelObject().getSelection();
     137        final Map<String, FacetSelection> selection = getModelObject().getSelection();
    138138
    139139        query.setVisible(queryString != null && !queryString.isEmpty());
     
    145145     * collection (if singleton, show its value; if multiple, comma separated)
    146146     */
    147     private final static IConverter<Collection<String>> selectionConverter = new IConverter<Collection<String>>() {
     147    private final static IConverter<FacetSelection> selectionConverter = new IConverter<FacetSelection>() {
    148148
    149149        @Override
    150         public Collection<String> convertToObject(String value, Locale locale) throws ConversionException {
     150        public FacetSelection convertToObject(String value, Locale locale) throws ConversionException {
    151151            throw new UnsupportedOperationException("Not supported yet.");
    152152        }
    153153
    154154        @Override
    155         public String convertToString(Collection<String> value, Locale locale) {
     155        public String convertToString(FacetSelection selection, Locale locale) {
     156            final Collection<String> value = selection.getValues();
     157            //TODO: include selection type
    156158            if (value.isEmpty()) {
    157159                return "";
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/AllFacetValuesPanel.java

    r4961 r4963  
    1818
    1919import com.google.common.collect.ImmutableList;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import eu.clarin.cmdi.vlo.pojo.FieldValuesFilter;
    2122import eu.clarin.cmdi.vlo.pojo.FieldValuesOrder;
     
    2425import eu.clarin.cmdi.vlo.wicket.model.BridgeOuterModel;
    2526import eu.clarin.cmdi.vlo.wicket.provider.FacetFieldValuesProvider;
    26 import java.util.Collection;
    2727import java.util.Collections;
    2828import org.apache.solr.client.solrj.response.FacetField;
     
    5656 */
    5757public abstract class AllFacetValuesPanel extends GenericPanel<FacetField> {
    58    
     58
    5959    private final FacetFieldValuesProvider valuesProvider;
    6060    private final WebMarkupContainer valuesContainer;
     
    7878    public AllFacetValuesPanel(String id, IModel<FacetField> model, IModel<FieldValuesFilter> filterModel) {
    7979        super(id, model);
    80        
     80
    8181        if (filterModel != null) {
    8282            this.filterModel = filterModel;
     
    8787        // create a provider that shows all values and is sorted by name by default
    8888        valuesProvider = new FacetFieldValuesProvider(model, Integer.MAX_VALUE, FieldValueOrderSelector.NAME_SORT) {
    89            
     89
    9090            @Override
    9191            protected IModel<FieldValuesFilter> getFilterModel() {
     
    9393                return AllFacetValuesPanel.this.filterModel;
    9494            }
    95            
     95
    9696        };
    9797
     
    110110        add(optionsForm);
    111111    }
    112    
     112
    113113    private DataView<FacetField.Count> createValuesView(String id) {
    114114        return new DataView<FacetField.Count>(id, valuesProvider) {
    115            
     115
    116116            @Override
    117117            protected void populateItem(final Item<FacetField.Count> item) {
     
    120120                // link to select an individual facet value
    121121                final Link selectLink = new AjaxFallbackLink("facetSelect") {
    122                    
     122
    123123                    @Override
    124124                    public void onClick(AjaxRequestTarget target) {
     
    127127                                item.getModelObject().getFacetField().getName(),
    128128                                // for now only single values can be selected
    129                                 Collections.singleton(item.getModelObject().getName()),
     129                                new FacetSelection(Collections.singleton(item.getModelObject().getName())),
    130130                                target);
    131131                    }
     
    141141        };
    142142    }
    143    
     143
    144144    private Form createOptionsForm(String id) {
    145145        final Form options = new Form(id);
    146        
     146
    147147        final DropDownChoice<SortParam<FieldValuesOrder>> sortSelect
    148148                = new FieldValueOrderSelector("sort", new PropertyModel<SortParam<FieldValuesOrder>>(valuesProvider, "sort"));
    149149        sortSelect.add(new UpdateOptionsFormBehavior(options));
    150150        options.add(sortSelect);
    151        
     151
    152152        final TextField filterField = new TextField<String>("filter", new PropertyModel(filterModel, "name"));
    153153        filterField.add(new AjaxFormComponentUpdatingBehavior("keyup") {
    154            
     154
    155155            @Override
    156156            protected void onUpdate(AjaxRequestTarget target) {
     
    159159        });
    160160        options.add(filterField);
    161        
     161
    162162        addOccurenceOptions(options);
    163        
     163
    164164        return options;
    165165    }
     
    198198        final DropDownChoice<Integer> minOccurence = new DropDownChoice<Integer>("minOccurences", minOccurenceSelectModel, ImmutableList.of(2, 5, 10, 100, 1000));
    199199        minOccurence.add(new UpdateOptionsFormBehavior(options) {
    200            
     200
    201201            @Override
    202202            protected void onUpdate(AjaxRequestTarget target) {
     
    207207                }
    208208            }
    209            
     209
    210210        });
    211211        options.add(minOccurence);
    212212    }
    213    
     213
    214214    private class UpdateOptionsFormBehavior extends OnChangeAjaxBehavior {
    215        
     215
    216216        private final Form options;
    217        
     217
    218218        public UpdateOptionsFormBehavior(Form options) {
    219219            this.options = options;
    220220        }
    221        
     221
    222222        @Override
    223223        protected void onUpdate(AjaxRequestTarget target) {
     
    225225            target.add(valuesContainer);
    226226        }
    227        
    228     }
    229    
     227
     228    }
     229
    230230    @Override
    231231    public void detachModels() {
     
    242242     * (fallback)!
    243243     */
    244     protected abstract void onValuesSelected(String facet, Collection<String> values, AjaxRequestTarget target);
    245    
     244    protected abstract void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target);
     245
    246246}
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetPanel.java

    r4962 r4963  
    1919import eu.clarin.cmdi.vlo.pojo.ExpansionState;
    2020import eu.clarin.cmdi.vlo.pojo.FacetFieldSelection;
     21import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2122import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2223import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel;
     
    117118                new PropertyModel<QueryFacetsSelection>(getModel(), "selection")) {
    118119                    @Override
    119                     public void onValuesSelected(String facet, Collection<String> value, AjaxRequestTarget target) {
     120                    public void onValuesSelected(String facet, FacetSelection value, AjaxRequestTarget target) {
    120121                        // A value has been selected on this facet's panel, update the model!
    121122                        FacetPanel.this.getModelObject().getSelection().selectValues(facet, value);
     
    135136
    136137                // Values have been removed, calculate remainder
    137                 final Collection<String> currentSelection = selection.getSelectionValues(facet);
     138                final FacetSelection facetSelection = selection.getSelectionValues(facet);
     139                final Collection<String> currentSelection = facetSelection.getValues();
    138140                final Collection<String> newSelection = new HashSet<String>(currentSelection);
    139141                newSelection.removeAll(valuesRemoved);
    140142
    141                 // Update model
    142                 selection.selectValues(facet, newSelection);
     143                // Update model (keep selection type)
     144                selection.selectValues(facet, new FacetSelection(facetSelection.getSelectionType(), newSelection));
    143145
    144146                // collapse after removal
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetValuesPanel.java

    r4950 r4963  
    1818
    1919import com.google.common.collect.ImmutableSet;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import eu.clarin.cmdi.vlo.pojo.FieldValuesFilter;
    2122import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
     
    136137                        item.getModelObject().getFacetField().getName(),
    137138                        // for now only single values can be selected
    138                         Collections.singleton(item.getModelObject().getName()),
     139                        new FacetSelection(Collections.singleton(item.getModelObject().getName())),
    139140                        target);
    140141            }
     
    161162
    162163            @Override
    163             protected void onValuesSelected(String facet, Collection<String> values, AjaxRequestTarget target) {
     164            protected void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target) {
    164165                window.close(target);
    165166                FacetValuesPanel.this.onValuesSelected(facet, values, target);
     
    210211     * (fallback)!
    211212     */
    212     protected abstract void onValuesSelected(String facet, Collection<String> values, AjaxRequestTarget target);
     213    protected abstract void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target);
    213214
    214215    @Override
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetsPanel.java

    r4962 r4963  
    1818
    1919import eu.clarin.cmdi.vlo.pojo.ExpansionState;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2122import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
     
    128129            protected void onConfigure() {
    129130                super.onConfigure();
    130                 final Map<String, Collection<String>> selection = selectionModel.getObject().getSelection();
     131                final Map selection = selectionModel.getObject().getSelection();
    131132                setVisible(selection != null && !selection.isEmpty());
    132133            }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/SelectedFacetPanel.java

    r4962 r4963  
    1818
    1919import eu.clarin.cmdi.vlo.pojo.FacetFieldSelection;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import java.util.Collection;
    2122import java.util.Collections;
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/SimpleSearchBrowsePanel.java

    r4943 r4963  
    1818
    1919import eu.clarin.cmdi.vlo.config.VloConfig;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2122import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
     
    2425import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel;
    2526import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage;
    26 import java.util.Collection;
    2727import java.util.List;
    2828import org.apache.solr.client.solrj.response.FacetField;
     
    8989
    9090                    @Override
    91                     protected void onValuesSelected(String facet, Collection<String> values, AjaxRequestTarget target) {
     91                    protected void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target) {
    9292                        // value selected, add to selection model then submit to search page
    9393                        final IModel<QueryFacetsSelection> selectionModel = SimpleSearchBrowsePanel.this.getModel();
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/FacetSelectionProvider.java

    r4727 r4963  
    1515 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    17 
    1817package eu.clarin.cmdi.vlo.wicket.provider;
    1918
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2020import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    21 import eu.clarin.cmdi.vlo.wicket.model.CollectionMapEntryModel;
    22 import java.util.Collection;
     21import eu.clarin.cmdi.vlo.wicket.model.MapEntryModel;
    2322import java.util.Iterator;
    2423import java.util.Map;
     
    3029 * @author twagoo
    3130 */
    32 public class FacetSelectionProvider implements IDataProvider<Map.Entry<String, Collection<String>>> {
     31public class FacetSelectionProvider implements IDataProvider<Map.Entry<String, FacetSelection>> {
     32
    3333    private final IModel<QueryFacetsSelection> selectionModel;
    3434
     
    3838
    3939    @Override
    40     public Iterator<? extends Map.Entry<String, Collection<String>>> iterator(long first, long count) {
     40    public Iterator<? extends Map.Entry<String, FacetSelection>> iterator(long first, long count) {
    4141        return selectionModel.getObject().getSelection().entrySet().iterator();
    4242    }
     
    4848
    4949    @Override
    50     public IModel<Map.Entry<String, Collection<String>>> model(Map.Entry<String, Collection<String>> object) {
    51         return new CollectionMapEntryModel<String, String>(object);
     50    public IModel<Map.Entry<String, FacetSelection>> model(Map.Entry<String, FacetSelection> object) {
     51        return new MapEntryModel<String, FacetSelection>(object);
    5252    }
    5353
     
    5656        selectionModel.detach();
    5757    }
    58    
     58
    5959}
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/QueryFacetsSelectionParametersConverterTest.java

    r4730 r4963  
    1818
    1919import eu.clarin.cmdi.vlo.service.solr.impl.QueryFacetsSelectionParametersConverter;
    20 import com.google.common.collect.HashMultimap;
     20import com.google.common.collect.Maps;
     21import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2122import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
     23import java.util.Arrays;
     24import java.util.Collections;
    2225import java.util.List;
     26import java.util.Map;
    2327import org.apache.commons.lang3.SerializationUtils;
    2428import org.apache.wicket.request.mapper.parameter.PageParameters;
     
    6367        assertThat(result.getFacets(), hasItem("facet1"));
    6468        assertThat(result.getFacets(), hasItem("facet2"));
    65         assertThat(result.getSelectionValues("facet1"), hasItem("valueA"));
    66         assertThat(result.getSelectionValues("facet1"), hasItem("valueB"));
    67         assertThat(result.getSelectionValues("facet2"), hasItem("valueC"));
     69        assertThat(result.getSelectionValues("facet1").getValues(), hasItem("valueA"));
     70        assertThat(result.getSelectionValues("facet1").getValues(), hasItem("valueB"));
     71        assertThat(result.getSelectionValues("facet2").getValues(), hasItem("valueC"));
    6872    }
    6973
     
    9397    public void testToParameters() {
    9498        final String query = "query";
    95         final HashMultimap<String, String> map = HashMultimap.<String, String>create();
    96         map.put("facet1", "valueA");
    97         map.put("facet1", "valueB");
    98         map.put("facet2", "valueC");
     99        final Map<String, FacetSelection> map = Maps.newHashMapWithExpectedSize(3);
     100        map.put("facet1", new FacetSelection(Arrays.asList("valueA", "valueB")));
     101        map.put("facet2", new FacetSelection(Collections.singleton("valueC")));
    99102
    100         QueryFacetsSelection selection = new QueryFacetsSelection(query, map.asMap());
     103        QueryFacetsSelection selection = new QueryFacetsSelection(query, map);
    101104        PageParameters result = instance.toParameters(selection);
    102105
     
    104107
    105108        final List<StringValue> fq = result.getValues("fq");
    106         assertEquals(3, fq.size());
     109        assertNotNull(fq);
    107110        assertThat(fq, hasItem(StringValue.valueOf("facet1:valueA")));
    108111        assertThat(fq, hasItem(StringValue.valueOf("facet1:valueB")));
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrDocumentQueryFactoryImplTest.java

    r4889 r4963  
    1818
    1919import com.google.common.collect.ImmutableList;
     20import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    2021import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2122import java.util.Collection;
     
    4748    @Test
    4849    public void testCreateDocumentQueryForSelection() {
    49         final Map<String, Collection<String>> selectionMap = Collections.<String, Collection<String>>singletonMap("field1", Collections.singleton("value 1"));
     50        final Map<String, FacetSelection> selectionMap = Collections.<String, FacetSelection>singletonMap("field1", new FacetSelection(Collections.singleton("value 1")));
    5051        final QueryFacetsSelection selection = new QueryFacetsSelection("query", selectionMap);
    5152        final int first = 100;
     
    7980        assertEquals(1, filterQueries.length);
    8081        assertEquals("id:\"docId\"", filterQueries[0]);
    81        
     82
    8283        final String fields = query.getFields();
    8384        assertTrue(fields.contains("field1"));
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrDocumentServiceImplTest.java

    r4849 r4963  
    1717package eu.clarin.cmdi.vlo.service.solr.impl;
    1818
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    1920import eu.clarin.cmdi.vlo.service.solr.impl.SolrDocumentServiceImpl;
    2021import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
     
    8283    @Test
    8384    public void testGetDocuments() {
    84         final QueryFacetsSelection selection = new QueryFacetsSelection("query", Collections.<String, Collection<String>>emptyMap());
     85        final QueryFacetsSelection selection = new QueryFacetsSelection("query", Collections.<String, FacetSelection>emptyMap());
    8586        final int first = 100;
    8687        final int count = 15;
     
    109110    @Test
    110111    public void testGetDocumentCount() {
    111         final QueryFacetsSelection selection = new QueryFacetsSelection("query", Collections.<String, Collection<String>>emptyMap());
     112        final QueryFacetsSelection selection = new QueryFacetsSelection("query", Collections.<String, FacetSelection>emptyMap());
    112113
    113114        final SolrQuery solrQuery = new SolrQuery("query");
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImplTest.java

    r4932 r4963  
    1717package eu.clarin.cmdi.vlo.service.solr.impl;
    1818
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
    1920import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2021import java.util.Arrays;
    21 import java.util.Collection;
    2222import java.util.Collections;
    2323import java.util.HashMap;
     
    7272    public void testCreateFacetQueryNoSelection() {
    7373        // Facets are present but no values are selected
    74         Map<String, Collection<String>> selection = new HashMap<String, Collection<String>>() {
     74        Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() {
    7575            {
    76                 put("facet1", Collections.<String>emptySet());
    77                 put("facet2", Collections.<String>emptyList());
     76                put("facet1", new FacetSelection(Collections.<String>emptySet()));
     77                put("facet2", new FacetSelection(Collections.<String>emptyList()));
    7878            }
    7979        };
     
    9797    public void testCreateFacetQuerySelection() {
    9898        // Some facets have one or more values selected
    99         Map<String, Collection<String>> selection = new HashMap<String, Collection<String>>() {
     99        Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() {
    100100            {
    101                 put("facet1", Arrays.asList("valueA"));
    102                 put("facet2", Arrays.asList("valueB", "valueC"));
    103                 put("facet3", Collections.<String>emptyList());
     101                put("facet1", new FacetSelection(Arrays.asList("valueA")));
     102                put("facet2", new FacetSelection(Arrays.asList("valueB", "valueC")));
     103                put("facet3", new FacetSelection(Collections.<String>emptyList()));
    104104            }
    105105        };
     
    125125    @Test
    126126    public void testCreateFacetQuerySelectionAndQuery() {
    127         Map<String, Collection<String>> selection = new HashMap<String, Collection<String>>() {
     127        Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() {
    128128            {
    129                 put("facet1", Arrays.asList("value A"));
     129                put("facet1", new FacetSelection(Arrays.asList("value A")));
    130130            }
    131131        };
Note: See TracChangeset for help on using the changeset viewer.