Changeset 6456


Ignore:
Timestamp:
08/14/15 12:04:16 (9 years ago)
Author:
davor.ostojic@oeaw.ac.at
Message:

multi value search for a single facet

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  
    7777        return values;
    7878    }
     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   
    7996
    8097    public FacetSelection getCopy() {
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/QueryFacetsSelection.java

    r4974 r6456  
    3333    private String queryString;
    3434    private final Map<String, FacetSelection> selection;
     35   
     36   
     37    //multi selection for single facet
     38    private String excludedFacet = null;   
     39   
    3540
    3641    /**
     
    116121        } else {
    117122            if (values instanceof Serializable) {
    118                 selection.put(facet, values);
     123                selection.put (facet, values);
    119124            } else {
    120                 selection.put(facet, values);
     125                selection.put (facet, values);
    121126            }
    122127        }
     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);
    123153    }
    124154
     
    136166    }
    137167
     168        public String getExcludedFacet() {
     169                return excludedFacet;
     170        }
     171
     172        public void setExcludedFacet(String excludedFacet) {
     173                this.excludedFacet = excludedFacet;
     174        }
     175   
     176   
     177
    138178}
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/SearchResultsDao.java

    r4661 r6456  
    3333    List<FacetField> getFacets(SolrQuery query);
    3434   
     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   
    3546}
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/SolrFacetQueryFactory.java

    r4932 r6456  
    4646    SolrQuery createCountFacetsQuery(List<String> facets);
    4747
     48    /* query that returns complete list of values for specified facet */
     49        SolrQuery createExludedFacetQuery(QueryFacetsSelection selection, String facet, int valueLimit);
     50
    4851}
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/AbstractSolrQueryFactory.java

    r6315 r6456  
    3434    protected static final String SOLR_SEARCH_ALL = null;
    3535
    36     protected final void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections) {
     36    protected final void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections, boolean includeFilterQueries) {
    3737        final String queryString = queryFacetsSelections.getQuery();
    3838        if (queryString == null) {
     
    6565                }
    6666            }
    67             query.setFilterQueries(encodedQueries.toArray(new String[encodedQueries.size()]));
     67            if(includeFilterQueries)
     68                query.setFilterQueries(encodedQueries.toArray(new String[encodedQueries.size()]));
    6869        }
    6970    }
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SearchResultsDaoImpl.java

    r4972 r6456  
    77import org.apache.solr.client.solrj.SolrServer;
    88import org.apache.solr.client.solrj.response.FacetField;
     9import org.apache.solr.client.solrj.response.FacetField.Count;
    910import org.apache.solr.client.solrj.response.QueryResponse;
    1011import org.apache.solr.common.SolrDocumentList;
     
    3435        return facetFields;
    3536    }
     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);
     56nextVal:                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   
    3689
    3790    @Override
     
    4295        return documents;
    4396    }
    44 
     97   
    4598}
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrDocumentQueryFactoryImpl.java

    r6284 r6456  
    5151        final SolrQuery query = getDefaultDocumentQuery();
    5252        // apply selection
    53         addQueryFacetParameters(query, selection);
     53        addQueryFacetParameters(query, selection, true);
    5454        // set offset and limit
    5555        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  
    4747    @Override
    4848    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));
    5053    }
    5154
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImpl.java

    r4932 r6456  
    4646    public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, List<String> facets, int facetValueLimit) {
    4747        final SolrQuery query = getBaseQuery(facets);
    48         addQueryFacetParameters(query, queryFacetsSelections);
     48        addQueryFacetParameters(query, queryFacetsSelections, true);
    4949        query.setFacetLimit(facetValueLimit);
    5050        return query;
    5151    }
     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   
    5263
    5364    @Override
  • vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetPanel.java

    r6431 r6456  
    8181
    8282        final boolean valuesSelected = !getModelObject().getFacetValues().isEmpty();
    83         //show both for multi values
    84         facetValuesPanel.setVisible(!valuesSelected);
     83        facetValuesPanel.setVisible(true);
    8584        selectedFacetPanel.setVisible(valuesSelected);
    8685
     
    105104                    public void onValuesSelected(String facet, FacetSelection value, AjaxRequestTarget target) {
    106105                        // 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);
    108108                        if (target != null) {
    109109                            // reload entire page for now
     
    121121
    122122                // Values have been removed, calculate remainder
     123               
    123124                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);
    127128
    128129                // 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);
    130134
    131135                // 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  
    7373    private final int subListSize;
    7474    private final IModel<String> fieldNameModel;
    75 
     75   
    7676    @SpringBean
    7777    private FieldValueConverterProvider fieldValueConverterProvider;
Note: See TracChangeset for help on using the changeset viewer.