source: vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetFieldsService.java @ 6461

Last change on this file since 6461 was 6461, checked in by davor.ostojic@oeaw.ac.at, 9 years ago

to prevent sending additional solr req for rest of the facets

File size: 2.5 KB
Line 
1/*
2 * Copyright (C) 2014 CLARIN
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package eu.clarin.cmdi.vlo.service.solr.impl;
18
19import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
20import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
21import eu.clarin.cmdi.vlo.service.solr.SearchResultsDao;
22import eu.clarin.cmdi.vlo.service.solr.SolrFacetQueryFactory;
23import java.util.List;
24import org.apache.solr.client.solrj.response.FacetField;
25
26/**
27 * Gets FacetFields from SOLR based on a selection and the queries constructed
28 * by the provided query factory
29 *
30 * @author twagoo
31 */
32public class SolrFacetFieldsService implements FacetFieldsService {
33
34    private final SearchResultsDao searchResultsDao;
35    private final SolrFacetQueryFactory queryFatory;
36
37    /**
38     *
39     * @param searchResultsDao DAO to use to retrieve facets
40     * @param queryFatory factory to use to construct facet queries
41     */
42    public SolrFacetFieldsService(SearchResultsDao searchResultsDao, SolrFacetQueryFactory queryFatory) {
43        this.searchResultsDao = searchResultsDao;
44        this.queryFatory = queryFatory;
45    }
46
47    @Override
48    public List<FacetField> getFacetFields(QueryFacetsSelection selection, List<String> facets, int valueLimit) {
49        //if excluded facet exists and it is equal to selected fire additional query
50        return (selection.getExcludedFacet() != null && selection.getExcludedFacet().equals(facets.get(0)))?
51        searchResultsDao.getFacets(queryFatory.createFacetQuery(selection, facets, valueLimit), 
52                        queryFatory.createExludedFacetQuery(selection, selection.getExcludedFacet(), valueLimit)) :
53        searchResultsDao.getFacets(queryFatory.createFacetQuery(selection, facets, valueLimit));
54    }
55
56    @Override
57    public long getFacetFieldCount(List<String> facets) {
58        return (long) searchResultsDao.getFacets(queryFatory.createCountFacetsQuery(facets)).size();
59    }
60
61}
Note: See TracBrowser for help on using the repository browser.