From 58e3c5132f9fe86fefbf2e130275ab9980eeed1e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 18 Jun 2003 11:46:33 +0000 Subject: [PATCH] Fix memory handling of quries in result sets --- CHANGELOG | 5 +++ dfa/dfa.c | 5 ++- include/zebraapi.h | 4 +-- index/apitest.c | 4 +-- index/index.h | 4 +-- index/zebraapi.c | 12 +++---- index/zserver.c | 4 +-- index/zsets.c | 6 ++-- test/api/Makefile.am | 7 ++-- test/api/t3.c | 4 +-- test/api/t4.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 test/api/t4.c diff --git a/CHANGELOG b/CHANGELOG index 9e8042a..2b0aeb0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,9 @@ +Bug fix: result sets were not recovered correctly. Had to +add ODR handle for zebra_search_RPN in order to make it work. + +Fixed a bug in regx filters that didn't do anchors (^) correctly. + Fixed a bug in searches with X-Path searches sometimes giving "extra" hits. diff --git a/dfa/dfa.c b/dfa/dfa.c index d52fc57..340cffc 100644 --- a/dfa/dfa.c +++ b/dfa/dfa.c @@ -1,4 +1,4 @@ -/* $Id: dfa.c,v 1.28 2002-08-02 19:26:55 adam Exp $ +/* $Id: dfa.c,v 1.29 2003-06-18 11:46:33 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -1067,7 +1067,10 @@ static struct DFA_states *mk_dfas (struct DFA_parse *dfap, int poset_chunk) init_DFA_states (&dfas, parse_info->poset, (int) (STATE_HASH)); mk_dfa_tran (parse_info, dfas); if (debug_dfa_tran) + { + printf ("PR_TRAN\n"); pr_tran (parse_info, dfas); + } if (dfa_verbose) pr_verbose (parse_info, dfas); del_pos(parse_info); diff --git a/include/zebraapi.h b/include/zebraapi.h index 77ad980..64de9eb 100644 --- a/include/zebraapi.h +++ b/include/zebraapi.h @@ -1,4 +1,4 @@ -/* $Id: zebraapi.h,v 1.6 2003-05-20 13:54:30 adam Exp $ +/* $Id: zebraapi.h,v 1.7 2003-06-18 11:46:33 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -132,7 +132,7 @@ YAZ_EXPORT int zebra_search_PQF (ZebraHandle zh, const char *pqf_query, const char *setname); /* Search using RPN Query */ -YAZ_EXPORT void zebra_search_RPN (ZebraHandle zh, Z_RPNQuery *query, +YAZ_EXPORT void zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query, const char *setname, int *hits); /* Retrieve record(s) */ diff --git a/index/apitest.c b/index/apitest.c index 72ba83e..ddc8c3a 100644 --- a/index/apitest.c +++ b/index/apitest.c @@ -1,4 +1,4 @@ -/* $Id: apitest.c,v 1.13 2003-05-20 13:52:41 adam Exp $ +/* $Id: apitest.c,v 1.14 2003-06-18 11:46:33 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -197,7 +197,7 @@ int main (int argc, char **argv) sprintf (setname, "%d", argno); /* fire up the search */ - zebra_search_RPN (zh, query, setname, &hits); + zebra_search_RPN (zh, odr_input, query, setname, &hits); /* status ... */ zebra_result (zh, &errCode, &errString); diff --git a/index/index.h b/index/index.h index a3f9426..985c39b 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.99 2003-05-20 12:52:49 adam Exp $ +/* $Id: index.h,v 1.100 2003-06-18 11:46:33 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -361,7 +361,7 @@ void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type, int use, const char *term); ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov); ZebraSet resultSetGet (ZebraHandle zh, const char *name); -ZebraSet resultSetAddRPN (ZebraHandle zh, Z_RPNQuery *rpn, +ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn, int num_bases, char **basenames, const char *setname); RSET resultSetRef (ZebraHandle zh, const char *resultSetId); diff --git a/index/zebraapi.c b/index/zebraapi.c index ff1d277..410a4ea 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.104 2003-06-17 13:53:27 adam Exp $ +/* $Id: zebraapi.c,v 1.105 2003-06-18 11:46:33 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -208,7 +208,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, assert (res); yaz_log (LOG_LOG|LOG_API, "zebra_register_open rw = %d useshadow=%d p=%p,n=%s,rp=%s", - rw, useshadow, reg, name, reg_path); + rw, useshadow, reg, name, reg_path ? reg_path : "(none)"); reg->dh = data1_createx (DATA1_FLAG_XML); if (!reg->dh) @@ -762,7 +762,7 @@ int zebra_select_databases (ZebraHandle zh, int num_bases, return 0; } -void zebra_search_RPN (ZebraHandle zh, +void zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query, const char *setname, int *hits) { ASSERTZH; @@ -776,7 +776,7 @@ void zebra_search_RPN (ZebraHandle zh, zebra_livcode_transform(zh, query); - resultSetAddRPN (zh, query, + resultSetAddRPN (zh, odr_extract_mem(o), query, zh->num_basenames, zh->basenames, setname); zebra_end_read (zh); @@ -1123,7 +1123,7 @@ void zebra_set_state (ZebraHandle zh, int val, int seqno) long p = getpid(); FILE *f; ASSERTZH; - yaz_log(LOG_API,"zebra_set_state v=%d seq=%s", val, seqno); + yaz_log(LOG_API,"zebra_set_state v=%d seq=%d", val, seqno); zh->errCode=0; sprintf (state_fname, "state.%s.LCK", zh->reg_name); @@ -1994,7 +1994,7 @@ int zebra_search_PQF (ZebraHandle zh, const char *pqf_query, if (!query) yaz_log (LOG_WARN, "bad query %s\n", pqf_query); else - zebra_search_RPN (zh, query, setname, &hits); + zebra_search_RPN (zh, odr, query, setname, &hits); odr_destroy(odr); diff --git a/index/zserver.c b/index/zserver.c index af32209..24aad32 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -1,4 +1,4 @@ -/* $Id: zserver.c,v 1.107 2003-05-24 22:35:11 adam Exp $ +/* $Id: zserver.c,v 1.108 2003-06-18 11:46:33 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -264,7 +264,7 @@ int bend_search (void *handle, bend_search_rr *r) switch (r->query->which) { case Z_Query_type_1: case Z_Query_type_101: - zebra_search_RPN (zh, r->query->u.type_1, + zebra_search_RPN (zh, r->stream, r->query->u.type_1, r->setname, &r->hits); zebra_result (zh, &r->errcode, &r->errstring); if (!r->errcode) diff --git a/index/zsets.c b/index/zsets.c index 51e48af..73e45b0 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.45 2003-05-20 12:52:50 adam Exp $ +/* $Id: zsets.c,v 1.46 2003-06-18 11:46:34 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -70,7 +70,7 @@ struct zset_sort_info { struct zset_sort_entry **entries; }; -ZebraSet resultSetAddRPN (ZebraHandle zh, +ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn, int num_bases, char **basenames, const char *setname) @@ -87,7 +87,7 @@ ZebraSet resultSetAddRPN (ZebraHandle zh, return 0; zebraSet->locked = 1; zebraSet->rpn = 0; - zebraSet->nmem = nmem_create (); + zebraSet->nmem = m; zebraSet->num_bases = num_bases; zebraSet->basenames = diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 5269641..fdbe210 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -1,18 +1,19 @@ -# $Id: Makefile.am,v 1.10 2003-05-21 14:39:22 adam Exp $ +# $Id: Makefile.am,v 1.11 2003-06-18 11:46:34 adam Exp $ -TESTS = t1 t2 t3 +TESTS = t1 t2 t3 t4 testclient_SOURCES = testclient.c noinst_PROGRAMS = testclient -EXTRA_PROGRAMS = t1 t2 t3 +EXTRA_PROGRAMS = t1 t2 t3 t4 EXTRA_DIST=t1.cfg t2.cfg t1_SOURCES = t1.c t2_SOURCES = t2.c t3_SOURCES = t3.c +t4_SOURCES = t4.c AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC) diff --git a/test/api/t3.c b/test/api/t3.c index 240a1d7..70d9729 100644 --- a/test/api/t3.c +++ b/test/api/t3.c @@ -1,4 +1,4 @@ -/* $Id: t3.c,v 1.2 2003-05-20 13:52:41 adam Exp $ +/* $Id: t3.c,v 1.3 2003-06-18 11:46:34 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -64,7 +64,7 @@ int main(int argc, char **argv) zebra_begin_trans (zh, 0); sprintf(setname, "s%d", i+1); - zebra_search_RPN (zh, query, setname, &hits); + zebra_search_RPN (zh, odr_input, query, setname, &hits); zebra_end_trans (zh); zebra_end_trans (zh); diff --git a/test/api/t4.c b/test/api/t4.c new file mode 100644 index 0000000..9ab82e9 --- /dev/null +++ b/test/api/t4.c @@ -0,0 +1,98 @@ +/* $Id: t4.c,v 1.1 2003-06-18 11:46:34 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 + Index Data Aps + +This file is part of the Zebra server. + +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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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. +*/ + +#include +#include +#include + +int main(int argc, char **argv) +{ + int i; + ZebraService zs; + ZebraHandle zh; + const char *myrec = + "\n" + " My title\n" + "\n"; + + yaz_log_init_file("t3.log"); + + nmem_init (); + + zs = zebra_start("t2.cfg"); + zh = zebra_open (zs); + zebra_select_database(zh, "Default"); + + zebra_begin_trans (zh, 1); + for (i = 0; i<1200; i++) + zebra_record_insert (zh, myrec, strlen(myrec)); + zebra_end_trans (zh); + zebra_close(zh); + zebra_stop(zs); + + zs = zebra_start("t2.cfg"); + zh = zebra_open (zs); + zebra_select_database(zh, "Default"); + + for (i = 0; i<4; i++) + { + ZebraRetrievalRecord retrievalRecord[1001]; + char setname[20]; + int j; + ODR odr_input = odr_createmem (ODR_DECODE); + ODR odr_output = odr_createmem (ODR_DECODE); + YAZ_PQF_Parser parser = yaz_pqf_create(); + Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, + "@attr 1=4 my"); + int hits; + + sprintf(setname, "s%d", i+1); + zebra_search_RPN (zh, odr_input, query, setname, &hits); + + printf ("hits=%d\n", hits); + + yaz_pqf_destroy(parser); + + odr_destroy (odr_input); + + zebra_begin_trans (zh, 1); + + for (j = 0; j<1001; j++) + retrievalRecord[j].position = j+1; + + zebra_records_retrieve (zh, odr_output, setname, 0, + VAL_TEXT_XML, 1001, retrievalRecord); + + + odr_destroy (odr_output); + + zebra_end_trans (zh); + + } + zebra_commit (zh); + zebra_close (zh); + zebra_stop (zs); + + nmem_exit (); + xmalloc_trav ("x"); + exit (0); +} -- 1.7.10.4