Changeset 926


Ignore:
Timestamp:
2000-02-16T11:38:28+13:00 (24 years ago)
Author:
kjm18
Message:

added options to change index and level for searching

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/mgpp/text/Queryer.cpp

    r879 r926  
    3333int main (int argc, char **argv) {
    3434  int ch;
    35   char *filename = "";
     35  char *textfilename = "";
     36  char *indexfilename = "";
    3637  char *basePath = "";
    3738 
     
    4041 
    4142  // process the command line arguments
    42   while ((ch = getopt (argc, argv, "f:d:h")) != -1) {
     43  while ((ch = getopt (argc, argv, "f:t:d:h")) != -1) {
    4344    switch (ch) {
    4445    case 'f':       /* input file */
    45       filename = optarg;
     46      indexfilename = optarg;
     47      break;
     48    case 't':
     49      textfilename = optarg;
    4650      break;
    4751    case 'd':
     
    5660  }
    5761
    58   if (filename[0] == '\0') {
    59     FatalError (1, "A file name must be specified with -f\n");
     62  if (textfilename[0] == '\0' || indexfilename[0] == '\0') {
     63    FatalError (1, "A file name must be specified with -f and -t \n");
    6064  }
    6165 
    6266  // init the text system
    6367  TextData textData;
    64   if (!textData.LoadData (filename)) {
    65     FatalError (1, "Couldn't load text information for \"%s\"", filename);
     68  if (!textData.LoadData (textfilename)) {
     69    FatalError (1, "Couldn't load text information for \"%s\"", textfilename);
    6670  }
    6771 
    6872  // init the query system
    6973  IndexData indexData;
    70   if (!indexData.LoadData (basePath, filename)) {
    71     FatalError (1, "Couldn't load index information for \"%s\"", filename);
     74  if (!indexData.LoadData (basePath, indexfilename)) {
     75    FatalError (1, "Couldn't load index information for \"%s\"", indexfilename);
    7276  }
    7377
    7478  // do querying
    7579  QueryInfo queryInfo;
    76   SetCStr (queryInfo.docLevel, "Chapter");
    77   queryInfo.maxDocs = 10;
     80  SetCStr (queryInfo.docLevel, "Document");
     81  queryInfo.maxDocs = 50;
    7882  queryInfo.sortByRank = true;
    7983  queryInfo.exactWeights = false;
     
    8185  queryInfo.needTermFreqs = true;
    8286 
    83   QueryResult queryResult;
     87  ExtQueryResult queryResult;
    8488  char query[2048];
    8589  UCArray queryArray;
    8690  QueryNode *queryTree = NULL;
     91
     92  UCArray level;
     93  level.clear();
     94  //SetCStr(level, "");
     95     
    8796
    8897  while (true) {
     
    95104    if (queryArray.size() >= 2 && queryArray[0] == '.') {
    96105      if (queryArray[1] == 'q') break;  // quit
     106     
    97107
    98       if (queryArray[1] == 'p') {
     108      if (queryArray[1] == 'i') {
     109    cout << "current index="<< queryInfo.docLevel << "\nchange to index:";
     110    cin >> query;
     111    queryInfo.docLevel.clear();
     112    SetCStr(queryInfo.docLevel, query);
     113    cout << "index set to " << queryInfo.docLevel <<"\n";
     114    cin.getline(query, 2048, '\n');
     115      }
     116      if (queryArray[1] == 'l') {
     117    cout << "current level="<< level << "\nchange to level:";
     118    cin >> query;
     119    level.clear();
     120    SetCStr(level, query);
     121    cout << "level set to " << level <<"\n";
     122    cin.getline(query, 2048, '\n');
     123      }
     124
     125
     126      else if (queryArray[1] == 'p') {
    99127    // print
    100128    UCArray docText;
     
    117145      PrintNode (cout, queryTree);
    118146
    119       MGQuery (indexData, queryInfo, queryTree, queryResult);
     147      MGQuery (indexData, queryInfo, queryTree, queryResult, level);
    120148      cout << queryResult;
    121149      cout << "\n";
Note: See TracChangeset for help on using the changeset viewer.