X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fsafari.c;h=be8c567764233a4659e0590fc1f172cfcb1a0b5b;hp=f7f25958f679354f59de359b93bb009449a9976d;hb=97a7adeb9e5059463f039495cc01cfa448463a27;hpb=7415d28c149c1bab51fe93aeaccdd14085b69bd9 diff --git a/index/safari.c b/index/safari.c index f7f2595..be8c567 100644 --- a/index/safari.c +++ b/index/safari.c @@ -1,8 +1,5 @@ -/* $Id: safari.c,v 1.1 2006-07-03 14:27:09 adam Exp $ - Copyright (C) 1995-2005 - Index Data ApS - -This file is part of the Zebra server. +/* This file is part of the Zebra server. + Copyright (C) 1995-2008 Index Data Zebra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -15,12 +12,12 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. -*/ +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include #include #include #include @@ -29,13 +26,20 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include struct filter_info { - char *sep; + int segments; }; -static void *filter_init (Res res, RecType recType) +static void *filter_init(Res res, RecType recType) +{ + struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo)); + tinfo->segments = 0; + return tinfo; +} + +static void *filter_init2(Res res, RecType recType) { struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo)); - tinfo->sep = 0; + tinfo->segments = 1; return tinfo; } @@ -47,7 +51,6 @@ static ZEBRA_RES filter_config(void *clientData, Res res, const char *args) static void filter_destroy(void *clientData) { struct filter_info *tinfo = clientData; - xfree (tinfo->sep); xfree (tinfo); } @@ -75,7 +78,7 @@ static int fi_getchar(struct fi_info *fi, char *dst) { if (fi->max <= 0) return 0; - fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096); + fi->max = fi->p->stream->readf(fi->p->stream, fi->buf, 4096); fi->offset = 0; if (fi->max <= 0) return 0; @@ -112,45 +115,72 @@ static int filter_extract(void *clientData, struct recExtractCtrl *p) struct filter_info *tinfo = clientData; char line[512]; RecWord recWord; + int ret = RECCTRL_EXTRACT_OK; struct fi_info *fi = fi_open(p); #if 0 yaz_log(YLOG_LOG, "filter_extract off=%ld", (long) (*fi->p->tellf)(fi->p->fh)); #endif - xfree(tinfo->sep); - tinfo->sep = 0; (*p->init)(p, &recWord); if (!fi_gets(fi, line, sizeof(line)-1)) - return RECCTRL_EXTRACT_ERROR_GENERIC; - sscanf(line, "%255s", p->match_criteria); - - recWord.index_type = '0'; - while (fi_gets(fi, line, sizeof(line)-1)) + ret = RECCTRL_EXTRACT_EOF; + else { - int nor = 0; - char field[40]; - char *cp; + sscanf(line, "%255s", p->match_criteria); + while (fi_gets(fi, line, sizeof(line)-1)) + { + int nor = 0; + char field[40]; + const char *cp = line; + char type_cstr[2]; #if 0 - yaz_log(YLOG_LOG, "safari line: %s", line); + yaz_log(YLOG_LOG, "safari line: %s", line); #endif - if (sscanf(line, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT " %39s %n", - &recWord.record_id, &recWord.section_id, &recWord.seqno, - field, &nor) < 4) - { - yaz_log(YLOG_WARN, "Bad safari record line: %s", line); - return RECCTRL_EXTRACT_ERROR_GENERIC; - } - for (cp = line + nor; *cp == ' '; cp++) - ; - recWord.index_name = field; - recWord.term_buf = cp; - recWord.term_len = strlen(cp); - (*p->tokenAdd)(&recWord); + type_cstr[1] = '\0'; + if (*cp >= '0' && *cp <= '9') + type_cstr[0] = '0'; /* the default is 0 (raw) */ + else + type_cstr[0] = *cp++; /* type given */ + type_cstr[1] = '\0'; + + recWord.index_type = type_cstr; + if (tinfo->segments) + { + if (sscanf(cp, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT + ZINT_FORMAT " %39s %n", + &recWord.record_id, &recWord.section_id, + &recWord.segment, + &recWord.seqno, + field, &nor) < 5) + { + yaz_log(YLOG_WARN, "Bad safari record line: %s", line); + ret = RECCTRL_EXTRACT_ERROR_GENERIC; + break; + } + } + else + { + if (sscanf(cp, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT " %39s %n", + &recWord.record_id, &recWord.section_id, &recWord.seqno, + field, &nor) < 4) + { + yaz_log(YLOG_WARN, "Bad safari record line: %s", line); + ret = RECCTRL_EXTRACT_ERROR_GENERIC; + break; + } + } + for (cp = cp + nor; *cp == ' '; cp++) + ; + recWord.index_name = field; + recWord.term_buf = cp; + recWord.term_len = strlen(cp); + (*p->tokenAdd)(&recWord); + } } fi_close(fi); - return RECCTRL_EXTRACT_OK; + return ret; } static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) @@ -216,7 +246,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) } if (!make_body) break; - r = (*p->readf)(p->fh, filter_buf + filter_ptr, 4096); + r = p->stream->readf(p->stream, filter_buf + filter_ptr, 4096); if (r <= 0) break; filter_ptr += r; @@ -242,7 +272,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) filter_ptr = p-filter_buf; } } - p->output_format = VAL_SUTRS; + p->output_format = yaz_oid_recsyn_sutrs; p->rec_buf = filter_buf; p->rec_len = filter_ptr; return 0; @@ -258,6 +288,16 @@ static struct recType filter_type = { filter_retrieve }; +static struct recType filter_type2 = { + 0, + "safari2", + filter_init2, + filter_config, + filter_destroy, + filter_extract, + filter_retrieve +}; + RecType #ifdef IDZEBRA_STATIC_SAFARI idzebra_filter_safari @@ -267,6 +307,7 @@ idzebra_filter [] = { &filter_type, + &filter_type2, 0, }; /*