home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / irfiles.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-14  |  9.3 KB  |  292 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4.  
  5.    Brewster@think.com
  6.  *
  7.  * $Log: irfiles.h,v $
  8.  * Revision 1.2  1993/06/01  14:05:54  pfeifer
  9.  * Added code for soundex/phonix indexing and retrieval
  10.  *
  11.  * Revision 1.1  1993/02/16  15:05:35  freewais
  12.  * Initial revision
  13.  *
  14.  * Revision 1.19  92/04/16  20:04:44  morris
  15.  * small fix to dictionary_blockword_occurances, lenght read was
  16.  * NEXT_INDEX_BLOCK_SIZE, now its NUMBR_OF_OCCURANCES_SIZE.
  17.  * 
  18.  * Revision 1.18  92/03/19  09:34:08  morris
  19.  * fixed the dictionary header to accurately indicate the number of blocks
  20.  * 
  21.  * Revision 1.17  92/02/17  12:38:00  jonathan
  22.  * Added defines for catalog.
  23.  * 
  24.  */
  25.  
  26. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  27.  
  28.  
  29. /* include file for irfiles.c */
  30.  
  31. #ifndef IRFILES_H
  32. #define IRFILES_H
  33.  
  34. #include "cdialect.h"
  35. #include "cutil.h"
  36. #include "hash.h"
  37. #include "ustubs.h" /* for time_t */
  38. #include "synonym.h"
  39.  
  40. /* filename extensions for various components */
  41. #define dictionary_ext            ".dct"
  42. #define filename_table_ext        ".fn"
  43. #define headline_table_ext        ".hl"
  44. #define document_table_ext        ".doc"
  45. #define index_ext            ".inv"
  46. #define source_ext             ".src"
  47. #define catalog_ext             ".cat"
  48. #define synonym_ext            ".syn"
  49. #ifdef BIO
  50. #define delimiters_ext    ".dlm"        /* dgg */
  51. #endif
  52.  
  53. /* these dictionary definitions are used in irhash,irverify, and irfiles */
  54. #define DICTIONARY_HEADER_SIZE 4
  55. #define DICTIONARY_BLOCK_SIZE 1000L  /* in entries, not bytes */
  56. #define DICTIONARY_ENTRY_HASH_CODE_SIZE 2
  57. /* #define DICTIONARY_ENTRY_COUNT_SIZE 3  moved to inverted file */
  58. /* #define DICTIONARY_ENTRY_INDEX_BLOCK_SIZE 4 not used and too long a symbol*/
  59. /* #define DICTIONARY_ELEMENT_SIZE 6 was 9 */
  60. #define DICTIONARY_SIZE 524288L
  61. #define DICTIONARY_TOTAL_SIZE_WORD "{}" /* the word that holds the total number of words in the whole dictionary */
  62.  
  63. #define INDEX_HEADER_SIZE 4
  64. #ifdef BIO
  65.  
  66. /* !! Bug in W8B5 -- Increasing this INDEX_BLOCK_SIZE_SIZE above 2 now fails !! */
  67. /* it worked in W8B3 ... both 3 and 4 fail now */
  68. #define INDEX_BLOCK_SIZE_SIZE 2  /* was 2, genbank wants 3, dgg */
  69.  
  70. #else
  71. #define INDEX_BLOCK_SIZE_SIZE 2
  72. #endif
  73.  
  74. #define NEXT_INDEX_BLOCK_SIZE 4
  75. #define INDEX_BLOCK_FLAG_SIZE 1
  76.  
  77. /* dgg -- this is a bug 
  78. #define INDEX_BLOCK_HEADER_SIZE 7
  79. This == 7 only if the component SIZEs don't change
  80. */
  81. #define INDEX_BLOCK_HEADER_SIZE (INDEX_BLOCK_SIZE_SIZE+NEXT_INDEX_BLOCK_SIZE+INDEX_BLOCK_FLAG_SIZE)
  82.  
  83.  
  84. #define NUMBER_OF_OCCURANCES_SIZE 4
  85. #define INDEX_BLOCK_NOT_FULL_FLAG 101
  86. #define INDEX_BLOCK_FULL_FLAG 69
  87. #define INDEX_BLOCK_DICTIONARY_FLAG 123
  88.  
  89. #define DOCUMENT_ID_SIZE 4
  90. #define WORD_POSITION_SIZE 0
  91. #define CHARACTER_POSITION_SIZE 3
  92. #define WEIGHT_SIZE 1
  93. #define INDEX_ELEMENT_SIZE 8
  94. #define WORD_ID_SIZE 4 /* for posting arrays */
  95.  
  96. #ifdef BOOLEANS            /* dgg */
  97. #define BOOLEAN_AND    "and"    /* may prefer "&", but need symbol fix */
  98. #define BOOLEAN_NOT "not"    /* may prefer "!", but need symbol fix */
  99. #define BOOLEAN_NOT_FLAG -91    /* stick in weight param as flag for search_word */
  100. #endif
  101.  
  102. #ifdef PARTIALWORD        /* dgg */
  103. #define PARTWORD_WILDCARD  '*'        
  104. #endif
  105.  
  106. #ifdef LITERAL            /* dgg */
  107. #define LITERAL_KEY1    '"'    
  108. #define LITERAL_KEY2    0x27    /* single quote ' dgg */
  109. #define LITERAL_FLAG    -92    /* stick in weight param as flag for search_word */
  110. #define MAX_PHRASE_LENGTH  200
  111. #endif
  112.  
  113. #ifdef SOUND
  114. #define SOUNDEX "soundex"
  115. #define PHONIX  "phonix"
  116. #endif
  117.  
  118. typedef struct database {
  119.     char*    database_file;
  120.     FILE*    dictionary_stream;
  121.     FILE*    filename_table_stream;
  122.     FILE*    headline_table_stream;
  123.     FILE*    document_table_stream;
  124.     FILE*    index_stream;
  125. #ifdef BIO
  126.     FILE*    delimiters_stream;
  127. #endif
  128.   long    doc_table_allocated_entries;
  129.     hashtable* the_word_memory_hashtable;
  130.  
  131.     long     number_of_words_in_hashtable; /* for building.
  132.                          checked on every add_word.
  133.                            set at start of building,
  134.                            and on every flush.*/
  135.     long     flush_after_n_words; /* set at the start of building used
  136.                     to compare with 
  137.                     number_of_words_in_hashtable. */
  138.     long     number_of_words; /* for building.  number of different words.
  139.                     Set from the headers of .inv files
  140.                     as they are merged. 
  141.                     It is used to set the header when a .inv 
  142.                     file is first created (not by merging).
  143.                     */
  144.     long    index_file_number; /* for building. */
  145.     long    total_word_count; /* Total number of word occurances.
  146.                      set during indexing, saved in 
  147.                      dictionary under 'ALL' entry */
  148.     void*   ext_database;
  149.  t_Synonym* syn_Table;       /* synonym index lookup table */
  150.         int     syn_Table_Size;     /* number of entries in synonym table */
  151. } database;
  152.  
  153. typedef struct document_table_entry {
  154.     long    filename_id;
  155.     long    headline_id;
  156.     long    source_id;    /* for signature system */
  157.     long    start_character;
  158.     long    end_character;
  159.     long     document_length; /* in characters */
  160.     long    number_of_lines; /* in lines */
  161.     time_t  date;            /* 0 if unknown */
  162. } document_table_entry;
  163.  
  164. #ifdef __cplusplus
  165. /* declare these as C style functions */
  166. extern "C"
  167.     {
  168. #endif /* def __cplusplus */
  169.  
  170. database*     openDatabase _AP((char* name, boolean initialize,boolean for_search));
  171. void        closeDatabase _AP((database* the_db));
  172. void        disposeDatabase _AP((database* the_db));
  173.  
  174. void initialize_index_files _AP((database* db));
  175.  
  176. char *read_filename_table_entry _AP((long position, 
  177.                   char* filename,
  178.                   char* type, 
  179.                   time_t* file_write_date,
  180.                   database* db));
  181.  
  182. long write_filename_table_entry _AP((char* filename, char *type, database* db));
  183. boolean filename_in_database _AP((char *filename, char *type,
  184.                   time_t *write_file_date, database *db));
  185. boolean filename_in_filename_file _AP ((char *filename, char*type,
  186.                   time_t *file_write_date, 
  187.                   char* filename_file));
  188. char *read_headline_table_entry _AP((long position,database* db));
  189. long write_headline_table_entry _AP((char* headline, database* db));
  190.  
  191. #ifdef BIO
  192. char *read_delimiters _AP((database* db));
  193. long write_delimiters _AP((char* delimiters, database* db));
  194. #endif
  195.  
  196. boolean read_document_table_entry 
  197.   _AP((document_table_entry* doc_entry,long number,database* db));
  198.  
  199. long write_document_table_entry
  200.   _AP((document_table_entry* doc_table_entry, database* db));
  201.  
  202. boolean writeUserValToDocIDTable _AP((unsigned long userVal,long doc,
  203.                       database* db));
  204.  
  205.  
  206. long next_document_id _AP((database* db));
  207.  
  208.  
  209. void close_dictionary_file _AP((database *db));
  210.  
  211. long add_word_to_dictionary
  212.      _AP((char *word, long index_file_block_number, long number_of_occurances,
  213.      database* db));
  214. #ifdef PARTIALWORD
  215. long look_up_partialword_in_dictionary _AP((char *word, long *word_id, database* db));
  216. #endif
  217. long look_up_word_in_dictionary _AP((char *word, long *word_id, database* db));
  218. long init_dict_file_for_writing _AP((database *db));
  219. void init_dict_file_detailed _AP((FILE* dictionary_stream,
  220.                   long number_of_blocks));
  221. void record_num_blocks_in_dict _AP((FILE* dictionary_stream,
  222.                     long number_of_words));
  223.  
  224. long finished_add_word_to_dictionary _AP((database *db));
  225.  
  226. boolean register_src_structure _AP((char *filename));
  227. boolean write_src_structure _AP((char *filename, 
  228.                  char *database_name, 
  229.                  char *typename,
  230.                  char **filenames, 
  231.                  long number_of_filename,
  232.                  boolean export_database,
  233.                  long tcp_port));
  234.  
  235. boolean build_catalog _AP((database* db));
  236.  
  237. long allocate_index_block _AP((long how_large, FILE* stream));
  238.  
  239. unsigned char *read_dictionary_block _AP((unsigned char* block,
  240.                       long position,long length,
  241.                       FILE* stream));
  242.                                       
  243. void print_dictionary _AP((database* db));
  244.  
  245. #define DICTIONARY_ENTRY_SIZE 29 /* sum of MAX_WORD_LENGTH, 1 ('\0'), 
  246.                     NEXT_INDEX_BLOCK_SIZE and
  247.                     NUMBER_OF_OCCURANCES_SIZE */
  248.  
  249.  
  250. #ifdef DICT_FUNC
  251.  
  252. char *dictionary_block_word _AP((long i,unsigned char* block));
  253. long dictionary_block_position _AP((long i,unsigned char* block));
  254. long dictionary_block_word_occurances _AP((long i,unsigned char* block));
  255.  
  256. #else /* macros */
  257.  
  258. #define dictionary_block_word(i,block) \
  259.   ((char *)((block) + ((i) * DICTIONARY_ENTRY_SIZE)))
  260.  
  261. #define dictionary_block_position(i,block) \
  262.   read_bytes_from_memory(NEXT_INDEX_BLOCK_SIZE, \
  263.              (block) + ((i) * DICTIONARY_ENTRY_SIZE) + \
  264.               MAX_WORD_LENGTH + 1)
  265.  
  266. #define dictionary_block_word_occurances(i,block) \
  267.   read_bytes_from_memory(NUMBER_OF_OCCURANCES_SIZE, \
  268.                          (block) + ((i) * DICTIONARY_ENTRY_SIZE) + \
  269.                          MAX_WORD_LENGTH + 1 + NEXT_INDEX_BLOCK_SIZE)
  270. #endif
  271.  
  272. void print_dictionary_block _AP((unsigned char* block,long size));
  273.  
  274. /* database functions */
  275. char* dictionary_filename _AP((char* destination, database* db));
  276. char* filename_table_filename _AP((char* destination, database* db));
  277. char* headline_table_filename _AP((char* destination, database* db));
  278. char* document_table_filename _AP((char* destination, database* db));
  279. char* index_filename _AP((char* destination, database* db));
  280. char* index_filename_with_version _AP((long version, char* destination, 
  281.                   database* db));
  282. char* source_filename _AP((char* destination, database* db));
  283. #ifdef BIO
  284. char* delimiters_filename _AP((char* destination, database* db));
  285. #endif
  286.  
  287. #ifdef __cplusplus
  288.     }
  289. #endif /* def __cplusplus */
  290.  
  291. #endif /* IRFILES_H */
  292.