From: Adam Dickmeiss Date: Mon, 22 Jan 2001 10:42:56 +0000 (+0000) Subject: Added numerical sort. X-Git-Tag: ZEBRA.1.1~35 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=671a4683745b7a6341099294ae04ebefc337ba84 Added numerical sort. --- diff --git a/CHANGELOG b/CHANGELOG index 56b656b..c6c8fe7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +Added numerical sort - triggered by structure=numeric (4=109). + Remote record import using Z39.50 Extended Services and Segments. Fixed bug where updating a database with user-defined attributes diff --git a/include/zebramap.h b/include/zebramap.h index 490373b..ac20d69 100644 --- a/include/zebramap.h +++ b/include/zebramap.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebramap.h,v $ - * Revision 1.10 1999-11-30 13:48:03 adam + * Revision 1.11 2001-01-22 10:42:56 adam + * Added numerical sort. + * + * Revision 1.10 1999/11/30 13:48:03 adam * Improved installation. Updated for inclusion of YAZ header files. * * Revision 1.9 1999/09/07 07:19:21 adam @@ -65,7 +68,8 @@ int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, unsigned *reg_id, char **search_type, char **rank_type, int *complete_flag, int *sort_flag); -int zebra_maps_sort (ZebraMaps zms, Z_SortAttributes *sortAttributes); +int zebra_maps_sort (ZebraMaps zms, Z_SortAttributes *sortAttributes, + int *numerical); int zebra_maps_is_complete (ZebraMaps zms, unsigned reg_id); int zebra_maps_is_sort (ZebraMaps zms, unsigned reg_id); diff --git a/index/zsets.c b/index/zsets.c index d2ebf5f..7bb569d 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zsets.c,v $ - * Revision 1.28 2000-07-07 12:49:20 adam + * Revision 1.29 2001-01-22 10:42:56 adam + * Added numerical sort. + * + * Revision 1.28 2000/07/07 12:49:20 adam * Optimized resultSetInsert{Rank,Sort}. * * Revision 1.27 2000/04/05 09:49:36 adam @@ -371,6 +374,7 @@ void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num) struct sortKeyInfo { int relation; int attrUse; + int numerical; }; void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, @@ -394,8 +398,21 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, int rel = 0; for (j = 0; jentries[i]->buf[j], + if (criteria[j].numerical) + { + double diff = atof(this_entry.buf[j]) - + atof(sort_info->entries[i]->buf[j]); + rel = 0; + if (diff > 0.0) + rel = 1; + else if (diff < 0.0) + rel = -1; + } + else + { + rel = memcmp (this_entry.buf[j], sort_info->entries[i]->buf[j], SORT_IDX_ENTRYSIZE); + } if (rel) break; } @@ -580,7 +597,8 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, logf (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1); sort_criteria[i].attrUse = zebra_maps_sort (zh->service->zebra_maps, - sk->u.sortAttributes); + sk->u.sortAttributes, + &sort_criteria[i].numerical); logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse); if (sort_criteria[i].attrUse == -1) { diff --git a/util/zebramap.c b/util/zebramap.c index e05bdce..04446fb 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebramap.c,v $ - * Revision 1.20 2000-03-02 14:35:19 adam + * Revision 1.21 2001-01-22 10:42:56 adam + * Added numerical sort. + * + * Revision 1.20 2000/03/02 14:35:19 adam * Added structure year and date. * * Revision 1.19 1999/11/30 13:48:04 adam @@ -495,11 +498,19 @@ int zebra_maps_is_sort (ZebraMaps zms, unsigned reg_id) return 0; } -int zebra_maps_sort (ZebraMaps zms, Z_SortAttributes *sortAttributes) +int zebra_maps_sort (ZebraMaps zms, Z_SortAttributes *sortAttributes, + int *numerical) { AttrType use; + AttrType structure; + int structure_value; attr_init_AttrList (&use, sortAttributes->list, 1); + attr_init_AttrList (&structure, sortAttributes->list, 4); + *numerical = 0; + structure_value = attr_find (&structure, 0); + if (structure_value == 109) + *numerical = 1; return attr_find (&use, NULL); }