Changeset 308 for trunk/gsdl/src


Ignore:
Timestamp:
1999-06-28T20:56:29+12:00 (25 years ago)
Author:
rjmcnab
Message:

A bit of hacking to remove the restriction that the index to get
a document must be a level 2 index. Now both level 2 and level 3
indexes can be used to get the text of a document.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/colservr/mgq.c

    r115 r308  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/06/28 08:56:29  rjmcnab
     15   A bit of hacking to remove the restriction that the index to get
     16   a document must be a level 2 index. Now both level 2 and level 3
     17   indexes can be used to get the text of a document.
     18
    1419   Revision 1.3  1999/01/19 01:38:16  rjmcnab
     20
    1521   Made the source more portable.
    1622
     
    120126  return 0;
    121127}
     128
     129static int GetParaNumFromDocNum(query_data *qd, int docnum) {
     130  int Documents = qd->td->cth.num_of_docs;
     131  int *Paragraph = qd->paragraph;
     132
     133  if (docnum > 0 && docnum <= Documents)
     134    return Paragraph[docnum-1]+1;
     135  return 0;
     136}
    122137#endif
    123138
     
    133148static int ProcessDocs (query_data * qd, int skip, int howmany,
    134149            enum result_kinds kind,
    135             int (*sender)(char *,int,int,float,void *), void *ptr)
    136 {
     150            int (*sender)(char *,int,int,float,void *), void *ptr) {
    137151  int max_buf = 0, output_failure = 0;
    138152  int DocCount = 0;
    139153  int need_text = (kind == result_docs);
    140  
    141   for (;;) {
    142     if (skip <= 0) break;
     154
     155  /* skip the requested number of documents */
     156  while (skip > 0) {
     157    if (!NextDoc(qd)) return 0;
    143158    skip--;
    144     if (!NextDoc(qd)) return 0;
    145   }
    146  
    147   if (need_text)
    148     {
    149       max_buf = atoi (GetDefEnv ("buffer", "1048576"));
    150     }
    151  
    152   do
    153     {
    154       u_char *UDoc = NULL;
    155       unsigned long ULen=0;
     159  }
     160
     161  /* find out the maximum size for the text buffer */
     162  if (need_text) max_buf = atoi (GetDefEnv ("buffer", "1048576"));
     163
     164  /* process each document */
     165  do {
     166    u_char *UDoc = NULL;
     167    unsigned long ULen=0;
     168
     169#if defined(PARADOCNUM) ||  defined(NZDL)
     170    /* adjust the document number for paragraph level result_docs */
     171    /* this is a bit of a hack ... */
     172    if (kind==result_docs && qd->id->ifh.InvfLevel == 3 &&
     173    qd->DL != NULL && (int)qd->doc_pos < (int)qd->DL->num)
     174      qd->DL->DE[qd->doc_pos].DocNum = GetParaNumFromDocNum(qd, qd->DL->DE[qd->doc_pos].DocNum);
     175#endif
     176   
     177    if (need_text) {
     178      /* load the compressed text */
     179      if (LoadCompressedText (qd, max_buf))
     180    MGQError("Unable to load compressed text(memory?).");
     181
     182      /* uncompress the loaded text */
     183      UDoc = GetDocText (qd, &ULen);
     184      if (UDoc == NULL) MGQError("UDoc is unexpectedly NULL");
     185    }
    156186     
    157       if (need_text)
    158     {
    159       /* load the compressed text */
    160       if (LoadCompressedText (qd, max_buf))
    161         {
    162           MGQError("Unable to load compressed text(memory?).");
    163         }
    164       /* uncompress the loaded text */
    165       UDoc = GetDocText (qd, &ULen);
    166       if (UDoc == NULL)
    167         MGQError("UDoc is unexpectedly NULL");
    168     }
     187    if (UDoc != NULL  ||  kind == result_docnums) {
     188      int docnum = GetDocNum(qd);
     189#if defined(PARADOCNUM) ||  defined(NZDL)
     190      if (qd->id->ifh.InvfLevel == 3) docnum = GetDocNumFromParaNum(qd, docnum);
     191#endif
     192      switch (kind) {
     193      case result_docnums:
     194    if (sender != NULL)
     195      output_failure = (*sender)("",0,docnum,GetDocWeight(qd),ptr);
     196    break;
     197      case result_docs:
     198    if (sender != NULL)
     199      output_failure = (*sender)((char *)UDoc,ULen,docnum,GetDocWeight(qd),ptr);
     200    break;
     201      default:
     202    break;
     203      }
     204    }
     205    DocCount++;
    169206     
    170       if (UDoc != NULL  ||  kind == result_docnums)
    171     {
    172       int docnum = GetDocNum(qd);
    173 #if defined(PARADOCNUM) ||  defined(NZDL)
    174       if (qd->id->ifh.InvfLevel == 3) docnum = GetDocNumFromParaNum(qd, docnum);
    175 #endif
    176       switch (kind)
    177         {
    178         case result_docnums:
    179           if (sender != NULL)
    180         output_failure = (*sender)("",0,docnum,GetDocWeight(qd),ptr);
    181           break;
    182         case result_docs:
    183           if (sender != NULL)
    184         output_failure = (*sender)((char *)UDoc,ULen,docnum,GetDocWeight(qd),ptr);
    185           break;
    186         default:
    187           break;
    188         }
    189     }
    190       DocCount++;
    191      
    192     }
    193   while (NextDoc (qd) && output_failure == 0 && --howmany > 0);
    194  
    195   if (need_text)
    196     {
    197       FreeTextBuffer (qd);
    198     }
     207  } while (NextDoc (qd) && output_failure == 0 && --howmany > 0);
     208 
     209  if (need_text) FreeTextBuffer (qd);
    199210 
    200211  return (DocCount);
     
    311322}
    312323
    313 /* search_doc_collect will search for an index which */
    314 /* belongs to a certain collection and which has a document */
    315 /* level index. It returns -1 if none could be found. */
     324/* search_collect will search for an index which */
     325/* belongs to a certain collection It returns -1 if none could be found. */
    316326/* init_dbcache should be called before this function */
    317 static int search_doc_collect (char *collection) {
     327static int search_collect (char *collection) {
    318328  int i = 0;
    319329
     
    321331    if ((dbcache[i].accessnum >= 0) &&
    322332    (dbcache[i].qd != NULL) &&
    323     (strcmp (collection, dbcache[i].collection) == 0) &&
    324     (dbcache[i].qd->id->ifh.InvfLevel == 2)) {
     333    (strcmp (collection, dbcache[i].collection) == 0)
     334    /* && (dbcache[i].qd->id->ifh.InvfLevel == 2)*/
     335    ) {
    325336      dbcache[i].accessnum = get_next_accessnum ();
    326337      return i;
     
    331342}
    332343
    333 /* search_doc_collect will search for an index which */
     344/* search_gensuffix will search for an index which */
    334345/* has a certain gensuffix. It returns -1 if none could be found. */
    335346/* init_dbcache should be called before this function */
     
    608619}
    609620
    610 /* load_text_database tries to make a level 2 index of the */
     621/* load_text_database tries to make an index of the */
    611622/* specified collection current */
    612623int load_text_database (char *collection) {
     
    615626
    616627  /* search for the index */
    617   i = search_doc_collect (collection);
     628  i = search_collect (collection);
    618629
    619630  /* return if none were found */
Note: See TracChangeset for help on using the changeset viewer.