From: Adam Dickmeiss Date: Fri, 27 Oct 1995 14:00:10 +0000 (+0000) Subject: Implemented detection of database availability. X-Git-Tag: ZEBRA.1.0~690 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=6617321a09d4d5bf442feaea2d7f1347acd82e3c;p=idzebra-moved-to-github.git Implemented detection of database availability. --- diff --git a/index/extract.c b/index/extract.c index b557a7f..fffe509 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.22 1995-10-17 18:02:07 adam + * Revision 1.23 1995-10-27 14:00:10 adam + * Implemented detection of database availability. + * + * Revision 1.22 1995/10/17 18:02:07 adam * New feature: databases. Implemented as prefix to words in dictionary. * * Revision 1.21 1995/10/10 12:24:38 adam @@ -262,7 +265,7 @@ static void wordAdd (const RecWord *p) key_buf[ptr_top-ptr_i] = (char*)key_buf + kused; kused += index_word_prefix ((char*)key_buf + kused, p->attrSet, p->attrUse, - 1, &key_databaseName); + key_databaseName); switch (p->which) { case Word_String: diff --git a/index/index.h b/index/index.h index 7f4d5cc..9c92696 100644 --- a/index/index.h +++ b/index/index.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.18 1995-10-17 18:02:08 adam + * Revision 1.19 1995-10-27 14:00:11 adam + * Implemented detection of database availability. + * + * Revision 1.18 1995/10/17 18:02:08 adam * New feature: databases. Implemented as prefix to words in dictionary. * * Revision 1.17 1995/10/13 16:01:49 adam @@ -113,6 +116,4 @@ void strtab_del (struct strtab *t, void *data); int index_char_cvt (int c); int index_word_prefix (char *string, int attset_ordinal, - int local_attribute, - int numbases, - char **databaseNames); + int local_attribute, char *databaseName); diff --git a/index/kcompare.c b/index/kcompare.c index 82f9343..c32998e 100644 --- a/index/kcompare.c +++ b/index/kcompare.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: kcompare.c,v $ - * Revision 1.12 1995-10-17 18:02:08 adam + * Revision 1.13 1995-10-27 14:00:11 adam + * Implemented detection of database availability. + * + * Revision 1.12 1995/10/17 18:02:08 adam * New feature: databases. Implemented as prefix to words in dictionary. * * Revision 1.11 1995/10/06 16:33:37 adam @@ -117,24 +120,11 @@ int index_char_cvt (int c) int index_word_prefix (char *string, int attset_ordinal, int local_attribute, - int num_bases, - char **databaseNames) + char *databaseName) { int i; - if (num_bases > 1) - { - sprintf (string, "%c%04d(", attset_ordinal + '0', local_attribute); - strcat (string, databaseNames[i]); - for (i = 1; i < num_bases; i++) - { - strcat (string, "|"); - strcat (string, databaseNames[i]); - } - strcat (string, ")@"); - } - else - sprintf (string, "%c%04d%s@", attset_ordinal + '0', local_attribute, - *databaseNames); + sprintf (string, "%s@%c%04d", databaseName, + attset_ordinal + '0', local_attribute); for (i = 0; string[i]; i++) string[i] = index_char_cvt (string[i]); return i; diff --git a/index/zrpn.c b/index/zrpn.c index 698dae1..b6ee62d 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.31 1995-10-17 18:02:10 adam + * Revision 1.32 1995-10-27 14:00:11 adam + * Implemented detection of database availability. + * + * Revision 1.31 1995/10/17 18:02:10 adam * New feature: databases. Implemented as prefix to words in dictionary. * * Revision 1.30 1995/10/16 09:32:38 adam @@ -118,7 +121,7 @@ #include int index_word_prefix_map (char *string, oid_value attrSet, int attrUse, - int num_bases, char **basenames) + char *basename) { attent *attp; @@ -128,8 +131,7 @@ int index_word_prefix_map (char *string, oid_value attrSet, int attrUse, return -1; logf (LOG_DEBUG, "ord=%d", attp->attset_ordinal); return index_word_prefix (string, attp->attset_ordinal, - attp->local_attribute, - num_bases, basenames); + attp->local_attribute, basename); } /* @@ -595,7 +597,8 @@ static int relational_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, const char *term_sub, char *term_dict, oid_value attributeSet, - struct grep_info *grep_info) + struct grep_info *grep_info, + int *max_pos) { AttrType relation; int relation_value; @@ -636,7 +639,7 @@ static int relational_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, return 0; } logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict); - r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, + r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, max_pos, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r); @@ -650,7 +653,7 @@ static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, int num_bases, char **basenames) { char term_dict[2*IT_MAX_WORD+2]; - int i, j, r; + int i, j, r, base_no; AttrType truncation; int truncation_value; AttrType use; @@ -666,63 +669,82 @@ static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, if (use_value == -1) use_value = 1016; - i = index_word_prefix_map (term_dict, curAttributeSet, use_value, - num_bases, basenames); - if (i < 0) - { - zi->errCode = 114; - return -1; - } - if (relational_term (zi, zapt, term_sub, term_dict, - attributeSet, grep_info)) - return 0; - switch (truncation_value) + for (base_no = 0; base_no < num_bases; base_no++) { - case -1: /* not specified */ - case 100: /* do not truncate */ - strcat (term_dict, "("); - strcat (term_dict, term_sub); - strcat (term_dict, ")"); - logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict); - r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, - grep_handle); - if (r) - logf (LOG_WARN, "dict_lookup_grep fail, trunc=none: %d", r); - break; - case 1: /* right truncation */ - strcat (term_dict, term_sub); - strcat (term_dict, ".*"); - dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, grep_handle); - break; - case 2: /* left truncation */ - case 3: /* left&right truncation */ - zi->errCode = 120; - return -1; - case 101: /* process # in term */ - for (j = strlen(term_dict), i = 0; term_sub[i] && i < 2; i++) - term_dict[j++] = term_sub[i]; - for (; term_sub[i]; i++) - if (term_sub[i] == '#') + int max_pos; + int prefix_len = index_word_prefix_map (term_dict, curAttributeSet, + use_value, + basenames[base_no]); + if (prefix_len < 0) + { + zi->errCode = 114; + return -1; + } + if (!relational_term (zi, zapt, term_sub, term_dict, + attributeSet, grep_info, &max_pos)) + { + switch (truncation_value) { - term_dict[j++] = '.'; - term_dict[j++] = '*'; + case -1: /* not specified */ + case 100: /* do not truncate */ + strcat (term_dict, "("); + strcat (term_dict, term_sub); + strcat (term_dict, ")"); + logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict); + r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, + &max_pos, grep_handle); + if (r) + logf (LOG_WARN, "dict_lookup_grep err, trunc=none:%d", r); + break; + case 1: /* right truncation */ + strcat (term_dict, term_sub); + strcat (term_dict, ".*"); + dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, + &max_pos, grep_handle); + break; + case 2: /* left truncation */ + case 3: /* left&right truncation */ + zi->errCode = 120; + return -1; + case 101: /* process # in term */ + for (j = strlen(term_dict), i = 0; term_sub[i] && i < 2; i++) + term_dict[j++] = term_sub[i]; + for (; term_sub[i]; i++) + if (term_sub[i] == '#') + { + term_dict[j++] = '.'; + term_dict[j++] = '*'; + } + else + term_dict[j++] = term_sub[i]; + term_dict[j] = '\0'; + r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, + &max_pos, grep_handle); + if (r) + logf (LOG_WARN, "dict_lookup_grep err, trunc=#: %d", + r); + break; + case 102: /* regular expression */ + strcat (term_dict, "("); + strcat (term_dict, term_sub); + strcat (term_dict, ")"); + logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict); + r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, + &max_pos, grep_handle); + if (r) + logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d", + r); + break; } - else - term_dict[j++] = term_sub[i]; - term_dict[j] = '\0'; - dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, grep_handle); - break; - case 102: /* regular expression */ - strcat (term_dict, "("); - strcat (term_dict, term_sub); - strcat (term_dict, ")"); - logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict); - r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, - grep_handle); - if (r) - logf (LOG_WARN, "dict_lookup_grep fail, trunc=regular: %d", r); - break; + } + logf (LOG_DEBUG, "max_pos = %d", max_pos); + if (max_pos <= strlen(basenames[base_no])) + { + zi->errCode = 109; /* Database unavailable */ + zi->errString = basenames[base_no]; + return -1; + } } logf (LOG_DEBUG, "%d positions", grep_info->isam_p_indx); return 0; @@ -1253,12 +1275,18 @@ static int scan_handle (Dict_char *name, const char *info, int pos, return 0; } -int rpn_scan (ZServerInfo *zi, ODR odr, Z_AttributesPlusTerm *zapt, + +static int dummy_handle (Dict_char *name, const char *info, void *p) +{ + return 0; +} + +int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, int num_bases, char **basenames, int *position, int *num_entries, struct scan_entry **list, int *status) { - int i, j, sizez; + int i, j, sizez, max_pos; int pos = *position; int num = *num_entries; int before; @@ -1275,12 +1303,13 @@ int rpn_scan (ZServerInfo *zi, ODR odr, Z_AttributesPlusTerm *zapt, return 111; scan_info.before = before = pos-1; scan_info.after = after = 1+num-pos; - scan_info.odr = odr; + scan_info.odr = zi->odr; logf (LOG_DEBUG, "scan, before = %d, after = %d", before, after); scan_info.isam = zi->wordIsam; - scan_info.list = odr_malloc (odr, (before+after)*sizeof(*scan_info.list)); + scan_info.list = odr_malloc (zi->odr, (before+after)* + sizeof(*scan_info.list)); for (j = 0; jwordDict, termz, 0, NULL, &max_pos, + dummy_handle); + if (max_pos <= strlen(*basenames)) + { + zi->errString = *basenames; + return zi->errCode = 109; /* Database unavailable */ + } strcpy (scan_info.prefix, termz); sizez = term->u.general->len; if (sizez > IT_MAX_WORD) diff --git a/index/zserver.c b/index/zserver.c index 07f5961..553e6fb 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.c,v $ - * Revision 1.19 1995-10-17 18:02:11 adam + * Revision 1.20 1995-10-27 14:00:12 adam + * Implemented detection of database availability. + * + * Revision 1.19 1995/10/17 18:02:11 adam * New feature: databases. Implemented as prefix to words in dictionary. * * Revision 1.18 1995/10/16 14:03:09 quinn @@ -134,12 +137,14 @@ bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd) odr_reset (server_info.odr); server_info.errCode = 0; + server_info.errString = NULL; switch (q->query->which) { case Z_Query_type_1: r.errcode = rpn_search (&server_info, q->query->u.type_1, q->num_bases, q->basenames, q->setname, &r.hits); + r.errstring = server_info.errString; break; default: r.errcode = 107; @@ -252,14 +257,15 @@ bend_scanresult *bend_scan (void *handle, bend_scanrequest *q, int *num) odr_reset (server_info.odr); server_info.errCode = 0; + server_info.errString = 0; - r.errstring = 0; r.term_position = q->term_position; r.num_entries = q->num_entries; - r.errcode = rpn_scan (&server_info, server_info.odr, q->term, + r.errcode = rpn_scan (&server_info, q->term, q->num_bases, q->basenames, &r.term_position, &r.num_entries, &r.entries, &status); + r.errstring = server_info.errString; r.status = status; return &r; } diff --git a/index/zserver.h b/index/zserver.h index 565965a..d6d6217 100644 --- a/index/zserver.h +++ b/index/zserver.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.h,v $ - * Revision 1.11 1995-10-17 18:02:12 adam + * Revision 1.12 1995-10-27 14:00:12 adam + * Implemented detection of database availability. + * + * Revision 1.11 1995/10/17 18:02:12 adam * New feature: databases. Implemented as prefix to words in dictionary. * * Revision 1.10 1995/10/09 16:18:38 adam @@ -72,7 +75,7 @@ int rpn_search (ZServerInfo *zi, Z_RPNQuery *rpn, int num_bases, char **basenames, const char *setname, int *hits); -int rpn_scan (ZServerInfo *zi, ODR odr, Z_AttributesPlusTerm *zapt, +int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, int num_bases, char **basenames, int *position, int *num_entries, struct scan_entry **list, int *status);