source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/SolrDocumentQueryFactoryImpl.java @ 4634

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

made constant for document fields in query factory

File size: 2.6 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.impl;
18
19import eu.clarin.cmdi.vlo.FacetConstants;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import eu.clarin.cmdi.vlo.service.SolrDocumentQueryFactory;
22import org.apache.solr.client.solrj.SolrQuery;
23
24/**
25 *
26 * @author twagoo
27 */
28public class SolrDocumentQueryFactoryImpl extends AbstractSolrQueryFactory implements SolrDocumentQueryFactory {
29
30    public static final String[] DOCUMENT_FIELDS = {
31        FacetConstants.FIELD_NAME,
32        FacetConstants.FIELD_DESCRIPTION,
33        FacetConstants.FIELD_COLLECTION,
34        FacetConstants.FIELD_GENRE,
35        FacetConstants.FIELD_LANGUAGE,
36        FacetConstants.FIELD_NATIONAL_PROJECT,
37        FacetConstants.FIELD_RESOURCE_CLASS,
38        FacetConstants.FIELD_RESOURCE,
39        FacetConstants.FIELD_LANDINGPAGE,
40        FacetConstants.FIELD_ID
41    };
42
43    @Override
44    public SolrQuery createDocumentQuery(QueryFacetsSelection selection, int first, int count) {
45        // make a query to get all documents that match the selection criteria
46        final SolrQuery query = getDefaultDocumentQuery();
47        // apply selection
48        addQueryFacetParameters(query, selection);
49        // set offset and limit
50        query.setStart(first);
51        query.setRows(count);
52        return query;
53    }
54
55    @Override
56    public SolrQuery createDocumentQuery(String docId) {
57        // make a query to look up a specific document by its ID
58        final SolrQuery query = getDefaultDocumentQuery();
59        // consider all documents
60        query.setQuery(SOLR_SEARCH_ALL);
61        // filter by ID
62        query.addFilterQuery(createFilterQuery(FacetConstants.FIELD_ID, docId));
63        // one result max
64        query.setRows(1);
65        return query;
66
67    }
68
69    private SolrQuery getDefaultDocumentQuery() {
70        SolrQuery query = new SolrQuery();
71        query.setFields(DOCUMENT_FIELDS);
72        query.setSort(SolrQuery.SortClause.asc(FacetConstants.FIELD_NAME));
73        return query;
74    }
75}
Note: See TracBrowser for help on using the repository browser.