source: vlo/branches/to-wicket-1.6/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/SearchServiceDataProvider.java @ 4201

Last change on this file since 4201 was 4201, checked in by keeloo, 10 years ago

After splitting of a branch (r4199) including code for moving from wicket 1.4 to wicket 6, some more modifications in the direction of that target.

  • Property svn:mime-type set to text/plain
File size: 2.4 KB
Line 
1package eu.clarin.cmdi.vlo.pages;
2
3import java.util.Iterator;
4
5import org.apache.solr.client.solrj.SolrQuery;
6import org.apache.solr.common.SolrDocument;
7import org.apache.solr.common.SolrDocumentList;
8import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
9import org.apache.wicket.model.IModel;
10import org.apache.wicket.model.Model;
11import org.slf4j.Logger;
12import org.slf4j.LoggerFactory;
13
14import eu.clarin.cmdi.vlo.FacetConstants;
15import eu.clarin.cmdi.vlo.dao.DaoLocator;
16import eu.clarin.cmdi.vlo.dao.SearchResultsDao;
17
18/**
19 * Data provider of all documents with SearchService entry (FCS) based on
20 * existing SolrQuery
21 *
22 * @author Thomas Eckart
23 *
24 */
25public class SearchServiceDataProvider extends SortableDataProvider<SolrDocument, String> {
26
27    private final static Logger LOG = LoggerFactory.getLogger(SearchServiceDataProvider.class);
28    private static final long serialVersionUID = -5355607690141772113L;
29    private final SolrQuery query;
30    private SolrDocumentList docList;
31
32    public SearchServiceDataProvider(SolrQuery query) {
33        this.query = query;
34        this.query.setFacet(false);
35        this.query.setStart(0);
36        this.query.setRows(10);
37        this.query.setFields(FacetConstants.FIELD_SEARCH_SERVICE, FacetConstants.FIELD_ID);
38        this.query.setQuery(query.getQuery());
39        this.query.addFilterQuery(FacetConstants.FIELD_SEARCH_SERVICE + ":*");
40        LOG.debug("Used query for search services: " + this.query.toString());
41    }
42
43    private SearchResultsDao getSearchResultsDao() {
44        return DaoLocator.getSearchResultsDao();
45    }
46
47    private SolrDocumentList getDocList() {
48        if (docList == null) {
49            docList = getSearchResultsDao().getResults(query);
50        }
51        return docList;
52    }
53
54    @Override
55    public Iterator<SolrDocument> iterator(long first, long count) {
56        if (first != query.getStart().intValue() || count != query.getRows().intValue()) {
57            query.setStart((int) first).setRows((int) count);
58            docList = null;
59        }
60        return getDocList().iterator();
61    }
62
63    public Iterator<SolrDocument> iterator() {
64        return getDocList().iterator();
65    }
66
67    @Override
68    public IModel<SolrDocument> model(SolrDocument solrDocument) {
69        return new Model<SolrDocument>(solrDocument);
70    }
71
72    @Override
73    public long size() {
74        return getDocList().getNumFound();
75    }
76}
Note: See TracBrowser for help on using the repository browser.