home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 1.0 / Image.iso / toolbox / ntserver / wtsource / irext.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-15  |  17.2 KB  |  508 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer. */
  4.  
  5. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  6.  
  7.  
  8. /* Include file for the irhash.c file.
  9.    Implements the building functions in irext.h */
  10.  
  11. #ifndef IREXT_H
  12. #define IREXT_H
  13.  
  14.  
  15. /* An interface for adding new server types into the WAIS system.
  16.  * The idea is to use the parsing and bookkeeping operatios of the serial 
  17.  * indexer, while allowing different invered file and signiture systems 
  18.  * to be added as back ends.
  19.  *
  20.  * - Tracy Shen and Brewster 3/91
  21.  */
  22.  
  23. /*
  24.  * $Log: irext.h,v $
  25.  * Revision 1.1  1993/02/16  15:05:35  freewais
  26.  * Initial revision
  27.  *
  28.  * Revision 1.24  92/03/20  11:02:16  jonathan
  29.  * Added word_position boolean to add_word.  This is a new switch to allow an
  30.  * indexer to ignore the word position info (if it cares), based on
  31.  * indexer parameters.
  32.  * 
  33.  * Revision 1.23  92/03/05  07:06:12  shen
  34.  * update init_search_engine prototype to add two more parameters
  35.  * For seeker-ram, the twonew parameters are: grow percent and textsixe
  36.  * 
  37.  * Revision 1.22  92/02/29  20:11:57  jonathan
  38.  * Conditionalized definition of DF_INDEPENDENT, etc.
  39.  * 
  40.  * Revision 1.21  92/02/13  12:24:25  jonathan
  41.  * conditionalized inclusion of irparse.h on BOOL.
  42.  * 
  43.  *
  44.  * Tracy changes:
  45.  *  - in function "add_word", add two more parameters, source and date
  46.  *  - add a new function "set_query_parameter"
  47.  * proposed changes by brewster:
  48.  *  replace date_type with time_t: accepted
  49.  *  take out all "unsigned" type modifiers (tracey will concider this)
  50.  *  replace short with long: accepted
  51.  *  replace int with long (we port to 16 bit machines still): accepted
  52.  *  added source to delete_doc_id parameters: accepted
  53.  * Proposed changes by brewster and tracy:
  54.  *  if routines are successful return 0, otherwise an error code: accepted
  55.  * Proposed changes by harry:
  56.  *  make the dictionary value be any size.  This can be done by 
  57.  *   passing in a size arg or by passing in read and write routines.
  58.  *  have a function that says we will not be calling best_hit anymore.
  59.  * proposed changes by brewster:
  60.  *  took out hash_pos from add word.
  61.  *  change source to a database* db.
  62.  *  added finished_best_hit, finished_search_word(db), finished_add_word
  63.  * NOT ACCEPTED proposed by tracy (9/91)
  64.  *  create a function init_search_word and pass an array of db's
  65.  *  modify search_word dont pass db.
  66.  *  modify finish_search_word dont pass db.
  67.  *  create init_best_hit pass dbs
  68.  *  modify best_hit to pass db (to be modified)
  69.  *  modify a hit structure to contain a db
  70.  *  create se_init, se_exit (tracy will send these in)
  71.  *  create se_open_database, se_close_database (tracy will send these in)
  72.  * ACCEPTED proposed by tracy (9/91)  
  73.  *  create a function init_search_word and pass db
  74.  *  add total word count to db (not set in server side)
  75.  *  create init_best_hit 
  76.  *  change dbs slot query_parameter_type from being a "database** dbs"
  77.  *    to "char** srcs" (not done on server side yet)
  78.  *  modify best_hit to have argument doc_id, best_character, score
  79.  *  create ext_open_database, ext_close_database
  80.  *  modify init_add_word to add char* src. (not done in server side)
  81.  * proposed changes by brewster
  82.  *  modify best_hit to take both best_character and best_line
  83.  * IMPLEMENTED proposed by brewster
  84.  *  specify that search_word take a downcased word
  85.  *  create function char *database_file(char *database_name)
  86.  *    that will return the name of the file that the database is stored in.
  87.  *    on Seeker and Beta this would return "INDEX" always, 
  88.  *     and serial server this would returns its argument. 
  89.  * IMPLEMENTED proposed by brewster
  90.  *   the srcs list in set_query_parameter will be what the user
  91.  *   passed in the database fields of the Z39.50 request.
  92.  *   This means that if multiple src's are specified separate by comma's
  93.  *   then it is up to the backend to parse those out.
  94.  * IMPLEMENTED proposed by brewster
  95.  *   the src field in init_add_word will always be NULL and
  96.  *   the information will be passed via set_query_parameter.
  97.  * APPROVED proposed by brewster
  98.  *   add init_search_engine and finished_search_engine
  99.  *     this would be called when the server process starts and exists.
  100.  *     these functions could check to make sure everything is sane.
  101.  *     same arguments in ext_open_database
  102.  * proposed by brewster 
  103.  *   change scores to doubles rather than longs.  maybe weights too.
  104.  * IMPLEMENTED proposed by tracy
  105.  *   pass another argument to search_word and add_word:
  106.  *    long word_pair.
  107.  * proposed by tracy: APPROVED
  108.  *   take out src arg from init_add_word
  109.  *   change arg name in search_word from doc_id to relevant_doc_number
  110.  *   take out dictionary_value from search_word
  111.  *   New arguments to ext_open_database:
  112.  *     initialize (same)
  113.  *     for_search  (if true searches can happen, otherwise can not)
  114.  *     for_update  (if true updates can happen, otherwise can not)
  115.  * proposed change by tracy
  116.  *   add 2 more long arguments to init_search_engine and ext_open_database
  117.  *     (for seeker, the first argument should be the percentage of 
  118.  *      CM memory for signatures.  For open_database put in the total 
  119.  *       raw text size).
  120.  *     
  121.  */
  122.  
  123. #include "cdialect.h"
  124. #include "irfiles.h" /* for database */
  125.  
  126. #ifdef BOOL
  127. #include "irparse.h" /* for boolean searches */
  128. #endif
  129.  
  130. #ifdef __cplusplus
  131. /* declare these as C style functions */
  132. extern "C"
  133.     {
  134. #endif /* def __cplusplus */
  135.  
  136. /* ============================
  137.  * ===  Control Functions  ===
  138.  * ============================*/
  139.  
  140. /*
  141.  * SE_init - Search Engine initialization function
  142.  *
  143.  * Parameter description:
  144.  *   if_update - if update is to be performed in this run, value
  145.  *               be True (1L) or False(0L).
  146.  *   if_query  - if query is to be performed in this run, value
  147.  *               be True (1L) or False (0L).
  148.  *
  149.  * Functional description:
  150.  *   This function should be the first function call FE(front end)
  151.  *   make to the BE(back end) SE(search engine).
  152.  *   It gives the SE a chance to initialize its global variables
  153.  *   to best serve FE's requests efficiently.
  154.  *   It only needs to * be called once each run. Sebsequent calls
  155.  *   will be ignored.
  156.  *   For a batch update ( eg, waisindex run),
  157.  *   parameters if_update should be set to True, and if_quesry be False.
  158.  *   For serving query (eg, a waisserver run), the if_query will be True.
  159.  *   To allow on-line update while serving query, if_update should be
  160.  *   set to True, otherwise be False.
  161.  *   The waisserver has to be able to take on-line update request and
  162.  *   update the search engine's database.
  163.  *
  164.  */
  165.  
  166. long SE_init _AP(( long if_update, long if_query));
  167.  
  168. /*
  169.  * SE_exit - Search Engine exit function
  170.  *
  171.  * Parameter description:
  172.  *   None
  173.  *
  174.  * Functional description:
  175.  *   This function should be the last function call FE(front end)
  176.  *   makes to SE. It gives the SE a chance to flush data kept in
  177.  *   buffers, clean up temporary files,  and free up resourecs.
  178.  */
  179.  
  180. long SE_exit _AP(( void));
  181.  
  182.  
  183.  
  184. long SE_open_database _AP (( database *db,
  185.                        long if_initialize,
  186.                        long if_update,
  187.                        long if_query,
  188.                        long *parameter1,
  189.                        long *parameter2));
  190. /*
  191.  * SE_open_database - open a database
  192.  *
  193.  * Parameter description:
  194.  *   db - pointer to a database structure. The structure should
  195.  *               contain a field "SE_private_tag" of type void *.
  196.  *               The SE will fill in this field when the
  197.  *               database is open. This is the search enginer's pointer
  198.  *               to its data structure of the database.
  199.  *   if_initialize - if initialize this databse. If value is
  200.  *               True, the database will be set empty. If
  201.  *               one already exists, it will be purged
  202.  *               or marked old  according to the system maintenance
  203.  *               policy employed.
  204.  *   if_update - if update is to be performed on this database, value
  205.  *               be True (1L) or False(0L).
  206.  *   parameter1 and parameter2 - these are additional info the
  207.  *               SE needs from the FE. They are pointers. If
  208.  *               a SE does not need extra info, FE will just pass
  209.  *               NULL.
  210.  *               For new seeker, parameter1 is the databases max size
  211.  *               in percentage to the full-system-load.
  212.  *               CM memory is a limited resource to be shared by
  213.  *               multiple databases, and is not efficient
  214.  *               in dynamic re-allocation.
  215.  *               Seeker requires the FE to tell it the maximum size the
  216.  *               database can grow to thus it can pre-allocate the
  217.  *               right amount of processors to the databse and will
  218.  *               wrap around when it reachs the limit to squeeze out
  219.  *               old data.
  220.  *               The It is specified as the
  221.  *               percentage of the full-load CM signature pool.
  222.  *               For example, on a 8K CM with small memory, it can
  223.  *               holds up to 200 megabytes raw text size data.
  224.  *               If parameter
  225.  *        
  226.  */
  227.  
  228. long SE_close_database _AP (( database *db));
  229.  
  230. long SE_checkpointing _AP(( database *db));
  231.  
  232.  
  233.  
  234.  
  235. /* this is called when the server or indexer is started up 
  236.  *   before any other operations are run.  
  237.  *
  238.  * If this is a server starting, then file is the directory of the index.
  239.  * If this is an indexer starting, then file is the index file.
  240.  * NOTE - This routine may be called more than once
  241.  *
  242.  *   return values: 0 if successful, non-0 if error
  243.  *       defined error conditions:
  244.  *
  245.  *          -1 insufficient resources
  246.  */
  247.  
  248. long init_search_engine _AP((char* file, 
  249.                  boolean initialize, 
  250.                  boolean for_search,
  251.                  long cm_mem_percent,
  252.                  long rawtext_size,
  253.                  long grow_percent));
  254.  
  255.  
  256. /* this is called when the server is shut down.
  257.  *
  258.  *   return values: 0 if successful, non-0 if error
  259.  *       defined error conditions:
  260.  */
  261.  
  262. long finished_search_engine _AP((void));
  263.  
  264.  
  265. /*
  266.  *  ext_open_database: This function will be called on a database before
  267.  *      any operations are done on it.  It might be called multiple times 
  268.  *    with the same database before a close is done.
  269.  *    initialize: means that the database should be cleared of all state 
  270.  *          since it will be rebuilt from scratch.
  271.  *    for_search: means that the database will only be used for searching.
  272.  *        if this is false, then it can be searched and added to.
  273.  *   return values: 0 if successful, non-0 if error
  274.  *       defined error conditions:
  275.  *
  276.  *
  277.  */
  278.  
  279. long ext_open_database _AP((database *db, 
  280.                 boolean initialize, 
  281.                 boolean for_search));
  282.  
  283. /*
  284.  *  ext_close_database: This function will be called after all operations 
  285.  *    on this database are done.
  286.  *   return values: 0 if successful, non-0 if error
  287.  *       defined error conditions:
  288.  *
  289.  */
  290.  
  291. long ext_close_database _AP((database *db));
  292.  
  293. char *database_file _AP((char *database_name));
  294.  
  295. /* ============================
  296.  * ===  Building Functions  ===
  297.  * ============================*/
  298.  
  299. /* init_add_word add_word... finished_search_word 
  300.  *  is the sequence for creating an update.  When a finished_add_word is done,
  301.  *  then the it is safe (and expected) that the builder will flush things to files.
  302.  *  set query parameter can be called at any time between documents during an add.
  303.  */
  304.  
  305. /*
  306.  *  init_add_word: called before any calls to add_word.  finished_add_word
  307.  *       will be called before another init_add_word is called.
  308.  *    db is the one that will be added to.
  309.  *     parameter1 and parameter2 are implementation specific.
  310.  *   return values: 0 if successful, non-0 if error
  311.  *       defined error conditions:
  312.  * 
  313.  */
  314. long init_add_word _AP ((database *db, 
  315.              long parameter1, long parameter2));
  316.  
  317. /*
  318.  *  add_word: add this word to the database
  319.  *   return values: 0 if successful, non-0 if error
  320.  *       defined error conditions:
  321.  *
  322.  */
  323. long add_word _AP((
  324.            char *word,    /* the word to be indexed, this could be a
  325.                    word pair. If NULL there are no more words
  326.                    to be indexed */
  327.            long char_pos, /* the position of the start of the
  328.                      word */
  329.            long line_pos, /* this is passed for the best
  330.                      section calculation */
  331.            long weight,    /* how important the word looks
  332.                    syntactically (such as is it bold)
  333.                    NOT used by signature system */
  334.            long doc_id,    /* current document, this will never be 0 */
  335.            time_t date, /* display day of this document, 0 if not known */
  336.            long word_pair, /* 1 if it is, 0 if not */
  337.            database* db, /* database to insert the document */
  338.            boolean word_position /* whether the position is valid or not */
  339.            ));
  340.  
  341. /*
  342.  *  finished_add_word: states that there are no more words to add
  343.  *   to this database.
  344.  *
  345.  *   return values: 0 if successful, non-0 if error
  346.  *       defined error conditions:
  347.  *
  348.  */
  349.  
  350. long finished_add_word _AP((database *db));
  351.  
  352. /* ===============================
  353.  * ===  Maintenance Functions  ===
  354.  * ===============================*/
  355.  
  356. /*
  357.  *  delete_doc_id : delete a document
  358.  *   return values:  0, successfull
  359.  *                  -1, document not found
  360.  *
  361.  */
  362. long delete_doc_id _AP((long doc_id, database *db));
  363.  
  364. /* =============================
  365.  * ===  Searching Functions  ===
  366.  * =============================*/
  367.  
  368.  
  369. /*
  370.  *  set_query_parameter : set query parameter
  371.  *      set search attributes such as date factor, document source ids,
  372.  *      and maximum number of documents returned in a search ( the last
  373.  *      one is an important performance factor to signature  type system)
  374.  *      The search artributes applies to all comming queries until
  375.  *      they are re-set by next set_query_parameter call.
  376.  *
  377.  *   return values:  none
  378.  *
  379.  */
  380. #define SET_MAX_RETRIEVED_MASK 1
  381. #define SET_DATE_FACTOR_MASK   2
  382. #define SET_SELECT_SOURCE      4
  383.  
  384. /* enum literals for date_factor */
  385. #ifndef DF_INDEPENDENT
  386. #define DF_INDEPENDENT          1
  387. #define DF_LATER                2
  388. #define DF_EARLIER              3
  389. #endif
  390.  
  391. typedef struct {
  392.   long max_hit_retrieved;
  393.   /* max number of hits can be returned by
  394.    * the search engine. For a signature
  395.    * type system, the default value is 20
  396.    */
  397.   long date_factor;        /* default is DF_INDEPENDENT */
  398.   long num_db;            /* value of zero indicating select all,
  399.                  * default is selecting all
  400.                  */
  401.   char **srcs;            /* string of sources to be searched */
  402. }  query_parameter_type;
  403.  
  404. /*
  405.  *  set_query_parameter: set a mode variable for the search engine
  406.  *   return values: 0 if successful, non-0 if error
  407.  *       defined error conditions:
  408.  *
  409.  */
  410.  
  411. long set_query_parameter _AP ((
  412.              long mask,
  413.              query_parameter_type *parameters
  414.              /* fields in the query parameter structure are only
  415.               * interpreted when the corresponding mask bit 
  416.               * is set in the mask argument.
  417.               */
  418.              ));
  419.  
  420.  
  421.  
  422. /*
  423.  *  init_search_word: called before any search_word is called in this query.
  424.  *     The only operations that occur after this is search_word.
  425.  *   return values: 0 if successful, non-0 if error
  426.  *       defined error conditions:
  427.  *
  428.  */
  429.  
  430. long init_search_word _AP((database* db));
  431.  
  432. /*
  433.  *  search_word: searches for a word in the index.  it side effects 
  434.  *               internal state so that best_hit will return the correct 
  435.  *               results.
  436.  *   return values: 0 if successful, non-0 if error
  437.  *       defined error conditions:
  438.  *
  439.  */
  440.  
  441. long search_word 
  442.   _AP ((char *word, /* the word to be searched for */
  443.     long char_pos,        /* the position of the start of the word */
  444.     long line_pos,        /* is this needed? not for signature system */
  445.     long weight,        /* how important the word looks syntactically,
  446.                    such as is it bold */
  447.     long relevant_doc_number,/* current document, seed words is 0,
  448.                    then it increments into the relevant 
  449.                    document */
  450.     long word_pair, /* 1 if it is, 0 if not */
  451.     database *db
  452.     ));
  453.  
  454.  
  455. /*
  456.  *  finished_search_word: states that there are no more words that will
  457.  *   be searched for before best_hit will be called.
  458.  *
  459.  *   return values: 0 if successful, non-0 if error
  460.  *       defined error conditions:
  461.  *
  462.  */
  463.  
  464. long finished_search_word _AP((database *db));
  465.  
  466.  
  467.  
  468. /*
  469.  *  init_best_hit: called before any best_hit is called in this query.
  470.  *     The only operations that occur after this is best_hit.
  471.  *   return values: 0 if successful, non-0 if error
  472.  *       defined error conditions:
  473.  *
  474.  */
  475.  
  476. long init_best_hit _AP((database *db));
  477.  
  478. /*
  479.  *  best-hit :
  480.  *
  481.  *   return values:  0, successfull
  482.  *                  -1, no more documents to return
  483.  *            Other values returned to signal future signals.
  484.  *
  485.  */
  486. long best_hit _AP ((database* db,long *doc_id, long *best_character, 
  487.             long *best_line, double *score, long *start,
  488.          long *end,long *date,long *length,long *nlines,
  489.          char *headline,char *filename,char *type));
  490.  
  491.  
  492. /*
  493.  *  finished_best_hit: states that there are no more best_hits will be called
  494.  *   before the next set of search_words or add_words.
  495.  *
  496.  *   return values: 0 if successful, non-0 if error
  497.  *       defined error conditions:
  498.  *
  499.  */
  500.  
  501. long finished_best_hit _AP((database* db));
  502.  
  503. #ifdef __cplusplus
  504.     }
  505. #endif /* def __cplusplus */
  506.  
  507. #endif /* ndef IREXT_H */
  508.