-/* $Id: mod_dom.c,v 1.14 2007-02-15 14:44:48 marc Exp $
+/* $Id: mod_dom.c,v 1.15 2007-02-15 15:08:41 marc Exp $
Copyright (C) 1995-2007
Index Data ApS
/* DOM filter style indexing */
static void index_value_of(struct filter_info *tinfo,
- struct recExtractCtrl *extctr,
+ struct recExtractCtrl *extctr,
+ RecWord* recword,
xmlNodePtr node,
xmlChar * index_p)
{
xmlChar type[256];
/* assingning text to be indexed */
- RecWord recWord;
- (*extctr->init)(extctr, &recWord);
- recWord.term_buf = (const char *)text;
- recWord.term_len = text_len;
+ recword->term_buf = (const char *)text;
+ recword->term_len = text_len;
/* parsing all index name/type pairs */
/* may not start with ' ' or ':' */
"INDEX '%s:%s' '%s'",
tinfo->fname, index, type, text);
- recWord.index_name = (const char *)index;
+ recword->index_name = (const char *)index;
if (type && *type)
- recWord.index_type = *type;
- (extctr->tokenAdd)(&recWord);
+ recword->index_type = *type;
+ (extctr->tokenAdd)(recword);
/* eat whitespaces */
if (*look && ' ' == *look && *(look+1)){
extctr->staticrank = atozint((const char *)rank_p);
/* if (!strcmp("update", type_str)) */
- /* index_node(tinfo, ctrl, ptr, recWord); */
+ /* index_node(tinfo, ctrl, ptr, recword); */
/* else if (!strcmp("delete", type_str)) */
/* yaz_log(YLOG_WARN, "dom filter delete: to be implemented"); */
/* else */
/* DOM filter style indexing */
static void process_xml_element_zebra_node(struct filter_info *tinfo,
struct recExtractCtrl *extctr,
+ RecWord* recword,
xmlNodePtr node)
{
if (node->type == XML_ELEMENT_NODE
struct _xmlAttr *attr;
for (attr = node->properties; attr; attr = attr->next){
if (attr_content_xml(attr, "name", &index_p)){
- index_value_of(tinfo, extctr, node, index_p);
+ index_value_of(tinfo, extctr, recword,node, index_p);
}
else
yaz_log(YLOG_WARN,"%s dom filter: "
/* DOM filter style indexing */
static void process_xml_element_node(struct filter_info *tinfo,
struct recExtractCtrl *extctr,
+ RecWord* recword,
xmlNodePtr node)
{
/* remember indexing instruction from PI to next element node */
xmlChar *index_p = 0;
- /* yaz_log(YLOG_DEBUG,"ELEM %s\n", xmlGetNodePath(node)); */
-
/* check if we are an element node in the special zebra namespace
and either set record data or index value-of node content*/
- process_xml_element_zebra_node(tinfo, extctr, node);
+ process_xml_element_zebra_node(tinfo, extctr, recword, node);
/* loop through kid nodes */
for (node = node->children; node; node = node->next)
else if (node->type == XML_ELEMENT_NODE){
/* if there was a PI index instruction before this element */
if (index_p){
- index_value_of(tinfo, extctr, node, index_p);
+ index_value_of(tinfo, extctr, recword, node, index_p);
index_p = 0;
}
- process_xml_element_node(tinfo, extctr, node);
+ process_xml_element_node(tinfo, extctr, recword,node);
}
else
continue;
struct recExtractCtrl *extctr,
xmlDocPtr doc)
{
- /* yaz_log(YLOG_DEBUG,"DOC %s\n", xmlGetNodePath((xmlNodePtr)doc)); */
-
xmlChar *buf_out;
int len_out;
+
+ /* only need to do the initialization once, reuse recword for all terms */
+ RecWord recword;
+ (*extctr->init)(extctr, &recword);
+
if (extctr->flagShowRecords){
xmlDocDumpMemory(doc, &buf_out, &len_out);
fwrite(buf_out, len_out, 1, stdout);
xmlFree(buf_out);
}
- process_xml_element_node(tinfo, extctr, (xmlNodePtr)doc);
+ process_xml_element_node(tinfo, extctr, &recword, (xmlNodePtr)doc);
}