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

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

Package structure: separated solr services from other services and moved all panels into new wicket.panels package

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 facetCountQuery;
33    private final String[] facets;
34   
35    /**
36     *
37     * @param facets names of facets to include in query
38     */
39    public SolrFacetQueryFactoryImpl(List<String> facets) {
40        this.facets = facets.toArray(new String[facets.size()]);
41
42        // create the query used to count facets (will never change)
43        facetCountQuery = getDefaultFacetQuery();
44        facetCountQuery.setRows(0);
45    }
46   
47    @Override
48    public SolrQuery createFacetQuery(QueryFacetsSelection queryFacetsSelections) {
49        final SolrQuery query = getDefaultFacetQuery();
50        addQueryFacetParameters(query, queryFacetsSelections);
51        return query;
52    }
53   
54    private SolrQuery getDefaultFacetQuery() {
55        SolrQuery query = new SolrQuery();
56        query.setRows(0);
57        query.setFacet(true);
58        query.setFacetMinCount(1);
59        query.addFacetField(facets);
60        return query;
61    }
62   
63    @Override
64    public synchronized SolrQuery createCountFacetsQuery() {
65        return facetCountQuery;
66    }
67   
68}
Note: See TracBrowser for help on using the repository browser.