Ignore:
Timestamp:
2010-05-06T12:58:19+12:00 (11 years ago)
Author:
davidb
Message:

Updating of code to support sql-query filter

Location:
main/trunk/greenstone2/runtime-src/src/colservr
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/colservr/Makefile.in

    r21472 r22050  
    158158    search.cpp \
    159159    source.cpp \
    160     sqlbrowsefilter.cpp
     160    sqlbrowsefilter.cpp \
     161    sqlqueryfilter.cpp \
     162    sqlfilter.cpp
    161163
    162164OBJECTS = \
     
    179181    search.o \
    180182    source.o \
    181     sqlbrowsefilter.o
     183    sqlbrowsefilter.o \
     184    sqlqueryfilter.o \
     185    sqlfilter.o
    182186
    183187LIBRARY = gsdlcolservr.a
  • main/trunk/greenstone2/runtime-src/src/colservr/collectserver.cpp

    r21324 r22050  
    5252  else {
    5353    cerr << "Error: buildtype '" << buildtype << "' is not a recognized indexer for Greenstone." << endl;
     54  }
     55
     56}
     57
     58
     59void check_if_valid_infodbtype(const text_t& infodbtype)
     60{
     61  if (infodbtype=="gdbm") {
     62#ifndef USE_GDBM
     63    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'gdbm'." << endl;
     64#endif
     65  }
     66  else if (infodbtype=="gdbm-txtgz") {
     67#ifndef USE_GDBM
     68    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'gdbm-txtgz'." << endl;
     69#endif
     70  }
     71  else if (infodbtype=="jdbm") {
     72#ifndef USE_JDBM
     73    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'jdbm'." << endl;
     74#endif
     75  }
     76  else if (infodbtype=="sqlite") {
     77#ifndef USE_SQLITE
     78    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'sqlite'." << endl;
     79#endif
     80  }
     81  else if (infodbtype=="mssql") {
     82#ifndef USE_MSSQL
     83    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'mssql'." << endl;
     84#endif
     85  }
     86
     87  else {
     88    cerr << "Error: infodbtype '" << infodbtype << "' is not a recognized database type for Greenstone." << endl;
    5489  }
    5590
     
    242277      //collectinfo.searchTypes = cfgline;
    243278    }
     279    else if (key == "infodbtype") {
     280      check_if_valid_infodbtype(value); // prints warning if value (database type) is invalid
     281      collectinfo.infodbType = value;
     282    }
    244283    else if (key == "separate_cjk") {
    245284      if (value == "true") collectinfo.isSegmented = true;
  • main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp

    r21472 r22050  
    3434#include "browsefilter.h"
    3535#include "sqlbrowsefilter.h"
     36#include "sqlqueryfilter.h"
    3637#include "queryfilter.h"
    3738
     
    335336    dbclass *db_ptr = NULL;
    336337
    337 #ifdef USE_SQLITE
    338338    if (infodbtype == "sqlite")
    339339      {
     340#ifdef USE_SQLITE
    340341    sqlitedbclass *sql_db_ptr = new sqlitedbclass();
    341342    db_ptr = sql_db_ptr;
     
    345346    sqlbrowsefilter->set_sql_db_ptr(sql_db_ptr);
    346347    cserver->add_filter (sqlbrowsefilter); 
    347       }
    348 #endif
     348
     349    // add a sql query filter
     350    sqlqueryfilterclass *sqlqueryfilter = new sqlqueryfilterclass();
     351    sqlqueryfilter->set_sql_db_ptr(sql_db_ptr);
     352    cserver->add_filter (sqlqueryfilter); 
     353
     354#else
     355    cerr << "Warning: infodbtype of 'sqlite' was not compiled in to " << endl;
     356    cerr << "         this installation of Greenstone";
     357#endif
     358      }
    349359 
    350 #ifdef USE_MSSQL
    351360    if (infodbtype == "mssql")
    352361      {
     362#ifdef USE_MSSQL
    353363    mssqldbclass *mssql_db_ptr = new mssqldbclass();
    354364    db_ptr = mssql_db_ptr;
     
    358368    sqlbrowsefilter->set_sql_db_ptr(mssql_db_ptr);
    359369    cserver->add_filter (sqlbrowsefilter); 
    360       }
    361 #endif
     370#else
     371    cerr << "Warning: infodbtype of 'mssql' was not compiled in to " << endl;
     372    cerr << "         this installation of Greenstone";
     373#endif
     374      }
     375
     376    if (infodbtype == "jdbm") {
    362377
    363378#ifdef USE_JDBM
    364     if (infodbtype == "jdbm") {
    365 
    366379    jdbmnaiveclass *jdbm_db_ptr = new jdbmnaiveclass(gsdlhome);
    367380    db_ptr = jdbm_db_ptr;
    368     }
    369 #endif
     381#else
     382    cerr << "Warning: infodbtype of 'jdbm' was not compiled in to " << endl;
     383    cerr << "         this installation of Greenstone";
     384#endif
     385    }
    370386
    371387    // Use GDBM if the infodb type is empty or not one of the values above
     
    373389#ifdef USE_GDBM
    374390      db_ptr = new gdbmclass();
     391#else
     392    cerr << "Warning: infodbtype of 'gdbm' was not compiled in to " << endl;
     393    cerr << "         this installation of Greenstone";
    375394#endif
    376395    }
  • main/trunk/greenstone2/runtime-src/src/colservr/comtypes.h

    r15802 r22050  
    106106  text_t         receptionist;
    107107  text_t         buildType;           // 'mg' or 'mgpp' or 'lucene'
    108   text_t         authenticate;      // 'document' or 'collection'
     108  text_t         infodbType;          // 'gdbm', 'sqlite', etc.
     109  text_t         authenticate;        // 'document' or 'collection'
    109110  text_t         auth_group;          // 'mygroup' 'yourgroup'
    110111  text_tmap      public_documents;    // the acl to allow access to listed documents
  • main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp

    r20727 r22050  
    265265              endresults, phrasematch, logout); 
    266266
    267     vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
     267  vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
    268268   
    269269  // do query
  • main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.cpp

    r16310 r22050  
    33 * sqlbrowsefilter.cpp --
    44 * Copyright (C) 2008  DL Consulting Ltd
     5 * Copyright (C) 2010  New Zealand Digital Library Project
    56 *
    67 * A component of the Greenstone digital library software
     
    2526
    2627#include "sqlbrowsefilter.h"
    27 #include "fileutil.h"
    28 
    2928
    3029sqlbrowsefilterclass::sqlbrowsefilterclass ()
    31 {
    32   sql_db_ptr = NULL;
    33 }
     30  : sqlfilterclass()
     31{}
    3432
    3533
    3634sqlbrowsefilterclass::~sqlbrowsefilterclass ()
    37 {
    38 }
    39 
    40 
    41 void sqlbrowsefilterclass::configure (const text_t &key, const text_tarray &cfgline)
    42 {
    43   filterclass::configure (key, cfgline);
    44 
    45   if (key == "indexstem")
    46   {
    47     indexstem = cfgline[0];
    48   }
    49 }
    50 
    51 
    52 bool sqlbrowsefilterclass::init (ostream &logout)
    53 {
    54   outconvertclass text_t2ascii;
    55 
    56   if (!filterclass::init(logout)) return false;
    57 
    58   if (sql_db_ptr == NULL)
    59   {
    60     // most likely a configuration problem
    61     logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
    62     return false;
    63   }
    64 
    65   if (indexstem.empty())
    66   {
    67     indexstem = collection;
    68   }
    69 
    70   // get the filename for the database and make sure it exists
    71   sql_db_filename = resolve_db_filename(indexstem,sql_db_ptr->getfileextension());
    72   if (!file_exists(sql_db_filename))
    73   {
    74     logout << text_t2ascii << "warning: database \"" << sql_db_filename << "\" does not exist\n\n";
    75     return false;
    76   }
    77 
    78   return true;
    79 }
    80 
     35{}
    8136
    8237void sqlbrowsefilterclass::filter (const FilterRequest_t &request,
     
    8641  outconvertclass text_t2ascii;
    8742
    88   response.clear();
    89   err = noError;
    90 
    91   if (sql_db_ptr == NULL) {
    92     // most likely a configuration problem
    93     logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
    94     err = configurationError;
    95     return;
    96   }
    97 
    98   // open the database
    99   sql_db_ptr->setlogout (&logout);
    100   if (!sql_db_ptr->opendatabase (sql_db_filename, DB_READER, 100, false)) {
    101     // most likely a system problem (we have already checked that the database exists)
    102     logout << text_t2ascii << "system problem: open on database \"" << sql_db_filename << "\" failed\n\n";
    103     err = systemProblem;
     43  if (!connect_to_sqldb(response,err,logout)) {
    10444    return;
    10545  }
     
    201141  }
    202142
    203   sql_db_ptr->closedatabase();  // Important that local library doesn't leave any files open
     143  disconnect_from_sqldb();
     144
    204145}
  • main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.h

    r15757 r22050  
    33 * sqlbrowsefilter.h --
    44 * Copyright (C) 2008  DL Consulting Ltd
     5 * Copyright (C) 2010  New Zealand Digital Library Project
    56 *
    67 * A component of the Greenstone digital library software
     
    2728#define SQLBROWSEFILTER_H
    2829
    29 
    30 #include "filter.h"
    31 #include "comtypes.h"
    32 #include "sqldbclass.h"
    33 #include "text_t.h"
     30#include "sqlfilter.h"
    3431
    3532
    36 class sqlbrowsefilterclass : public filterclass {
    37 protected:
    38   text_t sql_db_filename;
    39   text_t indexstem;
    40   sqldbclass *sql_db_ptr;
    41 
    42 public:
     33class sqlbrowsefilterclass : public sqlfilterclass
     34{
     35 public:
    4336  sqlbrowsefilterclass ();
    4437  virtual ~sqlbrowsefilterclass ();
    45 
     38 
    4639  text_t get_filter_name () { return "SQLBrowseFilter"; }
    47 
    48   // configure should be called once for each configuration line
    49   // default configures the default filter options
    50   virtual void configure (const text_t &key, const text_tarray &cfgline);
    51 
    52   // the sql db ptr remains the responsibility of the calling code and
    53   // should be destroyed after this sqlbrowsefilter is destroyed
    54   void set_sql_db_ptr (sqldbclass *sql_db_ptr_arg) { sql_db_ptr = sql_db_ptr_arg; }
    55 
    56   bool init (ostream &logout);
     40 
    5741  void filter (const FilterRequest_t &request,
    5842           FilterResponse_t &response,
Note: See TracChangeset for help on using the changeset viewer.