From 6b1dece7410af50ba077381066c10c44f0188868 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 19 Jan 2006 13:31:08 +0000 Subject: [PATCH] Fixed bug #451: Sorted result set disappears .. NEW BEHAVIOR --- index/Makefile.am | 4 ++-- index/orddict.c | 35 +++++++++++++++++++++++++++++++++++ index/orddict.h | 40 ++++++++++++++++++++++++++++++++++++++++ index/zsets.c | 46 +++++++++++++++++++++++++++++++++++++++------- 4 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 index/orddict.c create mode 100644 index/orddict.h diff --git a/index/Makefile.am b/index/Makefile.am index 5f78bd8..5b8e891 100644 --- a/index/Makefile.am +++ b/index/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.34 2005-10-28 07:25:30 adam Exp $ +## $Id: Makefile.am,v 1.35 2006-01-19 13:31:08 adam Exp $ noinst_PROGRAMS = apitest kdump @@ -10,7 +10,7 @@ libidzebra_api_la_SOURCES = dir.c dirs.c trav.c kinput.c kcompare.c \ zinfo.c invstat.c sortidx.c compact.c zsets.c zrpn.c \ rank1.c trunc.c retrieve.c extract.c rankstatic.c \ index.h recindex.h recindxp.h reckeys.c reckeys.h \ - zinfo.h zserver.h zvrank.c limit.c kcontrol.c + zinfo.h zserver.h zvrank.c limit.c kcontrol.c orddict.c orddict.h bin_PROGRAMS = zebraidx zebrasrv zebrash diff --git a/index/orddict.c b/index/orddict.c new file mode 100644 index 0000000..ed4a05f --- /dev/null +++ b/index/orddict.c @@ -0,0 +1,35 @@ + +#include + +#include "orddict.h" + +struct zebra_ord_dict { + char *str; + size_t str_sz; + Dict dict; +}; + +Zebra_ord_dict zebra_ord_dict_open(Dict dict) +{ + Zebra_ord_dict zod = xmalloc(sizeof(*zod)); + zod->str_sz = 50; + zod->str = xmalloc(zod->str_sz); + zod->dict = dict; + return zod; +} + +void zebra_ord_dict_close(Zebra_ord_dict zod) +{ + if (!zod) + return; + dict_close(zod->dict); + xfree(zod->str); + xfree(zod); +} + +char *zebra_ord_dict_lookup (Zebra_ord_dict zod, int ord, + const char *p) +{ + return dict_lookup(zod->dict, p); +} + diff --git a/index/orddict.h b/index/orddict.h new file mode 100644 index 0000000..930a8d3 --- /dev/null +++ b/index/orddict.h @@ -0,0 +1,40 @@ +/* $Id: orddict.h,v 1.1 2006-01-19 13:31:08 adam Exp $ + Copyright (C) 1995-2005 + 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. +*/ + +#ifndef ORDDICT_H +#define ORDDICT_H + +#include +#include + +YAZ_BEGIN_CDECL + + +typedef struct zebra_ord_dict *Zebra_ord_dict; + +Zebra_ord_dict zebra_ord_dict_open(Dict s); +void zebra_ord_dict_close(Zebra_ord_dict zod); +char *zebra_ord_dict_lookup (Zebra_ord_dict zod, int ord, + const char *p); + +YAZ_END_CDECL +#endif diff --git a/index/zsets.c b/index/zsets.c index ecbee31..2c543df 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.97 2006-01-12 13:21:45 adam Exp $ +/* $Id: zsets.c,v 1.98 2006-01-19 13:31:08 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -53,6 +53,7 @@ struct zebra_set { int num_bases; char **basenames; Z_RPNQuery *rpn; + Z_SortKeySpecList *sortSpec; struct zset_sort_info *sort_info; struct zebra_set_term_entry *term_entries; int term_entries_max; @@ -287,6 +288,13 @@ ZebraSet resultSetGet(ZebraHandle zh, const char *name) if (!s->rset_nmem) s->rset_nmem=nmem_create(); resultSetSearch(zh, nmem, s->rset_nmem, s->rpn, s); + if (s->rset && s->sortSpec) + { + int sort_status; + yaz_log(log_level_resultsets, "resort %s", name); + resultSetSortSingle (zh, nmem, s, s->rset, s->sortSpec, + &sort_status); + } nmem_destroy (nmem); } return s; @@ -654,13 +662,36 @@ void resultSetInsertRank (ZebraHandle zh, struct zset_sort_info *sort_info, new_entry->score = score; } -static Z_RPNQuery *copy_RPNQuery(Z_RPNQuery *src_rpn, NMEM dst) +static Z_RPNQuery *copy_RPNQuery(Z_RPNQuery *src, NMEM nmem) +{ + Z_RPNQuery *dst = 0; + ODR encode = odr_createmem(ODR_ENCODE); + ODR decode = odr_createmem(ODR_DECODE); + + if (z_RPNQuery(encode, &src, 0, 0)) + { + int len; + char *buf = odr_getbuf(encode, &len, 0); + + if (buf) + { + odr_setbuf(decode, buf, len, 0); + z_RPNQuery(decode, &dst, 0, 0); + } + } + nmem_transfer(nmem, decode->mem); + odr_destroy(encode); + odr_destroy(decode); + return dst; +} + +static Z_SortKeySpecList *copy_SortKeySpecList(Z_SortKeySpecList *src, NMEM nmem) { - Z_RPNQuery *dst_rpn = 0; + Z_SortKeySpecList *dst = 0; ODR encode = odr_createmem(ODR_ENCODE); ODR decode = odr_createmem(ODR_DECODE); - if (z_RPNQuery(encode, &src_rpn, 0, 0)) + if (z_SortKeySpecList(encode, &src, 0, 0)) { int len; char *buf = odr_getbuf(encode, &len, 0); @@ -668,13 +699,13 @@ static Z_RPNQuery *copy_RPNQuery(Z_RPNQuery *src_rpn, NMEM dst) if (buf) { odr_setbuf(decode, buf, len, 0); - z_RPNQuery(decode, &dst_rpn, 0, 0); + z_SortKeySpecList(decode, &dst, 0, 0); } } - nmem_transfer(dst, decode->mem); + nmem_transfer(nmem, decode->mem); odr_destroy(encode); odr_destroy(decode); - return dst_rpn; + return dst; } ZebraSet resultSetClone(ZebraHandle zh, const char *setname, @@ -739,6 +770,7 @@ ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem, } if (strcmp (output_setname, input_setnames[0])) sset = resultSetClone(zh, output_setname, sset); + sset->sortSpec = copy_SortKeySpecList(sort_sequence, sset->nmem); return resultSetSortSingle (zh, nmem, sset, rset, sort_sequence, sort_status); } -- 1.7.10.4