X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzsets.c;h=7bb569d79c7ce39a5599589ae4b29b07a353184c;hb=9b4f970d2816490fa4cc850fabc51f494ee5612b;hp=ed5e1a6834d928ceeed1f25a8cd0dc1b572e21c5;hpb=4c1c4df443dc34e0a183de4760a2890396409bb8;p=idzebra-moved-to-github.git diff --git a/index/zsets.c b/index/zsets.c index ed5e1a6..7bb569d 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,10 +1,38 @@ /* - * Copyright (C) 1994-1998, Index Data + * Copyright (C) 1994-2000, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: zsets.c,v $ - * Revision 1.20 1998-11-16 10:10:53 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 + * On Unix, zebra/z'mbol uses automake. + * + * Revision 1.26 2000/03/20 19:08:36 adam + * Added remote record import using Z39.50 extended services and Segment + * Requests. + * + * Revision 1.25 2000/03/15 15:00:31 adam + * First work on threaded version. + * + * Revision 1.24 1999/11/04 15:00:45 adam + * Implemented delete result set(s). + * + * Revision 1.23 1999/05/26 07:49:13 adam + * C++ compilation. + * + * Revision 1.22 1999/02/02 14:51:15 adam + * Updated WIN32 code specific sections. Changed header. + * + * Revision 1.21 1998/11/16 16:03:46 adam + * Moved loggin utilities to Yaz. Was implemented in file zlogs.c. + * + * Revision 1.20 1998/11/16 10:10:53 adam * Fixed problem with zebraPosSetCreate that occurred when positions were * less than 1. * @@ -79,7 +107,7 @@ */ #include #include -#ifdef WINDOWS +#ifdef WIN32 #include #else #include @@ -122,8 +150,6 @@ ZebraSet resultSetAddRPN (ZebraHandle zh, ODR input, ODR output, { ZebraSet zebraSet; - zlog_rpn (rpn); - zh->errCode = 0; zh->errString = NULL; zh->hits = 0; @@ -167,18 +193,19 @@ ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov) else { logf (LOG_DEBUG, "adding result set %s", name); - s = xmalloc (sizeof(*s)); + s = (ZebraSet) xmalloc (sizeof(*s)); s->next = zh->sets; zh->sets = s; - s->name = xmalloc (strlen(name)+1); + s->name = (char *) xmalloc (strlen(name)+1); strcpy (s->name, name); - s->sort_info = xmalloc (sizeof(*s->sort_info)); + s->sort_info = (struct zset_sort_info *) + xmalloc (sizeof(*s->sort_info)); s->sort_info->max_entries = 1000; - s->sort_info->entries = + s->sort_info->entries = (struct zset_sort_entry **) xmalloc (sizeof(*s->sort_info->entries) * s->sort_info->max_entries); - s->sort_info->all_entries = + s->sort_info->all_entries = (struct zset_sort_entry *) xmalloc (sizeof(*s->sort_info->all_entries) * s->sort_info->max_entries); for (i = 0; i < s->sort_info->max_entries; i++) @@ -210,26 +237,48 @@ ZebraSet resultSetGet (ZebraHandle zh, const char *name) return NULL; } - -void resultSetDestroy (ZebraHandle zh) +void resultSetDestroy (ZebraHandle zh, int num, char **names,int *statuses) { - ZebraSet s, s1; - - for (s = zh->sets; s; s = s1) + ZebraSet *ss = &zh->sets; + int i; + + if (statuses) + for (i = 0; ierrCode = 0; + zh->errString = NULL; + while (*ss) { - s1 = s->next; - - xfree (s->sort_info->all_entries); - xfree (s->sort_info->entries); - xfree (s->sort_info); - - if (s->nmem) - nmem_destroy (s->nmem); - rset_delete (s->rset); - xfree (s->name); - xfree (s); + int i = -1; + ZebraSet s = *ss; + if (num >= 0) + { + for (i = 0; iname, names[i])) + { + if (statuses) + statuses[i] = Z_DeleteStatus_success; + i = -1; + break; + } + } + if (i < 0) + { + *ss = s->next; + + xfree (s->sort_info->all_entries); + xfree (s->sort_info->entries); + xfree (s->sort_info); + + if (s->nmem) + nmem_destroy (s->nmem); + rset_delete (s->rset); + xfree (s->name); + xfree (s); + } + else + ss = &s->next; } - zh->sets = NULL; } ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, @@ -245,7 +294,7 @@ ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, return NULL; if (!(rset = sset->rset)) return NULL; - sr = xmalloc (sizeof(*sr) * num); + sr = (ZebraPosSet) xmalloc (sizeof(*sr) * num); for (i = 0; isort_info; int i, j; - sortIdx_sysno (zh->sortIdx, sysno); + sortIdx_sysno (zh->service->sortIdx, sysno); for (i = 0; isortIdx, criteria[i].attrUse); - sortIdx_read (zh->sortIdx, this_entry.buf[i]); + sortIdx_type (zh->service->sortIdx, criteria[i].attrUse); + sortIdx_read (zh->service->sortIdx, this_entry.buf[i]); } i = sort_info->num_entries; while (--i >= 0) @@ -348,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; } @@ -366,20 +429,23 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, break; } } - j = sort_info->max_entries-1; + ++i; + j = sort_info->max_entries; if (i == j) return; - ++i; + + if (sort_info->num_entries == j) + --j; + else + j = (sort_info->num_entries)++; new_entry = sort_info->entries[j]; while (j != i) { sort_info->entries[j] = sort_info->entries[j-1]; --j; } - sort_info->entries[j] = new_entry; + sort_info->entries[i] = new_entry; assert (new_entry); - if (sort_info->num_entries != sort_info->max_entries) - (sort_info->num_entries)++; for (i = 0; ibuf[i], this_entry.buf[i], SORT_IDX_ENTRYSIZE); new_entry->sysno = sysno; @@ -410,20 +476,24 @@ void resultSetInsertRank (ZebraHandle zh, struct zset_sort_info *sort_info, break; } } - j = sort_info->max_entries-1; + ++i; + j = sort_info->max_entries; if (i == j) return; - ++i; + + if (sort_info->num_entries == j) + --j; + else + j = (sort_info->num_entries)++; + new_entry = sort_info->entries[j]; while (j != i) { sort_info->entries[j] = sort_info->entries[j-1]; --j; } - sort_info->entries[j] = new_entry; + sort_info->entries[i] = new_entry; assert (new_entry); - if (sort_info->num_entries != sort_info->max_entries) - (sort_info->num_entries)++; new_entry->sysno = sysno; new_entry->score = score; } @@ -476,7 +546,7 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, { int i, psysno = 0; struct it_key key; - struct sortKey sort_criteria[3]; + struct sortKeyInfo sort_criteria[3]; int num_criteria; int term_index; RSFD rfd; @@ -526,14 +596,16 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, case Z_SortKey_sortAttributes: logf (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1); sort_criteria[i].attrUse = - zebra_maps_sort (zh->zebra_maps, sk->u.sortAttributes); + zebra_maps_sort (zh->service->zebra_maps, + sk->u.sortAttributes, + &sort_criteria[i].numerical); logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse); if (sort_criteria[i].attrUse == -1) { zh->errCode = 116; return; } - if (sortIdx_type (zh->sortIdx, sort_criteria[i].attrUse)) + if (sortIdx_type (zh->service->sortIdx, sort_criteria[i].attrUse)) { zh->errCode = 207; return; @@ -554,7 +626,6 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, } rset_close (rset, rfd); - zh->errCode = 0; *sort_status = Z_SortStatus_success; logf (LOG_DEBUG, "resultSetSortSingle end"); } @@ -624,22 +695,22 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset) ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name) { - ZebraRankClass p = zh->rank_classes; + ZebraRankClass p = zh->service->rank_classes; while (p && strcmp (p->control->name, name)) p = p->next; if (p && !p->init_flag) { if (p->control->create) - p->class_handle = (*p->control->create)(zh); + p->class_handle = (*p->control->create)(zh->service); p->init_flag = 1; } return p; } -void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl) +void zebraRankInstall (ZebraService zh, struct rank_control *ctrl) { - ZebraRankClass p = xmalloc (sizeof(*p)); - p->control = xmalloc (sizeof(*p->control)); + ZebraRankClass p = (ZebraRankClass) xmalloc (sizeof(*p)); + p->control = (struct rank_control *) xmalloc (sizeof(*p->control)); memcpy (p->control, ctrl, sizeof(*p->control)); p->control->name = xstrdup (ctrl->name); p->init_flag = 0; @@ -647,7 +718,7 @@ void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl) zh->rank_classes = p; } -void zebraRankDestroy (ZebraHandle zh) +void zebraRankDestroy (ZebraService zh) { ZebraRankClass p = zh->rank_classes; while (p)