Ignore:
Timestamp:
11/17/15 11:55:14 (9 years ago)
Author:
davor.ostojic@oeaw.ac.at
Message:

#795 VLO web-app generates unnecessary requests. The idea behind is to fire SOLR query only when selection is changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldsModel.java

    r4943 r6813  
    1717package eu.clarin.cmdi.vlo.wicket.model;
    1818
    19 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    20 import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
    2119import java.util.List;
     20
    2221import org.apache.solr.client.solrj.response.FacetField;
    2322import org.apache.wicket.model.IModel;
    2423import org.apache.wicket.model.LoadableDetachableModel;
     24
     25import eu.clarin.cmdi.vlo.pojo.FacetSelection;
     26import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
     27import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
    2528
    2629/**
     
    4144    private final IModel<QueryFacetsSelection> selectionModel;
    4245    private final int valueLimit;
     46   
     47   
     48    /**
     49     * now we are returning all facets and model is shared between facetValuesPanel and FacetsPagePanel
     50    *
     51    * @param service service to use for facet field retrieval
     52    * @param facets facets to include
     53    * @param selectionModel model that provides current query/selection
     54    */
     55    public FacetFieldsModel(FacetFieldsService service, List<String> facets, IModel<QueryFacetsSelection> selectionModel) {
     56        this(service, facets, selectionModel, -1);
     57    }
    4358
    4459    /**
     
    5671        this.valueLimit = valueLimit;
    5772    }
     73   
     74   
     75
    5876
    5977    @Override
     
    6785        selectionModel.detach();
    6886    }
     87   
     88    public FacetField getFacetField(String facetName){
     89        List<FacetField> facetList = getObject();
     90        if(facetList != null)
     91                for(FacetField facet: facetList)
     92                        if(facet.getName().equals(facetName))
     93                                return removeSelected(facet, selectionModel.getObject().getSelectionValues(facetName));
     94       
     95        return null;
     96    }
     97   
     98    private FacetField removeSelected(FacetField facetField, FacetSelection selection){
     99        FacetField filtered = new FacetField(facetField.getName());
     100        if(selection != null)
     101                for(FacetField.Count value: facetField.getValues())
     102                        if(selection.getValues().contains(value.getName()))
     103                                continue;
     104                        else
     105                                filtered.add(value.getName(), value.getCount());
     106        else
     107                filtered = facetField;
     108       
     109        return filtered;
     110    }
    69111
    70112}
Note: See TracChangeset for help on using the changeset viewer.