1 | package clarind.fcs; |
---|
2 | |
---|
3 | import eu.clarin.sru.client.*; |
---|
4 | |
---|
5 | import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordData; |
---|
6 | import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordParser; |
---|
7 | //import org.xml.sax.helpers.DefaultHandler; |
---|
8 | |
---|
9 | import org.zkoss.zul.Row; |
---|
10 | import org.zkoss.zul.Label; |
---|
11 | |
---|
12 | import java.util.*; |
---|
13 | |
---|
14 | public class SRUSearch { |
---|
15 | |
---|
16 | private ArrayList<Row> zeilen; |
---|
17 | |
---|
18 | public ArrayList<Row> execute(String query, String endpointURL, String corpus, int maximumRecords) throws Exception { |
---|
19 | zeilen = new ArrayList<Row>(); |
---|
20 | |
---|
21 | SRUClient client = new SRUClient(); |
---|
22 | client.registerRecordParser(new ClarinFederatedContentSearchRecordParser()); |
---|
23 | |
---|
24 | SRUSearchRetrieveRequest request = new SRUSearchRetrieveRequest(endpointURL); |
---|
25 | request.setQuery(query); |
---|
26 | request.setRecordSchema(ClarinFederatedContentSearchRecordParser.FCS_RECORD_SCHEMA); |
---|
27 | request.setMaximumRecords(maximumRecords); |
---|
28 | |
---|
29 | if (corpus != null) { |
---|
30 | request.setExtraRequestData("x-context", corpus); |
---|
31 | System.out.println("I'm setting the x-context"); |
---|
32 | |
---|
33 | } |
---|
34 | try { |
---|
35 | client.searchRetrieve(request, new SRUDefaultHandlerAdapter() { |
---|
36 | @Override |
---|
37 | public void onRecord(String identifier, int position, SRURecordData data) throws SRUClientException { |
---|
38 | if (ClarinFederatedContentSearchRecordParser.FCS_NS.equals(data.getRecordSchema())) { |
---|
39 | ClarinFederatedContentSearchRecordData record = (ClarinFederatedContentSearchRecordData) data; |
---|
40 | String left = record.getLeft(); |
---|
41 | String hit = record.getKeyword(); |
---|
42 | String right = record.getRight(); |
---|
43 | |
---|
44 | // System.out.print("LEFT: " + left); |
---|
45 | // System.out.println("HIT: " + hit); |
---|
46 | // System.out.println("RIGHT: " + right); |
---|
47 | |
---|
48 | Row r = new Row(); |
---|
49 | r.appendChild(new Label(left)); |
---|
50 | r.appendChild(new Label(hit)); |
---|
51 | r.appendChild(new Label(right)); |
---|
52 | |
---|
53 | zeilen.add(r); |
---|
54 | } |
---|
55 | } |
---|
56 | }); |
---|
57 | } catch (Exception ex){ |
---|
58 | System.out.println(ex.getMessage()); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | // System.out.println("NUMBER of LINES: " + zeilen.size()); |
---|
63 | |
---|
64 | return zeilen; |
---|
65 | } |
---|
66 | |
---|
67 | public static void main(String[] args) throws Exception { |
---|
68 | } // main |
---|
69 | } |
---|