From d8b7f92dc036c81ed51a5f22b8c5bc9a5ae74487 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 12 Jan 2006 13:21:45 +0000 Subject: [PATCH] Fixed bug #451: Sorted result set disappears after update --- index/zsets.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/index/zsets.c b/index/zsets.c index 949ace4..ecbee31 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.96 2005-10-28 07:25:30 adam Exp $ +/* $Id: zsets.c,v 1.97 2006-01-12 13:21:45 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -654,6 +654,54 @@ 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) +{ + Z_RPNQuery *dst_rpn = 0; + ODR encode = odr_createmem(ODR_ENCODE); + ODR decode = odr_createmem(ODR_DECODE); + + if (z_RPNQuery(encode, &src_rpn, 0, 0)) + { + int len; + char *buf = odr_getbuf(encode, &len, 0); + + if (buf) + { + odr_setbuf(decode, buf, len, 0); + z_RPNQuery(decode, &dst_rpn, 0, 0); + } + } + nmem_transfer(dst, decode->mem); + odr_destroy(encode); + odr_destroy(decode); + return dst_rpn; +} + +ZebraSet resultSetClone(ZebraHandle zh, const char *setname, + ZebraSet rset) +{ + ZebraSet nset; + int i; + + nset = resultSetAdd(zh, setname, 1); + if (!nset) + return 0; + + nset->nmem = nmem_create(); + + nset->num_bases = rset->num_bases; + nset->basenames = + nmem_malloc (nset->nmem, nset->num_bases * sizeof(*rset->basenames)); + for (i = 0; inum_bases; i++) + nset->basenames[i] = nmem_strdup(nset->nmem, rset->basenames[i]); + + if (rset->rset) + nset->rset = rset_dup(rset->rset); + if (rset->rpn) + nset->rpn = copy_RPNQuery(rset->rpn, nset->nmem); + return nset; +} + ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem, int num_input_setnames, const char **input_setnames, const char *output_setname, @@ -690,11 +738,7 @@ ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem, return ZEBRA_FAIL; } if (strcmp (output_setname, input_setnames[0])) - { - rset = rset_dup (rset); - sset = resultSetAdd (zh, output_setname, 1); - sset->rset = rset; - } + sset = resultSetClone(zh, output_setname, sset); return resultSetSortSingle (zh, nmem, sset, rset, sort_sequence, sort_status); } -- 1.7.10.4