Changeset 3101 for trunk/java-client/org


Ignore:
Timestamp:
2002-04-25T12:44:10+12:00 (22 years ago)
Author:
kjdon
Message:

can now specify which index to search. Also, the filterOPtions for queryfilter are returned for each collection, and the available and default indexes displayed to the user.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleClient.java

    r2220 r3101  
    5656import org.nzdl.gsdl.service.NzdlServiceClient;
    5757import org.nzdl.gsdl.util.NzdlServiceFactory;
    58 
     58import org.nzdl.gsdl.service.NzdlFilterOption;
     59import org.nzdl.gsdl.service.NzdlFilterOptions;
    5960/**
    6061 * Class SimpleClient
     
    9798  /** The query to use */
    9899  String queryToQuery = "the";
     100    /** The index to use */
     101    String indexToQuery = "";
    99102  /** Poll all collections */
    100103  boolean examineAllCollections = false;
     
    211214    while (e.hasMoreElements()) {
    212215      String collName  = (String) e.nextElement();
    213       NzdlCollectionInfo collInfo = nzdl.getCollectionInfo( collName );
    214      
     216
     217
     218      // get some basic col info - num docs in collection
     219      NzdlCollectionInfo collInfo = nzdl.getCollectionInfo( collName );     
    215220      if (verbosity > 0)
    216221    System.out.println("Searching collection: " + collName);
    217222     
    218       long numResults = collInfo.getNumOfDocs(); // what precisely is this number ?
    219 
     223      long numResults = collInfo.getNumOfDocs(); // number of docs in collection
    220224      if (verbosity > 2)
    221     System.out.println("Collection " + collName + " suggests to get results in chunks of " + numResults + " hits" );
    222       if (verbosity > 2)
    223     System.out.println("Query Term: " + queryTerm);
     225    System.out.println("Collection " + collName + " has " + numResults + " documents" );
     226
     227      // get some filter options for query filter - list the indexes available
     228      NzdlFilterOptions filterops = nzdl.getFilterOptionSet(collName, "QueryFilter");
     229     
     230      NzdlFilterOption filt;
     231      if (verbosity > 1) {
     232      if (filterops.hasOption("Index")) {
     233          filt = (NzdlFilterOption)filterops.getFilterOption("Index");
     234          System.out.println(collName+"  has indexes "+ filt.validValues);
     235          System.out.println("The default index is "+filt.defaultValue);
     236      }
     237      }
     238
     239      if (verbosity > 1)
     240    System.out.print("Searching for query term: " + queryTerm+ ", in index: ");
     241      if (indexToQuery=="") {
     242      System.out.println("[default]");
     243      }
     244      else {
     245      System.out.println(indexToQuery);
     246      }
    224247      String metaTag = "Title";
    225248     
    226       if (verbosity > 2)
    227     System.out.println("Searching in '" + metaTag + "' metadata");
     249      // if (verbosity > 2)
     250      //System.out.println("Searching in '" + metaTag + "' metadata");
    228251     
    229252      NzdlQuery query = new NzdlQuery( queryTerm );
    230253      // return the first numResults that match
    231       //query.setEndResults( 15 );
     254      query.setEndResults( 200 );
    232255      // "-1" means consider all the documents that match
    233       query.setMaxDocs( -1 );
     256      query.setMaxDocs( 200);
     257      query.setIndex(indexToQuery); // for mgpp colls, this must be a valid index, or "". otherwise it will cause an error.
    234258     
    235259      NzdlRequest request = new NzdlRequest( query );
     
    286310    s += "-a         --all                    Examine all collections\n";
    287311    s += "-q <query> --query <query>          Use <query>\n";
     312    s += "-i <index> --index <index>          Query the <index> index\n";
    288313    s += "-d         --docs                   Load the documents as well\n";
    289314    s += "-Q         --queryAllCollections    Apply the <query> to all collections\n";
     
    301326    System.err.println("in parseArgs");
    302327   
    303     LongOpt[] longopts = new LongOpt[10];
     328    LongOpt[] longopts = new LongOpt[11];
    304329    int i = 0;
    305330    StringBuffer sb = new StringBuffer();
     
    312337    longopts[i++]  = new LongOpt("all",                   LongOpt.NO_ARGUMENT,       null, 'a');
    313338    longopts[i++]  = new LongOpt("query",                 LongOpt.REQUIRED_ARGUMENT, null, 'q');
     339    longopts[i++]  = new LongOpt("index",                 LongOpt.REQUIRED_ARGUMENT, null, 'i');
    314340    longopts[i++]  = new LongOpt("docs",                  LongOpt.NO_ARGUMENT,       null, 'd');
    315341    longopts[i++]  = new LongOpt("verbose",               LongOpt.REQUIRED_ARGUMENT, null, 'v');
     
    317343    Getopt g = new Getopt("org.nzdl.gsdl.SimpleClient",
    318344                          args,
    319                           "hI:f:c:aq:dv:Qu:",
     345                          "hI:f:c:aq:i:dv:Qu:",
    320346                          longopts);
    321347    int c;
     
    344370      queryToQuery = g.getOptarg();
    345371          break;
     372    case 'i':
     373        indexToQuery = g.getOptarg();
     374        break;
    346375    case 'a':
    347376      examineAllCollections = true;
     
    381410      client.pollCollections();
    382411   
    383     client.runQuery();
     412        client.runQuery();
    384413   
    385414  } //main
Note: See TracChangeset for help on using the changeset viewer.