Changeset 2161 for SRUAggregator/trunk/src/java/clarind/fcs/SRUSearch.java
- Timestamp:
- 08/28/12 14:52:41 (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
SRUAggregator/trunk/src/java/clarind/fcs/SRUSearch.java
r2107 r2161 1 1 package clarind.fcs; 2 3 2 4 3 import eu.clarin.sru.client.*; … … 6 5 import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordData; 7 6 import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordParser; 7 import org.xml.sax.helpers.DefaultHandler; 8 8 9 import java.util.*; 10 public class TestSRUClient1 { 9 import org.zkoss.zul.Html; 10 import org.zkoss.zul.Grid; 11 import org.zkoss.zul.Rows; 12 import org.zkoss.zul.Row; 13 import org.zkoss.zul.Label; 14 15 16 public class SRUSearch { 17 private StringBuilder sb; 11 18 12 public static void main (String[] args) throws Exception { 13 14 String url = "http://weblicht.sfs.uni-tuebingen.de/rws/cqp-ws/cqp/sru"; 15 16 SRUClient client = new SRUClient(SRUVersion.VERSION_1_2); 17 18 client.registerRecordParser(new ClarinFederatedContentSearchRecordParser()); 19 20 SRUDefaultHandlerAdapter handler = new SRUDefaultHandlerAdapter(); 21 22 SRUExplainRequest request = new SRUExplainRequest(url); 23 client.explain(request, handler); 19 public StringBuilder execute(String query, String endpointURL, String corpus, int maximumRecords, Html results, final Grid grid) throws Exception { 20 sb = new StringBuilder(); 21 sb.append("URL: "+ endpointURL + "<br>"); 22 sb.append("CORPUS: " + corpus + "<br><hr>"); 24 23 25 24 26 25 SRUClient client = new SRUClient(); 26 client.registerRecordParser(new ClarinFederatedContentSearchRecordParser()); 27 28 SRUSearchRetrieveRequest request = new SRUSearchRetrieveRequest(endpointURL); 29 request.setQuery(query); 30 request.setRecordSchema(ClarinFederatedContentSearchRecordParser.FCS_RECORD_SCHEMA); 31 request.setMaximumRecords(maximumRecords); 32 33 if (corpus != null) { 34 request.setExtraRequestData("x-context", corpus); 35 System.out.println("I'm setting the x-context"); 36 37 } 38 39 client.searchRetrieve(request, new SRUDefaultHandlerAdapter() { 40 @Override 41 public void onRecord(String identifier, int position, SRURecordData data) throws SRUClientException { 42 if (ClarinFederatedContentSearchRecordParser.FCS_NS.equals(data.getRecordSchema())) { 43 ClarinFederatedContentSearchRecordData record = (ClarinFederatedContentSearchRecordData) data; 44 String left = record.getLeft(); 45 String hit = record.getKeyword(); 46 String right = record.getRight(); 47 48 System.out.print("LEFT: " + left); 49 System.out.println("HIT: " + hit); 50 System.out.println("RIGHT: " + right); 51 52 sb.append(left); 53 sb.append("<font color='red'>"); 54 sb.append(" " + hit + " "); 55 sb.append("</font>"); 56 sb.append(right); 57 sb.append("<br><br>"); 58 59 // Rows rows = grid.getRows(); 60 // Row r = new Row(); 61 // r.appendChild(new Label(left)); 62 // r.appendChild(new Label(hit)); 63 // r.appendChild(new Label(right)); 64 // 65 // rows.appendChild(r); 66 67 68 } 69 } 70 }); 71 sb.append("<hr>"); 72 return sb; 73 } 74 75 public static void main(String[] args) throws Exception { 76 77 78 79 27 80 } // main 28 29 81 }
Note: See TracChangeset
for help on using the changeset viewer.