Changeset 4867
- Timestamp:
- 04/01/14 10:12:59 (11 years ago)
- 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 19 19 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 20 20 import java.util.List; 21 import org.apache.solr.client.solrj.SolrQuery; 21 22 import org.apache.solr.client.solrj.response.FacetField; 22 23 … … 29 30 30 31 /** 31 * 32 * 32 33 * @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() }) 33 36 * @return facet field objects representing the state of all present facets 34 37 */ 35 List<FacetField> getFacetFields(QueryFacetsSelection selection );38 List<FacetField> getFacetFields(QueryFacetsSelection selection, int valueLimit); 36 39 37 40 /** 38 * 41 * 39 42 * @return the total number of facets 40 43 */ -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/SolrFacetQueryFactory.java
r4661 r4867 28 28 public interface SolrFacetQueryFactory { 29 29 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); 31 38 32 39 SolrQuery createCountFacetsQuery(); -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetFieldsService.java
r4661 r4867 22 22 import eu.clarin.cmdi.vlo.service.solr.SolrFacetQueryFactory; 23 23 import java.util.List; 24 import org.apache.solr.client.solrj.SolrQuery; 24 25 import org.apache.solr.client.solrj.response.FacetField; 25 26 … … 36 37 37 38 /** 38 * 39 * 39 40 * @param searchResultsDao DAO to use to retrieve facets 40 41 * @param queryFatory factory to use to construct facet queries … … 46 47 47 48 @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)); 50 51 } 51 52 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImpl.java
r4816 r4867 46 46 47 47 @Override 48 public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections ) {48 public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, int facetValueLimit) { 49 49 final SolrQuery query = getDefaultFacetQuery(); 50 50 addQueryFacetParameters(query, queryFacetsSelections); 51 query.setFacetLimit(facetValueLimit); 51 52 return query; 52 53 } … … 58 59 query.setFacetMinCount(1); 59 60 query.addFacetField(facets); 60 // get *all* facet values61 query.setFacetLimit(-1); //TODO: limit this when possible (i.e. in faceted search page can be way limited)62 61 return query; 63 62 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldModel.java
r4866 r4867 50 50 public FacetFieldModel(FacetField facetField, IModel<QueryFacetsSelection> selectionModel) { 51 51 super(facetField); 52 fieldsModel = new FacetFieldsModel(Collections.singletonList(facetField.getName()), selectionModel );52 fieldsModel = new FacetFieldsModel(Collections.singletonList(facetField.getName()), selectionModel, -1); 53 53 } 54 54 … … 59 59 * @param selectionModel model that provides current query/selection 60 60 */ 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); 63 63 } 64 64 … … 68 68 * @param selectionModel model that provides current query/selection 69 69 */ 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); 72 72 } 73 73 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldsModel.java
r4866 r4867 45 45 private final List<String> facets; 46 46 private final IModel<QueryFacetsSelection> selectionModel; 47 private final int valueLimit; 47 48 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); 50 58 } 51 59 … … 55 63 * @param facets facets to include 56 64 * @param selectionModel model that provides current query/selection 65 * @param valueLimit maximum number of values to retrieve per facet. 66 * Negative for unlimited 57 67 */ 58 protected FacetFieldsModel(FacetFieldsService service, List<String> facets, IModel<QueryFacetsSelection> selectionModel ) {68 protected FacetFieldsModel(FacetFieldsService service, List<String> facets, IModel<QueryFacetsSelection> selectionModel, int valueLimit) { 59 69 this.service = service; 60 70 this.facets = facets; 61 71 this.selectionModel = selectionModel; 72 this.valueLimit = valueLimit; 62 73 } 63 74 64 75 @Override 65 76 protected List<FacetField> load() { 66 final List<FacetField> allFacetFields = service.getFacetFields(selectionModel.getObject() );77 final List<FacetField> allFacetFields = service.getFacetFields(selectionModel.getObject(), valueLimit); 67 78 final Collection<FacetField> filtered = Collections2.filter(allFacetFields, new Predicate<FacetField>() { 68 79 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/AllFacetValuesPage.java
r4866 r4867 59 59 } 60 60 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 62 63 if (getModelObject() == null) { 63 64 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 13 13 import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel; 14 14 import eu.clarin.cmdi.vlo.wicket.panels.BreadCrumbPanel; 15 import eu.clarin.cmdi.vlo.wicket.panels.FacetValuesPanel; 15 16 import eu.clarin.cmdi.vlo.wicket.panels.PermaLinkPanel; 16 17 import java.util.List; … … 100 101 private Panel createCollectionsPanel(final String id) { 101 102 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); 103 104 final FacetSelectionModel collectionSelectionModel = new FacetSelectionModel(collectionFacetFieldModel, queryModel); 104 105 final FacetPanel panel = new FacetPanel(id, collectionSelectionModel, new Model<ExpansionState>(ExpansionState.COLLAPSED)) { … … 123 124 private Panel createFacetsPanel(final String id) { 124 125 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); 126 127 final FacetsPanel panel = new FacetsPanel(id, facetFieldsModel, queryModel) { 127 128 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/FacetValuesPanel.java
r4798 r4867 44 44 public abstract class FacetValuesPanel extends GenericPanel<FacetField> { 45 45 46 p rivate final static int maxNumberOfFacetsToShow= 10; //TODO: get from config46 public final static int MAX_NUMBER_OF_FACETS_TO_SHOW = 10; //TODO: get from config 47 47 48 48 private final ModalWindow valuesWindow; … … 54 54 55 55 // 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); 57 57 add(new DataView<Count>("facetValues", valuesProvider) { 58 58 … … 135 135 super.onConfigure(); 136 136 // 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); 138 138 } 139 139 -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetFieldsServiceTest.java
r4857 r4867 65 65 context.checking(new Expectations() { 66 66 { 67 oneOf(queryFactory).createFacetQuery(selection );67 oneOf(queryFactory).createFacetQuery(selection, 20); 68 68 will(returnValue(query)); 69 69 oneOf(dao).getFacets(query); … … 72 72 }); 73 73 74 final List<FacetField> result = instance.getFacetFields(selection );74 final List<FacetField> result = instance.getFacetFields(selection, 20); 75 75 assertEquals(fields, result); 76 76 } -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImplTest.java
r4849 r4867 56 56 // default constructor -> empty 57 57 QueryFacetsSelection selection = new QueryFacetsSelection(); 58 SolrQuery query = instance.createFacetQuery(selection );58 SolrQuery query = instance.createFacetQuery(selection, 20); 59 59 60 60 // default: query selects all values … … 63 63 // no selection -> no filter queries 64 64 assertEquals(0, query.getFilterQueries().length); 65 66 assertEquals(20, query.getFacetLimit()); 65 67 } 66 68 … … 78 80 }; 79 81 80 SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection) );82 SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection), 20); 81 83 82 84 // default: query selects all values … … 85 87 // Only empty selections -> no filter queries 86 88 assertEquals(0, query.getFilterQueries().length); 89 90 // Facet limit should be adopted 91 assertEquals(20, query.getFacetLimit()); 87 92 } 88 93 … … 100 105 } 101 106 }; 102 SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection) );107 SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection(selection), 20); 103 108 104 109 // default: query selects all values … … 111 116 assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet2:valueC")); 112 117 // facet 3 does not occur as there is not selected value! 118 119 // Facet limit should be adopted 120 assertEquals(20, query.getFacetLimit()); 113 121 } 114 122 … … 123 131 } 124 132 }; 125 SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection("query string", selection) );133 SolrQuery query = instance.createFacetQuery(new QueryFacetsSelection("query string", selection), 20); 126 134 127 135 assertEquals(1, query.getFilterQueries().length); … … 131 139 assertEquals(1, query.getFilterQueries().length); 132 140 assertThat(Arrays.asList(query.getFilterQueries()), Matchers.<String>hasItem("facet1:valueA")); 141 142 // Facet limit should be adopted 143 assertEquals(20, query.getFacetLimit()); 133 144 } 134 145 -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldModelTest.java
r4661 r4867 20 20 import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService; 21 21 import java.util.Arrays; 22 import java.util.List;23 22 import org.apache.solr.client.solrj.response.FacetField; 24 23 import org.apache.wicket.model.IModel; … … 56 55 @Test 57 56 public void testGetObject() { 58 final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel );57 final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel, 20); 59 58 60 59 context.checking(new Expectations() { 61 60 { 62 oneOf(service).getFacetFields(selection );61 oneOf(service).getFacetFields(selection, 20); 63 62 will(returnValue(Arrays.asList( 64 63 new FacetField("facet1"), … … 84 83 @Test 85 84 public void testGetObjectNotIncluded() { 86 final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel );85 final FacetFieldModel instance = new FacetFieldModel(service, "facet4", selectionModel, 20); 87 86 88 87 context.checking(new Expectations() { 89 88 { 90 oneOf(service).getFacetFields(selection );89 oneOf(service).getFacetFields(selection, 20); 91 90 will(returnValue(Arrays.asList( 92 91 new FacetField("facet1"), -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldsModelTest.java
r4661 r4867 50 50 final IModel<QueryFacetsSelection> selectionModel = new Model(selection); 51 51 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); 53 53 54 54 context.checking(new Expectations() { 55 55 { 56 oneOf(service).getFacetFields(selection );56 oneOf(service).getFacetFields(selection, 20); 57 57 will(returnValue(Arrays.asList( 58 58 new FacetField("facet1"), -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/pages/TestFacetedSearchPage.java
r4661 r4867 84 84 atLeast(1).of(facetFieldsService).getFacetFieldCount(); 85 85 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))); 87 87 will(returnValue(Arrays.asList(new FacetField("collection"), new FacetField("language"), new FacetField("resource class")))); 88 88
Note: See TracChangeset
for help on using the changeset viewer.