source: trunk/java-client/org/nzdl/gsdl/SimpleClient.java@ 2055

Last change on this file since 2055 was 2055, checked in by paynter, 23 years ago

Initial revision

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1
2
3import java.util.*;
4import java.text.*; // for date processing
5import javax.swing.tree.*;
6import org.nzdl.service.*;
7
8
9public class SimpleClient {
10
11 public static final void main( String [] args ) {
12
13 NzdlService nzdl = new NzdlServiceImpl( args );
14
15 if (args.length < 3) {
16 System.err.println("WARNING: missing command line arguments. using defualts:");
17 System.err.println("usage: java <javaoptions> SimpleClient <collect> <xxx> <query>");
18 System.err.println(" <javaoptions> = options to the JVM ");
19 System.err.println(" <collect> = the greenstone collection to use (demo)");
20 System.err.println(" <xxx> = a currently unused option (xxx)");
21 System.err.println(" <query> = the query to use on the collection (the)");
22 args = new String [3];
23 args[0] = "demo";
24 args[1] = "xxx";
25 args[2] = "the";
26 }
27
28 // extract some highlevel information on the collections on the server
29 // independent of the command line arguments passed in
30
31 Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles
32 System.out.println("Number of collections on the server: " + collectionSet.size());
33
34 Iterator collectionSetIterator = collectionSet.iterator();
35 while (collectionSetIterator.hasNext() ) {
36 String collectionName = (String)collectionSetIterator.next(); // object -> String
37 NzdlCollectionInfo collectionInfo = nzdl.getCollectionInfo( collectionName );
38 // this next line should work but doesn't
39 System.out.println("Collection: " + collectionInfo.getName());
40 // so we revert to using the original string from the collectionSet
41 System.out.println("Collection: " + collectionName);
42 if (nzdl.hasCollection(collectionName) ) {
43 System.out.println("\t" + "hasCollection(" + collectionName + ")" + " is true");
44 if (nzdl.pingCollection(collectionName) ) {
45 System.out.println("\t" + "pingCollection(" + collectionName + ")" + " is true");
46 // these next statements make use of the NzdlCollection API
47 System.out.println("\t" + "Public: " + collectionInfo.isPublic());
48 System.out.println("\t" + "Beta: " + collectionInfo.isBeta());
49 int buildDate = collectionInfo.getBuildDate();
50 //process buildDate into something sensible
51 System.out.println("\t" + "Build Date: " + buildDate);
52 System.out.println("\t" + "No. of Documents: " + collectionInfo.getNumOfDocs());
53 System.out.println("\t" + "No. of Words: " + collectionInfo.getNumOfWords());
54 System.out.println("\t" + "No. of Bytes: " + collectionInfo.getNumOfBytes());
55 }
56 else {
57 System.out.println("\t" + "pingCollection(" + collectionName + ")" + " is false");
58 }
59 }
60 else
61 { System.out.println("\t" + "hasCollection(" + collectionName + ")" + " is false"); }
62 }
63
64
65
66
67 String collName = args[0];
68 NzdlCollectionInfo collInfo = nzdl.getCollectionInfo( collName );
69
70 System.out.println("Searching collection: " + collName);
71
72 int numResults = collInfo.getNumOfDocs(); // what precisely is this number ?
73 System.out.println("Collection " + collName + " suggests to get results in chunks of " + numResults + " hits" );
74 String method = args[1];
75 System.out.println("Search method: " + method);
76 String queryTerm = args[2];
77 System.out.println("Query Term: " + queryTerm);
78 String metaTag = "Title";
79
80 System.out.println("Searching in '" + metaTag + "' metadata");
81
82 NzdlQuery query = new NzdlQuery( queryTerm );
83 // return the first numResults that match
84 //query.setEndResults( 15 );
85 // "-1" means consider all the documents that match
86 query.setMaxDocs( -1 );
87
88 NzdlRequest request = new NzdlRequest( query );
89 NzdlResponse response = new NzdlResponse( );
90 System.out.println("getting document IDs ... ");
91 nzdl.service( collName, request, response );
92
93 NzdlResultSet results = response.getResultSet();
94 List docIDs = results.getDocumentIDs();
95 System.out.println("Number of documents returned: " + docIDs.size());
96
97 System.out.println("getting '" + metaTag + "' meta data of documents ... ");
98 Map metaData = nzdl.getMetaData( collName, docIDs, metaTag );
99
100 for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) {
101 String id = (String) i.next();
102 Set meta = (Set) metaData.get( id );
103 System.out.println(meta.toString());
104 System.out.println("getting document contents ... ");
105 String documentContents = nzdl.getDocument(collName, id);
106 System.out.println("got document contents. ");
107 System.out.println(" *************** START DOC " + id + " ***************");
108 System.out.println(documentContents);
109 System.out.println(" *************** END DOC " + id + " ***************");
110 }
111
112
113 } //main
114
115} // class
Note: See TracBrowser for help on using the repository browser.