Changeset 4867


Ignore:
Timestamp:
04/01/14 10:12:59 (10 years ago)
Author:
Twan Goosen
Message:

Facet field retrieval (through the facet field(s) model) has a parameter that determines the facet values limit
Fixes #524

Location:
vlo/branches/vlo-3.0/vlo-web-app/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/FacetFieldsService.java

    r4661 r4867  
    1919import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2020import java.util.List;
     21import org.apache.solr.client.solrj.SolrQuery;
    2122import org.apache.solr.client.solrj.response.FacetField;
    2223
     
    2930
    3031    /**
    31      * 
     32     *
    3233     * @param selection query and selected facet values
     34     * @param valueLimit limits the number of values to retrieve per facet,
     35     * negative for unlimited (see {@link SolrQuery#getFacetLimit() })
    3336     * @return facet field objects representing the state of all present facets
    3437     */
    35     List<FacetField> getFacetFields(QueryFacetsSelection selection);
     38    List<FacetField> getFacetFields(QueryFacetsSelection selection, int valueLimit);
    3639
    3740    /**
    38      * 
     41     *
    3942     * @return the total number of facets
    4043     */
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/SolrFacetQueryFactory.java

    r4661 r4867  
    2828public interface SolrFacetQueryFactory {
    2929
    30     SolrQuery createFacetQuery(QueryFacetsSelection selection);
     30    /**
     31     *
     32     * @param selection selection to get facets and value counts for
     33     * @param valueLimit limits the number of values to retrieve per facet,
     34     * negative for unlimited (see {@link SolrQuery#getFacetLimit() })
     35     * @return query for retrieving the facets
     36     */
     37    SolrQuery createFacetQuery(QueryFacetsSelection selection, int valueLimit);
    3138
    3239    SolrQuery createCountFacetsQuery();
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetFieldsService.java

    r4661 r4867  
    2222import eu.clarin.cmdi.vlo.service.solr.SolrFacetQueryFactory;
    2323import java.util.List;
     24import org.apache.solr.client.solrj.SolrQuery;
    2425import org.apache.solr.client.solrj.response.FacetField;
    2526
     
    3637
    3738    /**
    38      * 
     39     *
    3940     * @param searchResultsDao DAO to use to retrieve facets
    4041     * @param queryFatory factory to use to construct facet queries
     
    4647
    4748    @Override
    48     public List<FacetField> getFacetFields(QueryFacetsSelection selection) {
    49         return searchResultsDao.getFacets(queryFatory.createFacetQuery(selection));
     49    public List<FacetField> getFacetFields(QueryFacetsSelection selection, int valueLimit) {
     50        return searchResultsDao.getFacets(queryFatory.createFacetQuery(selection, valueLimit));
    5051    }
    5152
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImpl.java

    r4816 r4867  
    4646   
    4747    @Override
    48     public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections) {
     48    public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, int facetValueLimit) {
    4949        final SolrQuery query = getDefaultFacetQuery();
    5050        addQueryFacetParameters(query, queryFacetsSelections);
     51        query.setFacetLimit(facetValueLimit);
    5152        return query;
    5253    }
     
    5859        query.setFacetMinCount(1);
    5960        query.addFacetField(facets);
    60         // get *all* facet values
    61         query.setFacetLimit(-1); //TODO: limit this when possible (i.e. in faceted search page can be way limited)
    6261        return query;
    6362    }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldModel.java

    r4866 r4867  
    5050    public FacetFieldModel(FacetField facetField, IModel<QueryFacetsSelection> selectionModel) {
    5151        super(facetField);
    52         fieldsModel = new FacetFieldsModel(Collections.singletonList(facetField.getName()), selectionModel);
     52        fieldsModel = new FacetFieldsModel(Collections.singletonList(facetField.getName()), selectionModel, -1);
    5353    }
    5454
     
    5959     * @param selectionModel model that provides current query/selection
    6060     */
    61     protected FacetFieldModel(FacetFieldsService service, String facet, IModel<QueryFacetsSelection> selectionModel) {
    62         fieldsModel = new FacetFieldsModel(service, Collections.singletonList(facet), selectionModel);
     61    protected FacetFieldModel(FacetFieldsService service, String facet, IModel<QueryFacetsSelection> selectionModel, int valueLimit) {
     62        fieldsModel = new FacetFieldsModel(service, Collections.singletonList(facet), selectionModel, valueLimit);
    6363    }   
    6464   
     
    6868     * @param selectionModel model that provides current query/selection
    6969     */
    70     public FacetFieldModel(String facet, IModel<QueryFacetsSelection> selectionModel) {
    71         fieldsModel = new FacetFieldsModel(Collections.singletonList(facet), selectionModel);
     70    public FacetFieldModel(String facet, IModel<QueryFacetsSelection> selectionModel, int valueLimit) {
     71        fieldsModel = new FacetFieldsModel(Collections.singletonList(facet), selectionModel, valueLimit);
    7272    }
    7373
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldsModel.java

    r4866 r4867  
    4545    private final List<String> facets;
    4646    private final IModel<QueryFacetsSelection> selectionModel;
     47    private final int valueLimit;
    4748
    48     public FacetFieldsModel(List<String> facets, IModel<QueryFacetsSelection> selectionModel) {
    49         this(VloWicketApplication.get().getFacetFieldsService(), facets, selectionModel);
     49    /**
     50     *
     51     * @param facets facets to include
     52     * @param selectionModel model that provides current query/selection
     53     * @param valueLimit maximum number of values to retrieve per facet.
     54     * Negative for unlimited
     55     */
     56    public FacetFieldsModel(List<String> facets, IModel<QueryFacetsSelection> selectionModel, int valueLimit) {
     57        this(VloWicketApplication.get().getFacetFieldsService(), facets, selectionModel, valueLimit);
    5058    }
    5159
     
    5563     * @param facets facets to include
    5664     * @param selectionModel model that provides current query/selection
     65     * @param valueLimit maximum number of values to retrieve per facet.
     66     * Negative for unlimited
    5767     */
    58     protected FacetFieldsModel(FacetFieldsService service, List<String> facets, IModel<QueryFacetsSelection> selectionModel) {
     68    protected FacetFieldsModel(FacetFieldsService service, List<String> facets, IModel<QueryFacetsSelection> selectionModel, int valueLimit) {
    5969        this.service = service;
    6070        this.facets = facets;
    6171        this.selectionModel = selectionModel;
     72        this.valueLimit = valueLimit;
    6273    }
    6374
    6475    @Override
    6576    protected List<FacetField> load() {
    66         final List<FacetField> allFacetFields = service.getFacetFields(selectionModel.getObject());
     77        final List<FacetField> allFacetFields = service.getFacetFields(selectionModel.getObject(), valueLimit);
    6778        final Collection<FacetField> filtered = Collections2.filter(allFacetFields, new Predicate<FacetField>() {
    6879
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/AllFacetValuesPage.java

    r4866 r4867  
    5959        }
    6060
    61         setModel(new FacetFieldModel(facet.toString(), selectionModel));
     61        // create a new model so that all values will be retrieved
     62        setModel(new FacetFieldModel(facet.toString(), selectionModel, -1)); // gets all facet values
    6263        if (getModelObject() == null) {
    6364            Session.get().error(String.format("Facet '%s' could not be found", facet));
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/FacetedSearchPage.java

    r4866 r4867  
    1313import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel;
    1414import eu.clarin.cmdi.vlo.wicket.panels.BreadCrumbPanel;
     15import eu.clarin.cmdi.vlo.wicket.panels.FacetValuesPanel;
    1516import eu.clarin.cmdi.vlo.wicket.panels.PermaLinkPanel;
    1617import java.util.List;
     
    100101    private Panel createCollectionsPanel(final String id) {
    101102        final IModel<QueryFacetsSelection> queryModel = getModel();
    102         final FacetFieldModel collectionFacetFieldModel = new FacetFieldModel(vloConfig.getCollectionFacet(), queryModel);
     103        final FacetFieldModel collectionFacetFieldModel = new FacetFieldModel(vloConfig.getCollectionFacet(), queryModel, FacetValuesPanel.MAX_NUMBER_OF_FACETS_TO_SHOW);
    103104        final FacetSelectionModel collectionSelectionModel = new FacetSelectionModel(collectionFacetFieldModel, queryModel);
    104105        final FacetPanel panel = new FacetPanel(id, collectionSelectionModel, new Model<ExpansionState>(ExpansionState.COLLAPSED)) {
     
    123124    private Panel createFacetsPanel(final String id) {
    124125        final IModel<QueryFacetsSelection> queryModel = getModel();
    125         final IModel<List<FacetField>> facetFieldsModel = new FacetFieldsModel(vloConfig.getFacetFields(), queryModel);
     126        final IModel<List<FacetField>> facetFieldsModel = new FacetFieldsModel(vloConfig.getFacetFields(), queryModel, FacetValuesPanel.MAX_NUMBER_OF_FACETS_TO_SHOW);
    126127        final FacetsPanel panel = new FacetsPanel(id, facetFieldsModel, queryModel) {
    127128
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/FacetValuesPanel.java

    r4798 r4867  
    4444public abstract class FacetValuesPanel extends GenericPanel<FacetField> {
    4545
    46     private final static int maxNumberOfFacetsToShow = 10; //TODO: get from config
     46    public final static int MAX_NUMBER_OF_FACETS_TO_SHOW = 10; //TODO: get from config
    4747
    4848    private final ModalWindow valuesWindow;
     
    5454
    5555        // provider that extracts values and counts from FacetField
    56         final FacetFieldValuesProvider valuesProvider = new FacetFieldValuesProvider(model, maxNumberOfFacetsToShow);
     56        final FacetFieldValuesProvider valuesProvider = new FacetFieldValuesProvider(model, MAX_NUMBER_OF_FACETS_TO_SHOW);
    5757        add(new DataView<Count>("facetValues", valuesProvider) {
    5858
     
    135135                super.onConfigure();
    136136                // only show if there actually are more values!
    137                 setVisible(getModel().getObject().getValueCount() > maxNumberOfFacetsToShow);
     137                setVisible(getModel().getObject().getValueCount() > MAX_NUMBER_OF_FACETS_TO_SHOW);
    138138            }
    139139
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetFieldsServiceTest.java

    r4857 r4867  
    6565        context.checking(new Expectations() {
    6666            {
    67                 oneOf(queryFactory).createFacetQuery(selection);
     67                oneOf(queryFactory).createFacetQuery(selection, 20);
    6868                will(returnValue(query));
    6969                oneOf(dao).getFacets(query);
     
    7272        });
    7373
    74         final List<FacetField> result = instance.getFacetFields(selection);
     74        final List<FacetField> result = instance.getFacetFields(selection, 20);
    7575        assertEquals(fields, result);
    7676    }
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImplTest.java

    r4849 r4867  
    5656        // default constructor -> empty
    5757        QueryFacetsSelection selection = new QueryFacetsSelection();
    58         SolrQuery query = instance.createFacetQuery(selection);
     58        SolrQuery query = instance.createFacetQuery(selection, 20);
    5959
    6060        // default: query selects all values
     
    6363        // no selection -> no filter queries
    6464        assertEquals(0, query.getFilterQueries().length);
     65
     66        assertEquals(20, query.getFacetLimit());
    6567    }
    6668
     
    7880        };
    7981
    80         SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection));
     82        SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection), 20);
    8183
    8284        // default: query selects all values
     
    8587        // Only empty selections -> no filter queries
    8688        assertEquals(0, query.getFilterQueries().length);
     89       
     90        // Facet limit should be adopted
     91        assertEquals(20, query.getFacetLimit());
    8792    }
    8893
     
    100105            }
    101106        };
    102         SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection));
     107        SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection), 20);
    103108
    104109        // default: query selects all values
     
    111116        assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet2:valueC"));
    112117        // facet 3 does not occur as there is not selected value!
     118       
     119        // Facet limit should be adopted
     120        assertEquals(20, query.getFacetLimit());
    113121    }
    114122
     
    123131            }
    124132        };
    125         SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection("query string", selection));
     133        SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection("query string", selection), 20);
    126134
    127135        assertEquals(1, query.getFilterQueries().length);
     
    131139        assertEquals(1, query.getFilterQueries().length);
    132140        assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet1:valueA"));
     141
     142        // Facet limit should be adopted
     143        assertEquals(20, query.getFacetLimit());
    133144    }
    134145
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldModelTest.java

    r4661 r4867  
    2020import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
    2121import java.util.Arrays;
    22 import java.util.List;
    2322import org.apache.solr.client.solrj.response.FacetField;
    2423import org.apache.wicket.model.IModel;
     
    5655    @Test
    5756    public void testGetObject() {
    58         final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel);
     57        final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel, 20);
    5958
    6059        context.checking(new Expectations() {
    6160            {
    62                 oneOf(service).getFacetFields(selection);
     61                oneOf(service).getFacetFields(selection, 20);
    6362                will(returnValue(Arrays.asList(
    6463                        new FacetField("facet1"),
     
    8483    @Test
    8584    public void testGetObjectNotIncluded() {
    86         final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel);
     85        final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel, 20);
    8786
    8887        context.checking(new Expectations() {
    8988            {
    90                 oneOf(service).getFacetFields(selection);
     89                oneOf(service).getFacetFields(selection, 20);
    9190                will(returnValue(Arrays.asList(
    9291                        new FacetField("facet1"),
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldsModelTest.java

    r4661 r4867  
    5050        final IModel<QueryFacetsSelection> selectionModel = new Model(selection);
    5151        final List<String> facets = Arrays.asList("facet1", "facet2", "facetX");
    52         final FacetFieldsModel instance = new FacetFieldsModel(service, facets, selectionModel);
     52        final FacetFieldsModel instance = new FacetFieldsModel(service, facets, selectionModel, 20);
    5353
    5454        context.checking(new Expectations() {
    5555            {
    56                 oneOf(service).getFacetFields(selection);
     56                oneOf(service).getFacetFields(selection, 20);
    5757                will(returnValue(Arrays.asList(
    5858                        new FacetField("facet1"),
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/pages/TestFacetedSearchPage.java

    r4661 r4867  
    8484                atLeast(1).of(facetFieldsService).getFacetFieldCount();
    8585                will(returnValue(2L));
    86                 atLeast(1).of(facetFieldsService).getFacetFields(with(any(QueryFacetsSelection.class)));
     86                atLeast(1).of(facetFieldsService).getFacetFields(with(any(QueryFacetsSelection.class)), with(any(Integer.class)));
    8787                will(returnValue(Arrays.asList(new FacetField("collection"), new FacetField("language"), new FacetField("resource class"))));
    8888
Note: See TracChangeset for help on using the changeset viewer.