Changeset 1900


Ignore:
Timestamp:
2001-02-02T14:33:01+13:00 (23 years ago)
Author:
jrm21
Message:

The z39.50 client now does "and" or "or" boolean searches depending on
whether "some" or "all" is chosen in the UI. Note that this has been claimed
for some time, but it actually does it now :)

Location:
trunk/gsdl/src/recpt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/z3950proto.cpp

    r1738 r1900  
    351351    // go through options
    352352    text_t opt_term;            // the term(s) that the user entered
     353    int opt_querytype=0;        // 1=>ranked (or), 2=>boolean (and)
    353354    text_t opt_fields;          // which fields to search on
    354355    int opt_start=1, opt_end=20; // default values
     
    357358    OptionValue_tarray::iterator ov_end=request.filterOptions.end();
    358359    while (ov_here != ov_end) {
    359       // cerr << "OV pair: `" << ov_here->name.getcstr() << "'=`"
    360       //      << ov_here->value.getcstr() << "'\n";
    361       if (ov_here->name=="Term")
    362     {
    363       opt_term=ov_here->value;
    364     } else if (ov_here->name=="Index")
    365       {
    366         opt_fields=ov_here->value;
    367       } else if (ov_here->name=="StartResults")
    368         {
    369           opt_start=ov_here->value.getint();
    370         } else if (ov_here->name=="EndResults")
    371           {
    372         opt_end=ov_here->value.getint();
    373           } else if (ov_here->name=="Maxdocs")
    374         {
    375           maxdocs=ov_here->value.getint();
    376         }
     360      if (ov_here->name=="Term") {
     361    opt_term=ov_here->value;
     362      } else if (ov_here->name=="QueryType") {
     363    if (ov_here->value=="ranked") opt_querytype=1;
     364    else if (ov_here->value=="boolean") opt_querytype=2;
     365    else { /* error - shouldn't happen */
     366      /* currently unhandled */
     367    }
     368      } else if (ov_here->name=="Index") {
     369    opt_fields=ov_here->value;
     370      } else if (ov_here->name=="StartResults") {
     371    opt_start=ov_here->value.getint();
     372      } else if (ov_here->name=="EndResults") {
     373    opt_end=ov_here->value.getint();
     374      } else if (ov_here->name=="Maxdocs") {
     375    maxdocs=ov_here->value.getint();
     376      }
    377377      ov_here++;
    378378    }
    379379    err=noError;
    380380    text_tarray *titles=(*zserver)->getrecordTitles(opt_term,
     381                            opt_querytype,
    381382                            opt_fields,
    382383                            opt_start, // first to get
     
    422423    } // end of if (... & FRtermFreq)
    423424   
    424   } // end of if (... & FROID)
     425  } // end of if (... == "QueryFilter")
    425426  else {
    426427    // this wasn't a query action
     
    443444      response.docInfo.push_back(*docInfo);
    444445    }
    445   }
     446  } // end of not a query action
     447
     448
    446449
    447450  // Fill in metadata for each response.docInfo (if wanted)
     
    450453    // should check err returned here....
    451454
    452     // get the Query out of the filterOptions.
    453     text_t query="";
    454     text_t field="";
    455     OptionValue_tarray::iterator opt_here=request.filterOptions.begin();
    456     OptionValue_tarray::iterator opt_end=request.filterOptions.end();
    457     while (opt_here!=opt_end) {
    458       if (opt_here->name=="Query") {
    459     query=opt_here->value;
    460     if (field!="") break; // break from loop if we've got both
    461       } else if (opt_here->name=="Index") {
    462     field=opt_here->value;
    463     if (query!="") break; // break from loop if we've got both
    464       }
    465       opt_here++;
    466     }
    467 
    468455    if (!request.fields.empty()) {
     456      // currently, this is only true for NullFilter when getting the "Title"
     457      // for a documentaction.
     458
    469459      // loop on each document being returned
    470460      ResultDocInfo_tarray::iterator docs_here=response.docInfo.begin();
    471461      ResultDocInfo_tarray::iterator docs_end=response.docInfo.end();
    472462      while (docs_here!=docs_end) {
    473    
    474463    // loop on all the metadata fields in request.fields (type text_tset)
    475464    text_tset::iterator fields_here=request.fields.begin();
     
    489478        i=request.docSet[0].getint();
    490479        text_t doctext="unneeded";
    491         (*zserver)->getfullrecord(query, field, i, doctitle, doctext, err);
     480        /* following variables aren't used, as our query result has been
     481           cached in z3950server.cpp (but really we shouldn't know that
     482           here...) But for the NullFilter, we don't get given these
     483           again in the request, so for now we'll take advantage of this.*/
     484
     485        int querytype=0; text_t field="";
     486
     487        // get the Query out of the filterOptions. (we need get the Title)
     488        text_t query="";
     489        OptionValue_tarray::iterator opthere=request.filterOptions.begin();
     490        OptionValue_tarray::iterator opt_end=request.filterOptions.end();
     491        while (opthere!=opt_end) {
     492          if (opthere->name=="Query") {
     493        query=opthere->value;
     494        break;
     495          }
     496          opthere++;
     497        }
     498        (*zserver)->getfullrecord(query, querytype, field, i, doctitle, doctext, err);
    492499        // check err value!
    493500        docs_here->metadata["Title"].values.push_back(doctitle);       
    494501      } else {
    495502        docs_here->metadata[*fields_here].values.push_back("");
    496         /////// cerr << " (not found)";
    497503      }
    498504      fields_here++;
     
    501507      } // end of outer while loop
    502508    } // end of if (!request.fields.empty())
    503 
     509   
    504510    else { // request.fields empty: return all metadata for about page or query
    505511      // we'll only put it in the first docInfo.
     
    571577  text_t query; // this should not be needed, as we have already connected to
    572578  // get the  title....
    573   text_t field; // ditto...
    574   (*zserver)->getfullrecord(query,field,request.OID.getint(),
     579  int querytype; //ditto...
     580  text_t field;  // ditto...
     581  (*zserver)->getfullrecord(query,querytype,field,request.OID.getint(),
    575582                title,doctext,err);
    576583  // check return value of above? (false=>not connected)
  • trunk/gsdl/src/recpt/z3950server.cpp

    r1738 r1900  
    107107
    108108void z3950_server::parseQuery(const text_t &query,
     109                  const int querytype,
    109110                  const text_t &fields,
    110111                  text_t &parsed_query) {
     
    127128  bool inword=false;
    128129  int num_terms=0;
     130
    129131
    130132  for (int i=0;i<strlength;i++) {
     
    161163    parsed_query+="1016 ";
    162164
     165  // querytype=1 => ranked/or,  =2 => boolean/and
    163166  // append "@and" for each term after the first
    164   for (int i=1;i<num_terms;i++)
    165     parsed_query+="@and ";
    166   // append the actual query
    167   parsed_query+=ptr;
    168 
     167  {
     168    char and_str[]="@and ";
     169    char or_str[]="@or ";
     170    char *q_type;
     171    if (querytype==1) q_type=or_str; else q_type=and_str;
     172    for (int i=1;i<num_terms;i++)
     173      parsed_query+=q_type;
     174    // append the actual query
     175    parsed_query+=ptr;
     176  }
    169177  delete ptr;
    170178}
    171179
    172180text_tarray *z3950_server::getrecordTitles(const text_t &query,
     181                       const int querytype,
    173182                       const text_t &fields,
    174183                       int first, int count,
     
    210219
    211220  text_t expanded_query="";
    212   parseQuery(query,fields,expanded_query);
     221  parseQuery(query,querytype,fields,expanded_query);
    213222
    214223  char* query_str=expanded_query.getcstr();
     
    253262}
    254263
    255 bool z3950_server::getfullrecord(const text_t &query, const text_t &fields,
     264bool z3950_server::getfullrecord(const text_t &query,
     265                 const int querytype,
     266                 const text_t &fields,
    256267                 const int ID,
    257268                 text_t &rettitle,
     
    279290
    280291    text_t expanded_query="";
    281     parseQuery(query,fields,expanded_query);
     292    parseQuery(query,querytype,fields,expanded_query);
    282293
    283294    char* query_str=expanded_query.getcstr();
  • trunk/gsdl/src/recpt/z3950server.h

    r1617 r1900  
    5858  text_t &getzAbout(); // gets any name, id, MOTD, etc from server.
    5959  text_tarray *getrecordTitles(const text_t &query,
     60                   const int querytype,
    6061                   const text_t &fields,
    6162                   const int first, const int count,
     
    6364  /* only get one record at a time? (Eventually we could buffer them, but
    6465     for now... */
    65   bool getfullrecord(const text_t &query, const text_t &fields,
     66  bool getfullrecord(const text_t &query, const int querytype,
     67             const text_t &fields,
    6668             const int ID, text_t &rettitle,
    6769             text_t &rettext,comerror_t &err);
    6870 private:
    69   void parseQuery(const text_t &query, const text_t &fields,
     71  void parseQuery(const text_t &query, const int querytype,
     72          const text_t &fields,
    7073          text_t &parsed_query);
    7174};
Note: See TracChangeset for help on using the changeset viewer.