X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzsets.c;h=8e7c694c43afac363665da6d32672185dd52ebf0;hb=1e58ebd4607490d810c7396a4e87eb70d9528166;hp=cbdc8b177a020af4b7853f70b55fc7ccd0b7f7f1;hpb=5437b50633032595afe6f87dc0f989bc92a5aea8;p=idzebra-moved-to-github.git diff --git a/index/zsets.c b/index/zsets.c index cbdc8b1..8e7c694 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.71 2004-11-19 10:27:09 heikki Exp $ +/* $Id: zsets.c,v 1.75 2004-12-10 12:37:07 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -71,6 +71,23 @@ struct zset_sort_info { struct zset_sort_entry **entries; }; +static int log_level_set=0; +static int log_level_sorting=0; +static int log_level_searchhits=0; +static int log_level_searchterms=0; +static int log_level_resultsets=0; + +static void loglevels() +{ + if (log_level_set) + return; + log_level_sorting = yaz_log_module_level("sorting"); + log_level_searchhits = yaz_log_module_level("searchhits"); + log_level_searchterms = yaz_log_module_level("searchterms"); + log_level_resultsets = yaz_log_module_level("resultsets"); + log_level_set=1; +} + ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn, int num_bases, char **basenames, @@ -137,60 +154,6 @@ void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type, (s->hits)++; } -#if 0 /* FIXME - Delete this, we don't count terms no more */ -int zebra_resultSetTerms (ZebraHandle zh, const char *setname, - int no, zint *count, - int *type, char *out, size_t *len) -{ - ZebraSet s = resultSetGet (zh, setname); - int no_max = 0; - - if (count) - *count = 0; - if (!s || !s->rset) - return 0; - no_max = s->rset->no_rset_terms; - if (no < 0 || no >= no_max) - return 0; - if (count) - *count = s->rset->rset_terms[no]->count; - if (type) - *type = s->rset->rset_terms[no]->type; - - if (out) - { - char *inbuf = s->rset->rset_terms[no]->name; - size_t inleft = strlen(inbuf); - size_t outleft = *len - 1; - int converted = 0; - - if (zh->iconv_from_utf8 != 0) - { - char *outbuf = out; - size_t ret; - - ret = yaz_iconv(zh->iconv_from_utf8, &inbuf, &inleft, - &outbuf, &outleft); - if (ret == (size_t)(-1)) - *len = 0; - else - *len = outbuf - out; - converted = 1; - } - if (!converted) - { - if (inleft > outleft) - inleft = outleft; - *len = inleft; - memcpy (out, inbuf, *len); - } - out[*len] = 0; - } - return no_max; -} - -#endif - ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov) { ZebraSet s; @@ -199,9 +162,12 @@ ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov) for (s = zh->sets; s; s = s->next) if (!strcmp (s->name, name)) break; + + if (!log_level_set) + loglevels(); if (s) { - yaz_log(YLOG_DEBUG, "updating result set %s", name); + yaz_log(log_level_resultsets, "updating result set %s", name); if (!ov || s->locked) return NULL; if (s->rset) @@ -215,7 +181,7 @@ ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov) { const char *sort_max_str = zebra_get_resource(zh, "sortmax", "1000"); - yaz_log(YLOG_DEBUG, "adding result set %s", name); + yaz_log(log_level_resultsets, "adding result set %s", name); s = (ZebraSet) xmalloc (sizeof(*s)); s->next = zh->sets; zh->sets = s; @@ -257,7 +223,7 @@ ZebraSet resultSetGet (ZebraHandle zh, const char *name) if (!s->term_entries && !s->rset && s->rpn) { NMEM nmem = nmem_create (); - yaz_log(YLOG_LOG, "research %s", name); + yaz_log(log_level_resultsets, "research %s", name); if (!s->rset_nmem) s->rset_nmem=nmem_create(); s->rset = @@ -274,6 +240,7 @@ void resultSetInvalidate (ZebraHandle zh) { ZebraSet s = zh->sets; + yaz_log(log_level_resultsets, "invalidating result sets"); for (; s; s = s->next) { if (s->rset) @@ -332,22 +299,49 @@ void resultSetDestroy (ZebraHandle zh, int num, char **names,int *statuses) } } -ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, - int num, int *positions) +ZebraMetaRecord *zebra_meta_records_create_range (ZebraHandle zh, + const char *name, + zint start, int num) +{ + zint pos_small[10]; + zint *pos = pos_small; + ZebraMetaRecord *mr; + int i; + + if (num > 10000 || num <= 0) + return 0; + + if (num > 10) + pos = xmalloc(sizeof(*pos) * num); + + for (i = 0; i 10) + xfree(pos); + return mr; +} + +ZebraMetaRecord *zebra_meta_records_create (ZebraHandle zh, const char *name, + int num, zint *positions) { ZebraSet sset; - ZebraPosSet sr = 0; + ZebraMetaRecord *sr = 0; RSET rset; int i; struct zset_sort_info *sort_info; + if (!log_level_set) + loglevels(); if (!(sset = resultSetGet (zh, name))) return NULL; if (!(rset = sset->rset)) { if (!sset->term_entries) return 0; - sr = (ZebraPosSet) xmalloc (sizeof(*sr) * num); + sr = (ZebraMetaRecord *) xmalloc (sizeof(*sr) * num); for (i = 0; i 0 && position <= sort_info->num_entries) { - yaz_log(YLOG_DEBUG, "got pos=%d (sorted)", position); + yaz_log(log_level_sorting, "got pos=%d (sorted)", position); sr[i].sysno = sort_info->entries[position-1]->sysno; sr[i].score = sort_info->entries[position-1]->score; } @@ -427,7 +421,7 @@ ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, if (position == positions[num_i]) { sr[num_i].sysno = psysno; - yaz_log(YLOG_DEBUG, "got pos=%d (unsorted)", position); + yaz_log(log_level_sorting, "got pos=%d (unsorted)", position); sr[num_i].score = -1; num_i++; } @@ -439,7 +433,8 @@ ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, return sr; } -void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num) +void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records, + int num) { assert(zh); /* compiler shut up about unused arg */ xfree (records); @@ -591,7 +586,9 @@ void resultSetSort (ZebraHandle zh, NMEM nmem, zh->errCode = 230; return; } - yaz_log(YLOG_DEBUG, "result set sort input=%s output=%s", + if (!log_level_set) + loglevels(); + yaz_log(log_level_sorting, "result set sort input=%s output=%s", *input_setnames, output_setname); sset = resultSetGet (zh, input_setnames[0]); if (!sset) @@ -670,20 +667,20 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, switch (sk->which) { case Z_SortKey_sortField: - yaz_log(YLOG_DEBUG, "Sort: key %d is of type sortField", i+1); + yaz_log(log_level_sorting, "Sort: key %d is of type sortField", i+1); zh->errCode = 207; return; case Z_SortKey_elementSpec: - yaz_log(YLOG_DEBUG, "Sort: key %d is of type elementSpec", i+1); + yaz_log(log_level_sorting, "Sort: key %d is of type elementSpec", i+1); zh->errCode = 207; return; case Z_SortKey_sortAttributes: - yaz_log(YLOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1); + yaz_log(log_level_sorting, "Sort: key %d is of type sortAttributes", i+1); sort_criteria[i].attrUse = zebra_maps_sort (zh->reg->zebra_maps, sk->u.sortAttributes, &sort_criteria[i].numerical); - yaz_log(YLOG_DEBUG, "use value = %d", sort_criteria[i].attrUse); + yaz_log(log_level_sorting, "use value = %d", sort_criteria[i].attrUse); if (sort_criteria[i].attrUse == -1) { zh->errCode = 116; @@ -712,10 +709,10 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, } } rset_close (rfd); - yaz_log(YLOG_DEBUG, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, sort", + yaz_log(log_level_sorting, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, sort", kno, sset->hits); for (i = 0; i < numTerms; i++) - yaz_log(YLOG_LOG, "term=\"%s\" type=%s count=" ZINT_FORMAT, + yaz_log(log_level_sorting, "term=\"%s\" type=%s count=" ZINT_FORMAT, terms[i]->name, terms[i]->flags, rset_count(terms[i]->rset)); *sort_status = Z_SortResponse_success; } @@ -748,6 +745,8 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset, NMEM nmem) zint esthits; double ratio; + if (!log_level_set) + loglevels(); sort_info = zebraSet->sort_info; sort_info->num_entries = 0; zebraSet->hits = 0; @@ -779,8 +778,9 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset, NMEM nmem) do { zint this_sys = key.mem[0]; /* FIXME - assumes scope==2 */ - zint seqno = key.mem[1]; /* FIXME - assumes scope==2 */ + zint seqno = key.mem[key.len-1]; /* FIXME - assumes scope==2 */ kno++; + key_logdump_txt(log_level_searchhits,&key," Got hit"); if (this_sys != psysno) { score = (*rc->calc) (handle, psysno); @@ -797,7 +797,7 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset, NMEM nmem) if (tot>0) { ratio = cur/tot; est = (zint)(0.5+zebraSet->hits/ratio); - yaz_log(YLOG_LOG, "Estimating hits (%s) " + yaz_log(log_level_searchhits, "Estimating hits (%s) " "%0.1f->" ZINT_FORMAT "; %0.1f->" ZINT_FORMAT, rset->control->desc, @@ -821,11 +821,11 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset, NMEM nmem) } rset_close (rfd); - yaz_log(YLOG_DEBUG, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, rank", + yaz_log(log_level_searchterms, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, rank", kno, zebraSet->hits); for (i = 0; i < numTerms; i++) { - yaz_log(YLOG_LOG, "term=\"%s\" type=%s count=" ZINT_FORMAT, + yaz_log(log_level_searchterms, "term=\"%s\" type=%s count=" ZINT_FORMAT, terms[i]->name, terms[i]->flags, rset_count(terms[i]->rset)); } } @@ -863,9 +863,9 @@ void zebraRankDestroy (struct zebra_register *reg) ZebraRankClass p_next = p->next; if (p->init_flag && p->control->destroy) (*p->control->destroy)(reg, p->class_handle); - xfree (p->control->name); - xfree (p->control); - xfree (p); + xfree(p->control->name); + xfree(p->control); + xfree(p); p = p_next; } reg->rank_classes = NULL;