X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=recctrl%2Fxslt.c;h=6331754f307a5f9491b3c15db1a3b6d7559148ef;hb=cae6de97d03369a9429024f9d4abc9f1e5fbf3bb;hp=b5d5ffea65967b4b4cb7aeaebe55ddfca41a948d;hpb=5498d6d66ab0f3639b6d4517cad14f2ba25b7553;p=idzebra-moved-to-github.git diff --git a/recctrl/xslt.c b/recctrl/xslt.c index b5d5ffe..6331754 100644 --- a/recctrl/xslt.c +++ b/recctrl/xslt.c @@ -1,4 +1,4 @@ -/* $Id: xslt.c,v 1.9 2005-06-07 13:10:52 adam Exp $ +/* $Id: xslt.c,v 1.12 2005-06-24 13:45:54 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -288,12 +288,12 @@ static int ioclose_ex(void *context) return 0; } -static void index_field(struct filter_info *tinfo, struct recExtractCtrl *ctrl, +static void index_cdata(struct filter_info *tinfo, struct recExtractCtrl *ctrl, xmlNodePtr ptr, RecWord *recWord) { for(; ptr; ptr = ptr->next) { - index_field(tinfo, ctrl, ptr->children, recWord); + index_cdata(tinfo, ctrl, ptr->children, recWord); if (ptr->type != XML_TEXT_NODE) continue; recWord->term_buf = ptr->content; @@ -313,27 +313,54 @@ static void index_node(struct filter_info *tinfo, struct recExtractCtrl *ctrl, continue; if (!strcmp(ptr->name, "index")) { - char *field_str = 0; + const char *name_str = 0; + const char *type_str = 0; const char *xpath_str = 0; struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { - if (!strcmp(attr->name, "field") - && attr->children && attr->children->type == XML_TEXT_NODE) - field_str = attr->children->content; - if (!strcmp(attr->name, "xpath") - && attr->children && attr->children->type == XML_TEXT_NODE) - xpath_str = attr->children->content; + attr_content(attr, "name", &name_str); + attr_content(attr, "xpath", &xpath_str); + attr_content(attr, "type", &type_str); } - if (field_str) + if (name_str) { - recWord->attrStr = field_str; - index_field(tinfo, ctrl, ptr->children, recWord); + int prev_type = recWord->index_type; /* save default type */ + + if (type_str && *type_str) + recWord->index_type = *type_str; /* type was given */ + recWord->index_name = name_str; + index_cdata(tinfo, ctrl, ptr->children, recWord); + + recWord->index_type = prev_type; /* restore it again */ } } } } +static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl, + xmlNodePtr ptr, RecWord *recWord) +{ + if (ptr->type == XML_ELEMENT_NODE && ptr->ns && + !strcmp(ptr->ns->href, zebra_xslt_ns) + && !strcmp(ptr->name, "record")) + { + const char *type_str = "update"; + const char *id_str = 0; + struct _xmlAttr *attr; + for (attr = ptr->properties; attr; attr = attr->next) + { + attr_content(attr, "type", &type_str); + attr_content(attr, "id", &id_str); + } + if (id_str) + sscanf(id_str, "%255s", ctrl->match_criteria); + + ptr = ptr->children; + } + index_node(tinfo, ctrl, ptr, recWord); +} + static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p, xmlDocPtr doc) { @@ -348,7 +375,6 @@ static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p, set_param_str(params, "schema", zebra_xslt_ns, tinfo->odr); (*p->init)(p, &recWord); - recWord.reg_type = 'w'; if (schema && schema->stylesheet_xsp) { @@ -361,7 +387,7 @@ static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p, fwrite(buf_out, len_out, 1, stdout); xmlFree(buf_out); } - index_node(tinfo, p, xmlDocGetRootElement(resDoc), &recWord); + index_record(tinfo, p, xmlDocGetRootElement(resDoc), &recWord); xmlFreeDoc(resDoc); } xmlDocDumpMemory(doc, &buf_out, &len_out); @@ -545,7 +571,8 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) if (p->score >= 0) set_param_int(params, "score", p->score, p->odr); set_param_int(params, "size", p->recordSize, p->odr); - + set_param_int(params, "id", p->localno, p->odr); + if (window_size >= 0) set_param_xml(params, "snippet", snippet_doc(p, 1, window_size), p->odr);