Changeset 6456
- Timestamp:
- 08/14/15 12:04:16 (9 years ago)
- Location:
- vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/FacetSelection.java
r6314 r6456 77 77 return values; 78 78 } 79 80 public void mergeValues(FacetSelection facetSel){ 81 if(facetSel == null || this.equals(facetSel)) 82 return; 83 for(String val: facetSel.values){ 84 this.values.add(val); 85 } 86 } 87 88 public void removeValues(FacetSelection facetSel){ 89 if(facetSel != null && facetSel.values != null){ 90 for(String val: facetSel.values){ 91 this.values.remove(val); 92 } 93 } 94 } 95 79 96 80 97 public FacetSelection getCopy() { -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/QueryFacetsSelection.java
r4974 r6456 33 33 private String queryString; 34 34 private final Map<String, FacetSelection> selection; 35 36 37 //multi selection for single facet 38 private String excludedFacet = null; 39 35 40 36 41 /** … … 116 121 } else { 117 122 if (values instanceof Serializable) { 118 selection.put(facet, values);123 selection.put (facet, values); 119 124 } else { 120 selection.put(facet, values);125 selection.put (facet, values); 121 126 } 122 127 } 128 } 129 130 public void addNewFacetValue(String facet, FacetSelection values){ 131 FacetSelection curSel = selection.get(facet); 132 if(curSel != null){ 133 curSel.mergeValues(values); 134 }else{ 135 curSel = values; 136 excludedFacet = facet; 137 } 138 selectValues(facet, curSel); 139 } 140 141 public void removeFacetValue(String facet, FacetSelection values){ 142 FacetSelection curSel = selection.get(facet); 143 if (curSel != null){ 144 curSel.removeValues(values); 145 146 //if it was the last one, reset the value 147 if(curSel.getValues().isEmpty()){ 148 excludedFacet = null; 149 } 150 } 151 //to remove facet from map if does not have any value 152 selectValues(facet, curSel); 123 153 } 124 154 … … 136 166 } 137 167 168 public String getExcludedFacet() { 169 return excludedFacet; 170 } 171 172 public void setExcludedFacet(String excludedFacet) { 173 this.excludedFacet = excludedFacet; 174 } 175 176 177 138 178 } -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/SearchResultsDao.java
r4661 r6456 33 33 List<FacetField> getFacets(SolrQuery query); 34 34 35 36 /* 37 * To support multi selection for single facet the idea is to fire another query 38 * to fetch all values for facet which is the first in the fq parameter 39 * and to merge (replace the list) with filtered 40 * 41 * another would be to replace the model itself, but where to keep it??? 42 */ 43 44 List<FacetField> getFacets(SolrQuery query, SolrQuery completeFacetValList); 45 35 46 } -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/SolrFacetQueryFactory.java
r4932 r6456 46 46 SolrQuery createCountFacetsQuery(List<String> facets); 47 47 48 /* query that returns complete list of values for specified facet */ 49 SolrQuery createExludedFacetQuery(QueryFacetsSelection selection, String facet, int valueLimit); 50 48 51 } -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/AbstractSolrQueryFactory.java
r6315 r6456 34 34 protected static final String SOLR_SEARCH_ALL = null; 35 35 36 protected final void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections ) {36 protected final void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections, boolean includeFilterQueries) { 37 37 final String queryString = queryFacetsSelections.getQuery(); 38 38 if (queryString == null) { … … 65 65 } 66 66 } 67 query.setFilterQueries(encodedQueries.toArray(new String[encodedQueries.size()])); 67 if(includeFilterQueries) 68 query.setFilterQueries(encodedQueries.toArray(new String[encodedQueries.size()])); 68 69 } 69 70 } -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SearchResultsDaoImpl.java
r4972 r6456 7 7 import org.apache.solr.client.solrj.SolrServer; 8 8 import org.apache.solr.client.solrj.response.FacetField; 9 import org.apache.solr.client.solrj.response.FacetField.Count; 9 10 import org.apache.solr.client.solrj.response.QueryResponse; 10 11 import org.apache.solr.common.SolrDocumentList; … … 34 35 return facetFields; 35 36 } 37 38 39 @Override 40 public java.util.List<FacetField> getFacets(SolrQuery query, SolrQuery completeFacetValList) { 41 final QueryResponse response = fireQuery(sanitise(query)); 42 43 final List<FacetField> facetFields = getFacets(query); 44 45 46 final QueryResponse completeList = fireQuery(sanitise(completeFacetValList)); 47 final FacetField excludedFacet = completeList.getFacetFields().get(0); 48 FacetField newFacet = null; 49 Integer ind = null; 50 51 for(FacetField facet: facetFields){ 52 if(facet.getName().equals(excludedFacet.getName())){ 53 logger.debug("Missing values for excluded Facet {} will be added", facet.getName()); 54 newFacet = copyFacetField(facet); 55 ind = facetFields.indexOf(facet); 56 nextVal: for(FacetField.Count exVal: excludedFacet.getValues()){ 57 boolean exists = false; 58 for(FacetField.Count val: facet.getValues()){ 59 if(exVal.getName().equals(val.getName())){ 60 exists = true; 61 break; 62 } 63 } 64 //import missing values into the facet from the list and set count to zero 65 if(!exists){ 66 logger.debug("Missing value {} is added with count 0", exVal.getName()); 67 newFacet.add(exVal.getName(), 0); 68 } 69 } 70 } 71 } 72 73 if(ind != null){ 74 facetFields.remove(ind); 75 facetFields.add(ind, newFacet); 76 } 77 78 return facetFields; 79 } 80 81 private FacetField copyFacetField(FacetField from){ 82 FacetField newFacet = new FacetField(from.getName(), from.getGap(), from.getEnd()); 83 for(FacetField.Count val: from.getValues()) 84 newFacet.add(val.getName(), val.getCount()); 85 86 return newFacet; 87 } 88 36 89 37 90 @Override … … 42 95 return documents; 43 96 } 44 97 45 98 } -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrDocumentQueryFactoryImpl.java
r6284 r6456 51 51 final SolrQuery query = getDefaultDocumentQuery(); 52 52 // apply selection 53 addQueryFacetParameters(query, selection );53 addQueryFacetParameters(query, selection, true); 54 54 // set offset and limit 55 55 query.setStart(first); -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetFieldsService.java
r4932 r6456 47 47 @Override 48 48 public List<FacetField> getFacetFields(QueryFacetsSelection selection, List<String> facets, int valueLimit) { 49 return searchResultsDao.getFacets(queryFatory.createFacetQuery(selection, facets, valueLimit)); 49 return (selection.getExcludedFacet() == null)? 50 searchResultsDao.getFacets(queryFatory.createFacetQuery(selection, facets, valueLimit)) : 51 searchResultsDao.getFacets(queryFatory.createFacetQuery(selection, facets, valueLimit), 52 queryFatory.createExludedFacetQuery(selection, selection.getExcludedFacet(), valueLimit)); 50 53 } 51 54 -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImpl.java
r4932 r6456 46 46 public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, List<String> facets, int facetValueLimit) { 47 47 final SolrQuery query = getBaseQuery(facets); 48 addQueryFacetParameters(query, queryFacetsSelections );48 addQueryFacetParameters(query, queryFacetsSelections, true); 49 49 query.setFacetLimit(facetValueLimit); 50 50 return query; 51 51 } 52 53 @Override 54 public SolrQuery createExludedFacetQuery(QueryFacetsSelection queryFacetsSelections, String facet, int facetValueLimit) { 55 SolrQuery query = baseQuery.getCopy(); 56 query.addFacetField(facet); 57 addQueryFacetParameters(query, queryFacetsSelections, false); 58 query.setFacetLimit(facetValueLimit); 59 return query; 60 } 61 62 52 63 53 64 @Override -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetPanel.java
r6431 r6456 81 81 82 82 final boolean valuesSelected = !getModelObject().getFacetValues().isEmpty(); 83 //show both for multi values 84 facetValuesPanel.setVisible(!valuesSelected); 83 facetValuesPanel.setVisible(true); 85 84 selectedFacetPanel.setVisible(valuesSelected); 86 85 … … 105 104 public void onValuesSelected(String facet, FacetSelection value, AjaxRequestTarget target) { 106 105 // A value has been selected on this facet's panel, update the model! 107 FacetPanel.this.getModelObject().getSelection().selectValues(facet, value); 106 FacetPanel.this.getModelObject().getSelection().addNewFacetValue(facet, value); 107 //FacetPanel.this.getModelObject().getSelection().selectValues(facet, value); 108 108 if (target != null) { 109 109 // reload entire page for now … … 121 121 122 122 // Values have been removed, calculate remainder 123 123 124 final FacetSelection facetSelection = selection.getSelectionValues(facet); 124 final Collection<String> currentSelection = facetSelection.getValues();125 final Collection<String> newSelection = new HashSet<String>(currentSelection);126 newSelection.removeAll(valuesRemoved);125 // final Collection<String> currentSelection = facetSelection.getValues(); 126 // final Collection<String> newSelection = new HashSet<String>(currentSelection); 127 // newSelection.removeAll(valuesRemoved); 127 128 128 129 // Update model (keep selection type) 129 selection.selectValues(facet, new FacetSelection(facetSelection.getSelectionType(), newSelection)); 130 // selection.selectValues(facet, new FacetSelection(facetSelection.getSelectionType(), newSelection)); 131 132 FacetSelection fSelToRemove = new FacetSelection(facetSelection.getSelectionType(), valuesRemoved); 133 selection.removeFacetValue(facet, fSelToRemove); 130 134 131 135 // collapse after removal -
vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetValuesPanel.java
r6005 r6456 73 73 private final int subListSize; 74 74 private final IModel<String> fieldNameModel; 75 75 76 76 @SpringBean 77 77 private FieldValueConverterProvider fieldValueConverterProvider;
Note: See TracChangeset
for help on using the changeset viewer.