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 | */ |
---|
17 | package eu.clarin.cmdi.vlo.service.solr.impl; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.service.solr.SolrFacetQueryFactory; |
---|
20 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
21 | import java.util.List; |
---|
22 | import 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 | */ |
---|
30 | public 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 | } |
---|