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

truncation of long record descriptions in search result items. plus test and documentation

Location:
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/SolrFieldLabel.java

    r4625 r4871  
    1919import eu.clarin.cmdi.vlo.wicket.model.NullFallbackModel;
    2020import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel;
     21import eu.clarin.cmdi.vlo.wicket.model.TruncatingStringModel;
    2122import org.apache.solr.common.SolrDocument;
    2223import org.apache.wicket.markup.html.basic.Label;
     
    2930public class SolrFieldLabel extends Label {
    3031
     32    /**
     33     *
     34     * @param id id of label
     35     * @param documentModel model that holds document to show field of
     36     * @param fieldName name of field to show value of
     37     */
    3138    public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName) {
    3239        super(id, new SolrFieldStringModel(documentModel, fieldName));
    3340    }
    3441
     42    /**
     43     *
     44     * @param id id of label
     45     * @param documentModel model that holds document to show field of
     46     * @param fieldName name of field to show value of
     47     * @param maxLength maximum length to allow
     48     * @param truncatePoint point to truncate if string is too long
     49     */
     50    public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName, int maxLength, int truncatePoint) {
     51        super(id,
     52                new TruncatingStringModel(
     53                        new SolrFieldStringModel(documentModel, fieldName), maxLength, truncatePoint));
     54    }
     55
     56    /**
     57     *
     58     * @param id id of label
     59     * @param documentModel model that holds document to show field of
     60     * @param fieldName name of field to show value of
     61     * @param nullFallback string to show if actual value is null
     62     */
    3563    public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName, String nullFallback) {
    3664        super(id, new NullFallbackModel(new SolrFieldStringModel(documentModel, fieldName), nullFallback));
    3765    }
    3866
     67    /**
     68     *
     69     * @param id id of label
     70     * @param documentModel model that holds document to show field of
     71     * @param fieldName name of field to show value of
     72     * @param nullFallback string to show if actual value is null
     73     * @param maxLength maximum length to allow
     74     * @param truncatePoint point to truncate if string is too long
     75     */
     76    public SolrFieldLabel(String id, IModel<SolrDocument> documentModel, String fieldName, String nullFallback, int maxLength, int truncatePoint) {
     77        super(id, new NullFallbackModel(
     78                new TruncatingStringModel(
     79                        new SolrFieldStringModel(documentModel, fieldName), maxLength, truncatePoint), nullFallback));
     80    }
     81
    3982}
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/SearchResultItemPanel.java

    r4686 r4871  
    1919import eu.clarin.cmdi.vlo.wicket.provider.ResouceTypeCountDataProvider;
    2020import eu.clarin.cmdi.vlo.FacetConstants;
    21 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2221import eu.clarin.cmdi.vlo.pojo.ResourceTypeCount;
    2322import eu.clarin.cmdi.vlo.pojo.SearchContext;
     
    4645
    4746    private final static ResourceTypeCountConverter resourceTypeCountConverter = new ResourceTypeCountConverter();
     47    private static final int MAX_DESCRIPTION_LENGTH = 350;
     48    private static final int LONG_DESCRIPTION_TRUNCATE_POINT = 320;
    4849
    4950    @SpringBean
     
    6162        add(recordLink);
    6263
    63         add(new SolrFieldLabel("description", documentModel, FacetConstants.FIELD_DESCRIPTION, "<no description>"));
     64        add(new SolrFieldLabel("description", documentModel, FacetConstants.FIELD_DESCRIPTION, "<no description>", MAX_DESCRIPTION_LENGTH, LONG_DESCRIPTION_TRUNCATE_POINT));
    6465
    6566        // get model for resources
Note: See TracChangeset for help on using the changeset viewer.