From: Adam Dickmeiss Date: Wed, 20 Sep 2006 10:51:25 +0000 (+0000) Subject: Fixed bug #669: Numeric sorting does not work, but yields "random" order. X-Git-Tag: ZEBRA.2.0.2~13 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=b8b19cd5ced95c850cf66f0ce306161ff78f490e Fixed bug #669: Numeric sorting does not work, but yields "random" order. The numerical sort did not convert characters back to original form, that is it would only work with 'charmap @'. Any charmap should now work but results will look random if charmap does not include the digits [0-9]. --- diff --git a/index/attribute.c b/index/attribute.c index 9e8f327..b9079cd 100644 --- a/index/attribute.c +++ b/index/attribute.c @@ -1,4 +1,4 @@ -/* $Id: attribute.c,v 1.26 2006-08-14 10:40:15 adam Exp $ +/* $Id: attribute.c,v 1.27 2006-09-20 10:51:25 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -190,11 +190,7 @@ ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh, if (zebra_attr_list_get_ord(zh, sortAttributes->list, zinfo_index_category_sort, - 's', VAL_BIB1, ord)== ZEBRA_OK) - return ZEBRA_OK; - if (zebra_attr_list_get_ord(zh, sortAttributes->list, - zinfo_index_category_sort, - 'S', VAL_BIB1, ord)== ZEBRA_OK) + -1 /* any index */, VAL_BIB1, ord)== ZEBRA_OK) return ZEBRA_OK; return ZEBRA_FAIL; } diff --git a/index/zinfo.c b/index/zinfo.c index 669f366..817f104 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -1,4 +1,4 @@ -/* $Id: zinfo.c,v 1.69 2006-09-15 10:45:13 adam Exp $ +/* $Id: zinfo.c,v 1.70 2006-09-20 10:51:25 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -1360,10 +1360,10 @@ int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, assert (zei->curDatabaseInfo); for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo; *zsui; zsui = &(*zsui)->next) - if ((*zsui)->info.index_type == index_type - && (*zsui)->info.cat == cat - && (*zsui)->info.which == ZEB_SU_STR - && !yaz_matchstr((*zsui)->info.u.str, str)) + if ( (index_type == -1 || (*zsui)->info.index_type == index_type) + && (*zsui)->info.cat == cat + && (*zsui)->info.which == ZEB_SU_STR + && !yaz_matchstr((*zsui)->info.u.str, str)) { struct zebSUInfoB *zsui_this = *zsui; diff --git a/index/zsets.c b/index/zsets.c index 556e917..c4ee2ff 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.110 2006-08-14 10:40:15 adam Exp $ +/* $Id: zsets.c,v 1.111 2006-09-20 10:51:25 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -534,12 +534,9 @@ void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records, struct sortKeyInfo { int relation; -#if 0 - int attrUse; -#else int ord; -#endif int numerical; + int index_type; }; void resultSetInsertSort(ZebraHandle zh, ZebraSet sset, @@ -573,12 +570,22 @@ void resultSetInsertSort(ZebraHandle zh, ZebraSet sset, cmp_buf[j] + i * SORT_IDX_ENTRYSIZE; if (criteria[j].numerical) { - double diff = atof(this_entry_buf) - atof(other_entry_buf); - rel = 0; + char this_entry_org[1024]; + char other_entry_org[1024]; + double diff; + int index_type = criteria[j].index_type; + zebra_term_untrans(zh, index_type, this_entry_org, + this_entry_buf); + zebra_term_untrans(zh, index_type, other_entry_org, + other_entry_buf); + diff = atof(this_entry_org) - atof(other_entry_org); + if (diff > 0.0) rel = 1; else if (diff < 0.0) rel = -1; + else + rel = 0; } else { @@ -872,8 +879,7 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, sort_criteria[i].ord = zebraExplain_lookup_attr_str(zh->reg->zei, zinfo_index_category_sort, - 's', - sk->u.sortField); + -1, sk->u.sortField); if (sks->which != Z_SortKeySpec_null && sort_criteria[i].ord == -1) { @@ -890,12 +896,20 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, case Z_SortKey_sortAttributes: yaz_log(log_level_sort, "key %d is of type sortAttributes", i+1); res = zebra_sort_get_ord(zh, sk->u.sortAttributes, + &sort_criteria[i].ord, &sort_criteria[i].numerical); if (sks->which != Z_SortKeySpec_null && res != ZEBRA_OK) return ZEBRA_FAIL; break; } + if (zebraExplain_lookup_ord(zh->reg->zei, sort_criteria[i].ord, + &sort_criteria[i].index_type, + 0, 0)) + { + zebra_setError(zh, YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0); + return ZEBRA_FAIL; + } } /* allocate space for each cmpare buf + one extra for tmp comparison */ for (i = 0; i