X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Falvis.c;h=851064fdbb723b26569ffbf629862397afd6946f;hb=fd10c2116175815cf6c2da430a439c27991e1918;hp=43847e0ce106c260d2be81179584a3125c04e82a;hpb=5d13c6c6bb31cb385291820d9d1d9e4d192e8d0a;p=idzebra-moved-to-github.git diff --git a/index/alvis.c b/index/alvis.c index 43847e0..851064f 100644 --- a/index/alvis.c +++ b/index/alvis.c @@ -1,4 +1,4 @@ -/* $Id: alvis.c,v 1.5 2006-11-10 12:56:26 adam Exp $ +/* $Id: alvis.c,v 1.9 2006-12-22 12:13:40 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -161,8 +161,8 @@ static void *filter_init(Res res, RecType recType) static int attr_content(struct _xmlAttr *attr, const char *name, const char **dst_content) { - if (!XML_STRCMP(attr->name, name) && attr->children && - attr->children->type == XML_TEXT_NODE) + if (!XML_STRCMP(attr->name, name) && attr->children + && attr->children->type == XML_TEXT_NODE) { *dst_content = (const char *)(attr->children->content); return 1; @@ -193,27 +193,29 @@ static ZEBRA_RES create_schemas(struct filter_info *tinfo, const char *fname) char tmp_full_name[1024]; xmlNodePtr ptr; tinfo->fname = xstrdup(fname); - - if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path, + + if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path, NULL, tmp_full_name)) - tinfo->full_name = xstrdup(tmp_full_name); + tinfo->full_name = xstrdup(tmp_full_name); else - tinfo->full_name = xstrdup(tinfo->fname); - + tinfo->full_name = xstrdup(tinfo->fname); + yaz_log(YLOG_LOG, "alvis filter: loading config file %s", tinfo->full_name); - + tinfo->doc = xmlParseFile(tinfo->full_name); - - if (!tinfo->doc){ + + if (!tinfo->doc) + { yaz_log(YLOG_WARN, "alvis filter: could not parse config file %s", tinfo->full_name); - + return ZEBRA_FAIL; } ptr = xmlDocGetRootElement(tinfo->doc); - if (!ptr || ptr->type != XML_ELEMENT_NODE || - XML_STRCMP(ptr->name, "schemaInfo")){ + if (!ptr || ptr->type != XML_ELEMENT_NODE + || XML_STRCMP(ptr->name, "schemaInfo")) + { yaz_log(YLOG_WARN, "alvis filter: config file %s :" " expected root element ", @@ -432,7 +434,12 @@ static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl, sscanf(id_str, "%255s", ctrl->match_criteria); if (rank_str) - ctrl->staticrank = atoi(rank_str); + ctrl->staticrank = +#if HAVE_ATOLL + atoll(rank_str); +#else + atoi(rank_str); +#endif ptr = ptr->children; } @@ -516,9 +523,7 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p) { int type = xmlTextReaderNodeType(tinfo->reader); int depth = xmlTextReaderDepth(tinfo->reader); - if (tinfo->split_level == 0 || - (tinfo->split_level > 0 && - type == XML_READER_TYPE_ELEMENT && tinfo->split_level == depth)) + if (type == XML_READER_TYPE_ELEMENT && tinfo->split_level == depth) { xmlNodePtr ptr = xmlTextReaderExpand(tinfo->reader); if (ptr) @@ -544,13 +549,33 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p) return RECCTRL_EXTRACT_EOF; } +static int extract_full(struct filter_info *tinfo, struct recExtractCtrl *p) +{ + if (p->first_record) /* only one record per stream */ + { + xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex, p /* I/O handler */, + 0 /* URL */, + 0 /* encoding */, + XML_PARSE_XINCLUDE); + if (!doc) + { + return RECCTRL_EXTRACT_ERROR_GENERIC; + } + return extract_doc(tinfo, p, doc); + } + else + return RECCTRL_EXTRACT_EOF; +} + static int filter_extract(void *clientData, struct recExtractCtrl *p) { struct filter_info *tinfo = clientData; odr_reset(tinfo->odr); - - return extract_split(tinfo, p); + if (tinfo->split_level == 0) + return extract_full(tinfo, p); + else + return extract_split(tinfo, p); } static int ioread_ret(void *context, char *buffer, int len) @@ -706,8 +731,11 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) xmlChar *buf_out; int len_out; - xsltSaveResultToString(&buf_out, &len_out, resDoc, - schema->stylesheet_xsp); + if (schema->stylesheet_xsp) + xsltSaveResultToString(&buf_out, &len_out, resDoc, + schema->stylesheet_xsp); + else + xmlDocDumpMemory(resDoc, &buf_out, &len_out); p->output_format = VAL_TEXT_XML; p->rec_len = len_out; @@ -720,8 +748,11 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) xmlChar *buf_out; int len_out; - xsltSaveResultToString(&buf_out, &len_out, resDoc, - schema->stylesheet_xsp); + if (schema->stylesheet_xsp) + xsltSaveResultToString(&buf_out, &len_out, resDoc, + schema->stylesheet_xsp); + else + xmlDocDumpMemory(resDoc, &buf_out, &len_out); p->output_format = VAL_SUTRS; p->rec_len = len_out;