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

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

ignored and technical fields are now configured through VloConfig?.xml

File size: 2.9 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_ID,
40        FacetConstants.FIELD_DATA_PROVIDER,
41        FacetConstants.FIELD_FILENAME,
42        FacetConstants.FIELD_FORMAT,
43        FacetConstants.FIELD_LANDINGPAGE,
44        FacetConstants.FIELD_SEARCHPAGE,
45        FacetConstants.FIELD_SEARCH_SERVICE,
46        FacetConstants.FIELD_LAST_SEEN,
47        FacetConstants.FIELD_CLARIN_PROFILE
48    };
49
50    @Override
51    public SolrQuery createDocumentQuery(QueryFacetsSelection selection, int first, int count) {
52        // make a query to get all documents that match the selection criteria
53        final SolrQuery query = getDefaultDocumentQuery();
54        // apply selection
55        addQueryFacetParameters(query, selection);
56        // set offset and limit
57        query.setStart(first);
58        query.setRows(count);
59        return query;
60    }
61
62    @Override
63    public SolrQuery createDocumentQuery(String docId) {
64        // make a query to look up a specific document by its ID
65        final SolrQuery query = getDefaultDocumentQuery();
66        // consider all documents
67        query.setQuery(SOLR_SEARCH_ALL);
68        // filter by ID
69        query.addFilterQuery(createFilterQuery(FacetConstants.FIELD_ID, docId));
70        // one result max
71        query.setRows(1);
72        return query;
73
74    }
75
76    private SolrQuery getDefaultDocumentQuery() {
77        SolrQuery query = new SolrQuery();
78        query.setFields(DOCUMENT_FIELDS);
79        query.setSort(SolrQuery.SortClause.asc(FacetConstants.FIELD_NAME));
80        return query;
81    }
82}
Note: See TracBrowser for help on using the repository browser.