Changeset 235


Ignore:
Timestamp:
1999-04-12T15:45:05+12:00 (25 years ago)
Author:
rjmcnab
Message:

Finished the query filter.

Location:
trunk/gsdl/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/colservr/filter.cpp

    r226 r235  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/04/12 03:45:02  rjmcnab
     15   Finished the query filter.
     16
    1417   Revision 1.3  1999/04/06 22:20:30  rjmcnab
    1518   Got browsefilter working.
     
    220223  set1 = resultset;
    221224}
     225
     226
     227// tests to see if el is in set
     228bool in_set (const text_tset &set1, const text_t &el) {
     229  text_t::const_iterator here = el.begin();
     230  text_t::const_iterator end = el.begin();
     231  text_t tryel, tryel_add;
     232  bool first = true;
     233
     234  // the element is in the set if any of its parents are
     235  // in the set
     236  do {
     237    // get next possible element to try
     238    here = getdelimitstr (here, end, '.', tryel_add);
     239    if (!first) tryel += ".";
     240    first = false;
     241    tryel += tryel_add;
     242
     243    // see if this element is in the set
     244    if (set1.find(tryel) != set1.end()) return true;
     245  } while (here != end);
     246
     247  return false;
     248}
  • trunk/gsdl/src/colservr/filter.h

    r226 r235  
    113113void intersect (text_tset &set1, const text_tset &set2);
    114114
     115// tests to see if el is in set
     116bool in_set (const text_tset &set1, const text_t &el);
     117
    115118#endif
  • trunk/gsdl/src/colservr/queryfilter.cpp

    r227 r235  
    1212/*
    1313   $Log$
     14   Revision 1.2  1999/04/12 03:45:03  rjmcnab
     15   Finished the query filter.
     16
    1417   Revision 1.1  1999/04/06 22:22:09  rjmcnab
    1518   Initial revision.
     
    2023#include "queryfilter.h"
    2124#include "fileutil.h"
     25#include "queryinfo.h"
     26
     27
     28// some useful functions
     29
     30// translate will return true if successful
     31static bool translate (gdbmclass *gdbmptr, int docnum, text_t &trans_OID) {
     32  infodbclass info;
     33
     34  trans_OID.clear();
     35
     36  // get the info
     37  if (gdbmptr == NULL) return false;
     38  if (!gdbmptr->getinfo(docnum, info)) return false;
     39
     40  // translate
     41  if (info["section"].empty()) return false;
     42
     43  trans_OID = info["section"];
     44  return true;
     45}
     46
    2247
    2348
     
    163188}
    164189
    165 void queryfilterclass::filter (const FilterRequest_t &/*request*/,
     190void queryfilterclass::filter (const FilterRequest_t &request,
    166191                FilterResponse_t &response,
    167                 comerror_t &err, ostream &/*logout*/) {
    168   response.clear();
     192                comerror_t &err, ostream &logout) {
     193  outconvertclass text_t2ascii;
     194
     195  response.clear ();
    169196  err = noError;
    170 }
     197  if (gdbmptr == NULL) {
     198    // most likely a configuration problem
     199    logout << text_t2ascii
     200       << "configuration error: queryfilter contains a null gdbmclass\n\n";
     201    err = configurationError;
     202    return;
     203  }
     204  if (mgsearchptr == NULL) {
     205    // most likely a configuration problem
     206    logout << text_t2ascii
     207       << "configuration error: queryfilter contains a null mgsearchclass\n\n";
     208    err = configurationError;
     209    return;
     210  }
     211
     212  // open the database
     213  gdbmptr->setlogout(&logout);
     214  if (!gdbmptr->opendatabase (gdbm_filename)) {
     215    // most likely a system problem (we have already checked that the
     216    // gdbm database exists)
     217    logout << text_t2ascii
     218       << "system problem: open on gdbm database \""
     219       << gdbm_filename << "\" failed\n\n";
     220    err = systemProblem;
     221    return;
     222  }
     223
     224  // get the query parameters
     225  int startresults = filterOptions["StartResults"].defaultValue.getint();
     226  int endresults = filterOptions["EndResults"].defaultValue.getint();
     227  text_t index = filterOptions["Index"].defaultValue;
     228  text_t subcollection = filterOptions["Subcollection"].defaultValue;
     229  text_t language = filterOptions["Language"].defaultValue;
     230  queryparamclass queryparams;
     231  queryparams.collection = collection;
     232  queryparams.search_type = (filterOptions["QueryType"].defaultValue == "ranked");
     233  queryparams.casefolding = (filterOptions["Casefold"].defaultValue == "true");
     234  queryparams.stemming = (filterOptions["Stem"].defaultValue == "true");
     235
     236  OptionValue_tarray::const_iterator options_here = request.filterOptions.begin();
     237  OptionValue_tarray::const_iterator options_end = request.filterOptions.end();
     238  while (options_here != options_end) {
     239    if ((*options_here).name == "StartResults") {
     240      startresults = (*options_here).value.getint();
     241    } else if ((*options_here).name == "EndResults") {
     242      endresults = (*options_here).value.getint();
     243    } else if ((*options_here).name == "QueryType") {
     244      queryparams.search_type = ((*options_here).value == "ranked");
     245    } else if ((*options_here).name == "Term") {
     246      queryparams.querystring = (*options_here).value;
     247    } else if ((*options_here).name == "Casefold") {
     248      queryparams.casefolding = ((*options_here).value == "true");
     249    } else if ((*options_here).name == "Stem") {
     250      queryparams.stemming = ((*options_here).value == "true");
     251    } else if ((*options_here).name == "Index") {
     252      index = (*options_here).value;
     253    } else if ((*options_here).name == "Subcollection") {
     254      subcollection = (*options_here).value;
     255    } else if ((*options_here).name == "Language") {
     256      language = (*options_here).value;
     257    } else {
     258      logout << text_t2ascii
     259         << "warning: unknown queryfilter option \""
     260         << (*options_here).name
     261         << "\" ignored.\n\n";
     262    }
     263
     264    options_here++;
     265  }
     266
     267  queryparams.search_index = index+subcollection+language;
     268  queryparams.maxdocs = (endresults > 100) ? endresults : 100;
     269
     270  // do query
     271  queryresultsclass queryresults;
     272  mgsearchptr->setcollectdir (collectdir);
     273  if (!mgsearchptr->search(queryparams, queryresults)) {
     274    // most likely a system problem
     275    logout << text_t2ascii
     276       << "system problem: could not do search with mg for index \""
     277       << queryparams.search_index << "\".\n\n";
     278    err = systemProblem;
     279    return;
     280  }
     281
     282  // assemble document results
     283  if ((request.filterResultOptions & FROID) || (request.filterResultOptions & FRranking) ||
     284      (request.filterResultOptions & FRmetadata)) {
     285    int resultnum = 1;
     286    ResultDocInfo_t resultdoc;
     287    text_t trans_OID;
     288    vector<docresultclass>::iterator docs_here = queryresults.docs.begin();
     289    vector<docresultclass>::iterator docs_end = queryresults.docs.end();
     290   
     291    while (docs_here != docs_end) {
     292      if (resultnum > endresults) break;
     293     
     294      // translate the document number
     295      if (!translate(gdbmptr, (*docs_here).docnum, trans_OID)) {
     296    logout << text_t2ascii
     297           << "warning: could not translate mg document number \""
     298           << (*docs_here).docnum << "\"to OID.\n\n";
     299   
     300      } else {
     301    // see if it is in the set (or the set is empty)
     302    if (request.docSet.empty() || in_set(request.docSet, trans_OID)) {
     303      if (resultnum >= startresults) {
     304        // add this document
     305        resultdoc.OID = trans_OID;
     306        resultdoc.ranking = (int)((*docs_here).docweight * 10000.0 + 0.5);
     307        response.docInfo.push_back (resultdoc);
     308      }
     309     
     310      resultnum++;
     311    }
     312      }
     313     
     314      docs_here++;
     315    }
     316  }
     317
     318  // assemble the term results
     319  if ((request.filterResultOptions & FRtermFreq) || (request.filterResultOptions & FRmatchTerms)) {
     320    queryresults.sortqueryterms();
     321    queryresults.uniqqueryterms();
     322
     323    TermInfo_t terminfo;
     324    bool terms_first = true;
     325    vector<termfreqclass>::iterator terms_here = queryresults.terms.begin();
     326    vector<termfreqclass>::iterator terms_end = queryresults.terms.end();
     327
     328    while (terms_here != terms_end) {
     329      terminfo.clear();
     330      terminfo.term = (*terms_here).termstr;
     331      terminfo.freq = (*terms_here).termfreq;
     332      if (terms_first) terminfo.matchTerms = queryresults.termvariants;
     333      terms_first = false;
     334
     335      response.termInfo.push_back (terminfo);
     336
     337      terms_here++;
     338    }
     339  }
     340
     341  response.numDocs = response.docInfo.size();
     342  response.isApprox = (queryresults.getnumdocs() != queryparams.maxdocs);
     343}
  • trunk/gsdl/src/colservr/queryinfo.h

    r114 r235  
    102102  vector<docresultclass> docs;
    103103  vector<termfreqclass> terms;
    104   vector<text_t> termvariants;
     104  text_tarray termvariants;
    105105
    106106  void clear ();
  • trunk/gsdl/src/recpt/Makefile

    r226 r235  
    1212CC = gcc
    1313CCFLAGS = -g -Wall -Wunused -pedantic -W -Woverloaded-virtual # -Wshadow
    14 DEFS = -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DUSE_FASTCGI -DGSDLSERVER
     14DEFS = -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DUSE_FASTCGI -DGSDLSERVER \
     15       -D_LITTLE_ENDIAN
    1516INCLUDES = -I../../lib -I../../packages/mg-1.3d -I../../packages/mg-1.3d/lib \
    1617           -I../../packages/mg-1.3d/src/text -I../../packages/fcgi/include
     
    9697
    9798install:
    98 #   cp recpt /home/nzdl/nzdl-1.2/cgi-bin/rrecpt; \
    99 #   cp library /home/nzdl/nzdl-1.2/cgi-bin/rlibrary
    100     cp $(EXEC) /home/nzdl/nzdl-1.2/cgi-bin
     99    cp recpt /home/nzdl/nzdl-1.2/cgi-bin/rrecpt; \
     100    cp library /home/nzdl/nzdl-1.2/cgi-bin/rlibrary
     101#   cp $(EXEC) /home/nzdl/nzdl-1.2/cgi-bin
    101102
    102103depend:
  • trunk/gsdl/src/recpt/librarymain.cpp

    r226 r235  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/04/12 03:45:05  rjmcnab
     15   Finished the query filter.
     16
    1417   Revision 1.3  1999/04/06 22:20:35  rjmcnab
    1518   Got browsefilter working.
     
    7073  recpt.add_protocol (&nproto);
    7174
    72   cgiwrapper (recpt, "cnrub");
     75  cgiwrapper (recpt, "gberg");
    7376  return 0;
    7477}
Note: See TracChangeset for help on using the changeset viewer.