X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frecgrs.c;h=4d621efddbfad14eac5cd30373a21f17584d0b06;hb=ca8c7208a371bcfb79c846dfec9cd7cb42ecaf92;hp=7adf1609992aca539627a2fd4b1ba103e2f172e4;hpb=7415d28c149c1bab51fe93aeaccdd14085b69bd9;p=idzebra-moved-to-github.git diff --git a/index/recgrs.c b/index/recgrs.c index 7adf160..4d621ef 100644 --- a/index/recgrs.c +++ b/index/recgrs.c @@ -1,4 +1,4 @@ -/* $Id: recgrs.c,v 1.1 2006-07-03 14:27:09 adam Exp $ +/* $Id: recgrs.c,v 1.7 2006-09-29 10:02:47 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -15,9 +15,9 @@ 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 @@ -392,20 +392,37 @@ pop, 2003-01-17 data1_termlist *xpath_termlist_by_tagpath(char *tagpath, data1_node *n) { data1_absyn *abs = n->root->u.root.absyn; - data1_xpelement *xpe = abs->xp_elements; + + data1_xpelement *xpe = 0; data1_node *nn; #ifdef ENHANCED_XELM struct xpath_location_step *xp; #endif char *pexpr = xmalloc(strlen(tagpath)+5); - int ok = 0; sprintf (pexpr, "/%s\n", tagpath); - for (; xpe; xpe = xpe->next) + + for (xpe = abs->xp_elements; xpe; xpe = xpe->next) + xpe->match_state = -1; /* don't know if it matches yet */ + + for (xpe = abs->xp_elements; xpe; xpe = xpe->next) { int i; - ok = dfa_match_first(xpe->dfa->states, pexpr); - + int ok = xpe->match_state; + if (ok == -1) + { /* don't know whether there is a match yet */ + data1_xpelement *xpe1; + + assert(xpe->dfa); + ok = dfa_match_first(xpe->dfa->states, pexpr); + +#if OPTIMIZE_MELM + /* mark this and following ones with same regexp */ + for (xpe1 = xpe; xpe1; xpe1 = xpe1->match_next) + xpe1->match_state = ok; +#endif + } + assert (ok == 0 || ok == 1); if (ok) { #ifdef ENHANCED_XELM /* we have to check the perdicates up to the root node */ @@ -440,7 +457,7 @@ data1_termlist *xpath_termlist_by_tagpath(char *tagpath, data1_node *n) xfree(pexpr); - if (ok) { + if (xpe) { yaz_log(YLOG_DEBUG, "Got it"); return xpe->termlists; } else { @@ -937,6 +954,8 @@ int grs_extract_tree(struct recExtractCtrl *p, data1_node *n) } (*p->init)(p, &wrd); + /* data1_pr_tree(p->dh, n, stdout); */ + return dumpkeys(n, p, &wrd); } @@ -950,12 +969,7 @@ static int grs_extract_sub(void *clientData, struct recExtractCtrl *p, int oidtmp[OID_SIZE]; RecWord wrd; - gri.readf = p->readf; - gri.seekf = p->seekf; - gri.tellf = p->tellf; - gri.endf = p->endf; - gri.fh = p->fh; - gri.offset = p->offset; + gri.stream = p->stream; gri.mem = mem; gri.dh = p->dh; gri.clientData = clientData; @@ -980,6 +994,9 @@ static int grs_extract_sub(void *clientData, struct recExtractCtrl *p, /* ensure our data1 tree is UTF-8 */ data1_iconv (p->dh, mem, n, "UTF-8", data1_get_encoding(p->dh, n)); + + data1_remove_idzebra_subtree (p->dh, n); + #if 0 data1_pr_tree (p->dh, n, stdout); #endif @@ -987,10 +1004,8 @@ static int grs_extract_sub(void *clientData, struct recExtractCtrl *p, (*p->init)(p, &wrd); if (dumpkeys(n, p, &wrd) < 0) { - data1_free_tree(p->dh, n); return RECCTRL_EXTRACT_ERROR_GENERIC; } - data1_free_tree(p->dh, n); return RECCTRL_EXTRACT_OK; } @@ -1146,12 +1161,7 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p, int dummy; mem = nmem_create(); - gri.readf = p->readf; - gri.seekf = p->seekf; - gri.tellf = p->tellf; - gri.endf = NULL; - gri.fh = p->fh; - gri.offset = 0; + gri.stream = p->stream; gri.mem = mem; gri.dh = p->dh; gri.clientData = clientData; @@ -1166,6 +1176,8 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p, } data1_concat_text(p->dh, mem, node); + data1_remove_idzebra_subtree (p->dh, node); + #if 0 data1_pr_tree (p->dh, node, stdout); #endif @@ -1313,9 +1325,6 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p, p->odr)) > 0) { p->diagnostic = res; - if (onode) - data1_free_tree(p->dh, onode); - data1_free_tree(p->dh, node); nmem_destroy(mem); return 0; } @@ -1432,10 +1441,6 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p, p->rec_buf = new_buf; } } - if (node) - data1_free_tree(p->dh, node); - if (onode) - data1_free_tree(p->dh, onode); nmem_destroy(mem); return 0; }