Changeset 4963
- Timestamp:
- 04/14/14 11:37:03 (10 years ago)
- 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 17 17 package eu.clarin.cmdi.vlo.pojo; 18 18 19 import com.google.common.collect.Lists;20 19 import com.google.common.collect.Maps; 21 20 import java.io.Serializable; … … 33 32 34 33 private String queryString; 35 private final Map<String, Collection<String>> selection;34 private final Map<String, FacetSelection> selection; 36 35 37 36 /** … … 39 38 */ 40 39 public QueryFacetsSelection() { 41 this(null, Maps.<String, Collection<String>>newHashMap());40 this(null, Maps.<String, FacetSelection>newHashMap()); 42 41 } 43 42 … … 48 47 */ 49 48 public QueryFacetsSelection(String query) { 50 this(query, Maps.<String, Collection<String>>newHashMap());49 this(query, Maps.<String, FacetSelection>newHashMap()); 51 50 } 52 51 … … 56 55 * @param selection facet values selection map 57 56 */ 58 public QueryFacetsSelection(Map<String, Collection<String>> selection) {57 public QueryFacetsSelection(Map<String, FacetSelection> selection) { 59 58 this(null, selection); 60 59 } … … 66 65 * @param selection facet values selection map (can be null) 67 66 */ 68 public QueryFacetsSelection(String query, Map<String, Collection<String>> selection) {67 public QueryFacetsSelection(String query, Map<String, FacetSelection> selection) { 69 68 this.queryString = query; 70 69 if (selection == null) { 71 this.selection = new HashMap<String, Collection<String>>();70 this.selection = new HashMap<String, FacetSelection>(); 72 71 } else { 73 72 this.selection = selection; … … 79 78 * @return a facet -> values map representing the current selection 80 79 */ 81 public Map<String, Collection<String>> getSelection() {80 public Map<String, FacetSelection> getSelection() { 82 81 return selection; 83 82 } … … 96 95 * @return the selected values for the specified facet. Can be null. 97 96 */ 98 public Collection<String>getSelectionValues(String facet) {97 public FacetSelection getSelectionValues(String facet) { 99 98 return selection.get(facet); 100 99 } … … 112 111 } 113 112 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) { 116 115 selection.remove(facet); 117 116 } else { … … 119 118 selection.put(facet, values); 120 119 } else { 121 selection.put(facet, Lists.newArrayList(values));120 selection.put(facet, values); 122 121 } 123 122 } … … 130 129 131 130 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()); 135 134 } 136 135 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 17 17 package eu.clarin.cmdi.vlo.service.solr.impl; 18 18 19 import com.google.common.base.Joiner;19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 20 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 21 import java.util.ArrayList; … … 42 42 query.setQuery("\"" + ClientUtils.escapeQueryChars(queryString) + "\""); 43 43 } 44 final Map<String, Collection<String>> selections = queryFacetsSelections.getSelection();44 final Map<String, FacetSelection> selections = queryFacetsSelections.getSelection(); 45 45 if (selections != null) { 46 46 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()); 53 64 } 54 65 } … … 60 71 protected final String createFilterQuery(String facetName, String value) { 61 72 // escape value and wrap in quotes to make literal query 73 //TODO: encode value 62 74 return String.format("%s:\"%s\"", facetName, ClientUtils.escapeQueryChars(value)); 63 75 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/QueryFacetsSelectionParametersConverter.java
r4730 r4963 17 17 package eu.clarin.cmdi.vlo.service.solr.impl; 18 18 19 import com.google.common.collect.ArrayListMultimap;20 19 import com.google.common.collect.HashMultimap; 21 20 import com.google.common.collect.Lists; 22 21 import com.google.common.collect.Maps; 23 22 import com.google.common.collect.Multimap; 23 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 24 24 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 25 25 import eu.clarin.cmdi.vlo.service.PageParametersConverter; … … 28 28 import java.util.HashMap; 29 29 import java.util.List; 30 import java.util.Map; 30 31 import java.util.Map.Entry; 31 32 import org.apache.wicket.request.mapper.parameter.PageParameters; … … 41 42 @Override 42 43 public QueryFacetsSelection fromParameters(PageParameters params) { 44 // Assuming AND. TODO: decode NOT,OR,not empty. Abandon multimap stategy? 43 45 // Get query string from params 44 46 final String query = params.get("q").toOptionalString(); … … 60 62 // Facet selection expects a mutable and serializable map, so first convert 61 63 // 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); 63 65 64 66 // Facet selection expects a mutable and serializable map, so first convert … … 77 79 78 80 // 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()) { 81 85 params.add("fq", String.format("%s:%s", facetSelection.getKey(), value)); 82 86 } … … 91 95 * @return a fully serializable map with collection values 92 96 */ 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()); 95 100 for (Entry<String, Collection<String>> entry : selectionMap.asMap().entrySet()) { 96 final Collection<String> value = entry.getValue();101 final FacetSelection value = new FacetSelection(entry.getValue()); 97 102 if (value instanceof Serializable) { 98 103 // keep serializable collection value … … 100 105 } else { 101 106 // copy to a serializable collection 102 selection.put(entry.getKey(), Lists.newArrayList(value));107 selection.put(entry.getKey(), value); 103 108 } 104 109 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldSelectionModel.java
r4962 r4963 18 18 19 19 import eu.clarin.cmdi.vlo.pojo.FacetFieldSelection; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 22 import java.util.Collection; … … 28 29 29 30 /** 30 * Model for FacetFieldSelection that simply wraps a QueryFacetsSelection model and31 * 'filters' for the specified facet31 * Model for FacetFieldSelection that simply wraps a QueryFacetsSelection model 32 * and 'filters' for the specified facet 32 33 * 33 34 * @author twagoo … … 56 57 public List<String> getFacetValues() { 57 58 final String facetName = getFacetField().getName(); 58 final Collection<String> selectionValues= getSelection().getSelectionValues(facetName);59 if (selection Values== null) {59 final FacetSelection selection = getSelection().getSelectionValues(facetName); 60 if (selection == null) { 60 61 return Collections.emptyList(); 61 62 } 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 } 63 69 } 64 70 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/AllFacetValuesPage.java
r4872 r4963 17 17 package eu.clarin.cmdi.vlo.wicket.pages; 18 18 19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 19 20 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 20 21 import eu.clarin.cmdi.vlo.service.PageParametersConverter; … … 86 87 87 88 @Override 88 protected void onValuesSelected(String facet, Collection<String>values, AjaxRequestTarget target) {89 protected void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target) { 89 90 // Create updated selection state 90 91 final QueryFacetsSelection newSelection; -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/BreadCrumbPanel.java
r4943 r4963 17 17 package eu.clarin.cmdi.vlo.wicket.panels; 18 18 19 import eu.clarin.cmdi.vlo. wicket.provider.FacetSelectionProvider;19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 20 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 21 import eu.clarin.cmdi.vlo.service.PageParametersConverter; 22 22 import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel; 23 23 import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage; 24 import eu.clarin.cmdi.vlo.wicket.provider.FacetSelectionProvider; 24 25 import java.util.Collection; 25 26 import java.util.Iterator; 26 27 import java.util.Locale; 27 28 import java.util.Map; 28 import org.apache.wicket.Application;29 29 import org.apache.wicket.AttributeModifier; 30 30 import org.apache.wicket.markup.html.WebMarkupContainer; … … 91 91 // create a provider that lists the facet name -> values entries 92 92 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) { 94 94 95 95 @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(); 98 98 // add a label for the selected facet value(s) 99 99 final Label valueLabel = new Label("value", new PropertyModel(selectionModel, "value")) { … … 135 135 136 136 final String queryString = getModelObject().getQuery(); 137 final Map<String, Collection<String>> selection = getModelObject().getSelection();137 final Map<String, FacetSelection> selection = getModelObject().getSelection(); 138 138 139 139 query.setVisible(queryString != null && !queryString.isEmpty()); … … 145 145 * collection (if singleton, show its value; if multiple, comma separated) 146 146 */ 147 private final static IConverter< Collection<String>> selectionConverter = new IConverter<Collection<String>>() {147 private final static IConverter<FacetSelection> selectionConverter = new IConverter<FacetSelection>() { 148 148 149 149 @Override 150 public Collection<String>convertToObject(String value, Locale locale) throws ConversionException {150 public FacetSelection convertToObject(String value, Locale locale) throws ConversionException { 151 151 throw new UnsupportedOperationException("Not supported yet."); 152 152 } 153 153 154 154 @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 156 158 if (value.isEmpty()) { 157 159 return ""; -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/AllFacetValuesPanel.java
r4961 r4963 18 18 19 19 import com.google.common.collect.ImmutableList; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import eu.clarin.cmdi.vlo.pojo.FieldValuesFilter; 21 22 import eu.clarin.cmdi.vlo.pojo.FieldValuesOrder; … … 24 25 import eu.clarin.cmdi.vlo.wicket.model.BridgeOuterModel; 25 26 import eu.clarin.cmdi.vlo.wicket.provider.FacetFieldValuesProvider; 26 import java.util.Collection;27 27 import java.util.Collections; 28 28 import org.apache.solr.client.solrj.response.FacetField; … … 56 56 */ 57 57 public abstract class AllFacetValuesPanel extends GenericPanel<FacetField> { 58 58 59 59 private final FacetFieldValuesProvider valuesProvider; 60 60 private final WebMarkupContainer valuesContainer; … … 78 78 public AllFacetValuesPanel(String id, IModel<FacetField> model, IModel<FieldValuesFilter> filterModel) { 79 79 super(id, model); 80 80 81 81 if (filterModel != null) { 82 82 this.filterModel = filterModel; … … 87 87 // create a provider that shows all values and is sorted by name by default 88 88 valuesProvider = new FacetFieldValuesProvider(model, Integer.MAX_VALUE, FieldValueOrderSelector.NAME_SORT) { 89 89 90 90 @Override 91 91 protected IModel<FieldValuesFilter> getFilterModel() { … … 93 93 return AllFacetValuesPanel.this.filterModel; 94 94 } 95 95 96 96 }; 97 97 … … 110 110 add(optionsForm); 111 111 } 112 112 113 113 private DataView<FacetField.Count> createValuesView(String id) { 114 114 return new DataView<FacetField.Count>(id, valuesProvider) { 115 115 116 116 @Override 117 117 protected void populateItem(final Item<FacetField.Count> item) { … … 120 120 // link to select an individual facet value 121 121 final Link selectLink = new AjaxFallbackLink("facetSelect") { 122 122 123 123 @Override 124 124 public void onClick(AjaxRequestTarget target) { … … 127 127 item.getModelObject().getFacetField().getName(), 128 128 // for now only single values can be selected 129 Collections.singleton(item.getModelObject().getName()),129 new FacetSelection(Collections.singleton(item.getModelObject().getName())), 130 130 target); 131 131 } … … 141 141 }; 142 142 } 143 143 144 144 private Form createOptionsForm(String id) { 145 145 final Form options = new Form(id); 146 146 147 147 final DropDownChoice<SortParam<FieldValuesOrder>> sortSelect 148 148 = new FieldValueOrderSelector("sort", new PropertyModel<SortParam<FieldValuesOrder>>(valuesProvider, "sort")); 149 149 sortSelect.add(new UpdateOptionsFormBehavior(options)); 150 150 options.add(sortSelect); 151 151 152 152 final TextField filterField = new TextField<String>("filter", new PropertyModel(filterModel, "name")); 153 153 filterField.add(new AjaxFormComponentUpdatingBehavior("keyup") { 154 154 155 155 @Override 156 156 protected void onUpdate(AjaxRequestTarget target) { … … 159 159 }); 160 160 options.add(filterField); 161 161 162 162 addOccurenceOptions(options); 163 163 164 164 return options; 165 165 } … … 198 198 final DropDownChoice<Integer> minOccurence = new DropDownChoice<Integer>("minOccurences", minOccurenceSelectModel, ImmutableList.of(2, 5, 10, 100, 1000)); 199 199 minOccurence.add(new UpdateOptionsFormBehavior(options) { 200 200 201 201 @Override 202 202 protected void onUpdate(AjaxRequestTarget target) { … … 207 207 } 208 208 } 209 209 210 210 }); 211 211 options.add(minOccurence); 212 212 } 213 213 214 214 private class UpdateOptionsFormBehavior extends OnChangeAjaxBehavior { 215 215 216 216 private final Form options; 217 217 218 218 public UpdateOptionsFormBehavior(Form options) { 219 219 this.options = options; 220 220 } 221 221 222 222 @Override 223 223 protected void onUpdate(AjaxRequestTarget target) { … … 225 225 target.add(valuesContainer); 226 226 } 227 228 } 229 227 228 } 229 230 230 @Override 231 231 public void detachModels() { … … 242 242 * (fallback)! 243 243 */ 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 246 246 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetPanel.java
r4962 r4963 19 19 import eu.clarin.cmdi.vlo.pojo.ExpansionState; 20 20 import eu.clarin.cmdi.vlo.pojo.FacetFieldSelection; 21 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 21 22 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 22 23 import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel; … … 117 118 new PropertyModel<QueryFacetsSelection>(getModel(), "selection")) { 118 119 @Override 119 public void onValuesSelected(String facet, Collection<String>value, AjaxRequestTarget target) {120 public void onValuesSelected(String facet, FacetSelection value, AjaxRequestTarget target) { 120 121 // A value has been selected on this facet's panel, update the model! 121 122 FacetPanel.this.getModelObject().getSelection().selectValues(facet, value); … … 135 136 136 137 // 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(); 138 140 final Collection<String> newSelection = new HashSet<String>(currentSelection); 139 141 newSelection.removeAll(valuesRemoved); 140 142 141 // Update model 142 selection.selectValues(facet, new Selection);143 // Update model (keep selection type) 144 selection.selectValues(facet, new FacetSelection(facetSelection.getSelectionType(), newSelection)); 143 145 144 146 // 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 18 18 19 19 import com.google.common.collect.ImmutableSet; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import eu.clarin.cmdi.vlo.pojo.FieldValuesFilter; 21 22 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; … … 136 137 item.getModelObject().getFacetField().getName(), 137 138 // for now only single values can be selected 138 Collections.singleton(item.getModelObject().getName()),139 new FacetSelection(Collections.singleton(item.getModelObject().getName())), 139 140 target); 140 141 } … … 161 162 162 163 @Override 163 protected void onValuesSelected(String facet, Collection<String>values, AjaxRequestTarget target) {164 protected void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target) { 164 165 window.close(target); 165 166 FacetValuesPanel.this.onValuesSelected(facet, values, target); … … 210 211 * (fallback)! 211 212 */ 212 protected abstract void onValuesSelected(String facet, Collection<String>values, AjaxRequestTarget target);213 protected abstract void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target); 213 214 214 215 @Override -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetsPanel.java
r4962 r4963 18 18 19 19 import eu.clarin.cmdi.vlo.pojo.ExpansionState; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 22 import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService; … … 128 129 protected void onConfigure() { 129 130 super.onConfigure(); 130 final Map <String, Collection<String>>selection = selectionModel.getObject().getSelection();131 final Map selection = selectionModel.getObject().getSelection(); 131 132 setVisible(selection != null && !selection.isEmpty()); 132 133 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/SelectedFacetPanel.java
r4962 r4963 18 18 19 19 import eu.clarin.cmdi.vlo.pojo.FacetFieldSelection; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import java.util.Collection; 21 22 import 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 18 18 19 19 import eu.clarin.cmdi.vlo.config.VloConfig; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 22 import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService; … … 24 25 import eu.clarin.cmdi.vlo.wicket.model.SolrFieldNameModel; 25 26 import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage; 26 import java.util.Collection;27 27 import java.util.List; 28 28 import org.apache.solr.client.solrj.response.FacetField; … … 89 89 90 90 @Override 91 protected void onValuesSelected(String facet, Collection<String>values, AjaxRequestTarget target) {91 protected void onValuesSelected(String facet, FacetSelection values, AjaxRequestTarget target) { 92 92 // value selected, add to selection model then submit to search page 93 93 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 15 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 18 17 package eu.clarin.cmdi.vlo.wicket.provider; 19 18 19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 20 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 import eu.clarin.cmdi.vlo.wicket.model.CollectionMapEntryModel; 22 import java.util.Collection; 21 import eu.clarin.cmdi.vlo.wicket.model.MapEntryModel; 23 22 import java.util.Iterator; 24 23 import java.util.Map; … … 30 29 * @author twagoo 31 30 */ 32 public class FacetSelectionProvider implements IDataProvider<Map.Entry<String, Collection<String>>> { 31 public class FacetSelectionProvider implements IDataProvider<Map.Entry<String, FacetSelection>> { 32 33 33 private final IModel<QueryFacetsSelection> selectionModel; 34 34 … … 38 38 39 39 @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) { 41 41 return selectionModel.getObject().getSelection().entrySet().iterator(); 42 42 } … … 48 48 49 49 @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); 52 52 } 53 53 … … 56 56 selectionModel.detach(); 57 57 } 58 58 59 59 } -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/QueryFacetsSelectionParametersConverterTest.java
r4730 r4963 18 18 19 19 import eu.clarin.cmdi.vlo.service.solr.impl.QueryFacetsSelectionParametersConverter; 20 import com.google.common.collect.HashMultimap; 20 import com.google.common.collect.Maps; 21 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 21 22 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 23 import java.util.Arrays; 24 import java.util.Collections; 22 25 import java.util.List; 26 import java.util.Map; 23 27 import org.apache.commons.lang3.SerializationUtils; 24 28 import org.apache.wicket.request.mapper.parameter.PageParameters; … … 63 67 assertThat(result.getFacets(), hasItem("facet1")); 64 68 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")); 68 72 } 69 73 … … 93 97 public void testToParameters() { 94 98 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"))); 99 102 100 QueryFacetsSelection selection = new QueryFacetsSelection(query, map .asMap());103 QueryFacetsSelection selection = new QueryFacetsSelection(query, map); 101 104 PageParameters result = instance.toParameters(selection); 102 105 … … 104 107 105 108 final List<StringValue> fq = result.getValues("fq"); 106 assert Equals(3, fq.size());109 assertNotNull(fq); 107 110 assertThat(fq, hasItem(StringValue.valueOf("facet1:valueA"))); 108 111 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 18 18 19 19 import com.google.common.collect.ImmutableList; 20 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 21 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 22 import java.util.Collection; … … 47 48 @Test 48 49 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"))); 50 51 final QueryFacetsSelection selection = new QueryFacetsSelection("query", selectionMap); 51 52 final int first = 100; … … 79 80 assertEquals(1, filterQueries.length); 80 81 assertEquals("id:\"docId\"", filterQueries[0]); 81 82 82 83 final String fields = query.getFields(); 83 84 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 17 17 package eu.clarin.cmdi.vlo.service.solr.impl; 18 18 19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 19 20 import eu.clarin.cmdi.vlo.service.solr.impl.SolrDocumentServiceImpl; 20 21 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; … … 82 83 @Test 83 84 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()); 85 86 final int first = 100; 86 87 final int count = 15; … … 109 110 @Test 110 111 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()); 112 113 113 114 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 17 17 package eu.clarin.cmdi.vlo.service.solr.impl; 18 18 19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 19 20 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 20 21 import java.util.Arrays; 21 import java.util.Collection;22 22 import java.util.Collections; 23 23 import java.util.HashMap; … … 72 72 public void testCreateFacetQueryNoSelection() { 73 73 // 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>() { 75 75 { 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())); 78 78 } 79 79 }; … … 97 97 public void testCreateFacetQuerySelection() { 98 98 // 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>() { 100 100 { 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())); 104 104 } 105 105 }; … … 125 125 @Test 126 126 public void testCreateFacetQuerySelectionAndQuery() { 127 Map<String, Collection<String>> selection = new HashMap<String, Collection<String>>() {127 Map<String, FacetSelection> selection = new HashMap<String, FacetSelection>() { 128 128 { 129 put("facet1", Arrays.asList("value A"));129 put("facet1", new FacetSelection(Arrays.asList("value A"))); 130 130 } 131 131 };
Note: See TracChangeset
for help on using the changeset viewer.