source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/solr/impl/SolrFacetQueryFactoryImpl.java @ 4932

Last change on this file since 4932 was 4932, checked in by Twan Goosen, 10 years ago

List of included facet fields is now passed in each request, so that only the facets that are actually required are fetched

File size: 2.2 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.service.solr.SolrFacetQueryFactory;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import java.util.List;
22import org.apache.solr.client.solrj.SolrQuery;
23
24/**
25 * Implements a SOLR query factory, to be used by SOLR service implementation
26 * for the VLO
27 *
28 * @author twagoo
29 */
30public class SolrFacetQueryFactoryImpl extends AbstractSolrQueryFactory implements SolrFacetQueryFactory {
31
32    private final SolrQuery baseQuery;
33
34    /**
35     *
36     */
37    public SolrFacetQueryFactoryImpl() {
38        // create the base query (copied on each request to create new queries)
39        baseQuery = new SolrQuery();
40        baseQuery.setRows(0);
41        baseQuery.setFacet(true);
42        baseQuery.setFacetMinCount(1);
43    }
44
45    @Override
46    public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections, List<String> facets, int facetValueLimit) {
47        final SolrQuery query = getBaseQuery(facets);
48        addQueryFacetParameters(query, queryFacetsSelections);
49        query.setFacetLimit(facetValueLimit);
50        return query;
51    }
52
53    @Override
54    public synchronized SolrQuery createCountFacetsQuery(List<String> facets) {
55        final SolrQuery query = getBaseQuery(facets);
56        query.setFacetLimit(0);
57        return query;
58    }
59
60    private SolrQuery getBaseQuery(List<String> facets) {
61        SolrQuery query = baseQuery.getCopy();
62        query.addFacetField(facets.toArray(new String[facets.size()]));
63        return query;
64    }
65
66}
Note: See TracBrowser for help on using the repository browser.