From 89d059a3e4541ff00bbb4193ba34c1dbe1e21928 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 14 Nov 2001 22:06:27 +0000 Subject: [PATCH] Rank-weight may be controlled via query. --- CHANGELOG | 6 +++++- include/zebramap.h | 7 +++++-- index/rank1.c | 16 ++++++++++++---- index/zrpn.c | 13 ++++++++----- util/zebramap.c | 20 +++++++++++++++----- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bdc1ab5..29990f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,13 @@ + +Rank weight can be controlled with attribute type 9. Default +value is 34. Recommended values between 1-36. + --- 1.1 2001/10/25 Updated for YAZ version 1.8. Added support for termsets - a result set of terms matching -a given query. +a given query. For @attr 8= creates termset named . Added support for raw retrieval. Element Set Name R forces the text filter which returns the record in its original form. diff --git a/include/zebramap.h b/include/zebramap.h index ac20d69..21fd34a 100644 --- a/include/zebramap.h +++ b/include/zebramap.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebramap.h,v $ - * Revision 1.11 2001-01-22 10:42:56 adam + * Revision 1.12 2001-11-14 22:06:27 adam + * Rank-weight may be controlled via query. + * + * Revision 1.11 2001/01/22 10:42:56 adam * Added numerical sort. * * Revision 1.10 1999/11/30 13:48:03 adam @@ -65,7 +68,7 @@ const char **zebra_maps_input (ZebraMaps zms, unsigned reg_id, const char *zebra_maps_output(ZebraMaps, unsigned reg_id, const char **from); int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, - unsigned *reg_id, char **search_type, char **rank_type, + unsigned *reg_id, char **search_type, char *rank_type, int *complete_flag, int *sort_flag); int zebra_maps_sort (ZebraMaps zms, Z_SortAttributes *sortAttributes, diff --git a/index/rank1.c b/index/rank1.c index d947684..29fcb58 100644 --- a/index/rank1.c +++ b/index/rank1.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rank1.c,v $ - * Revision 1.6 2000-03-15 15:00:30 adam + * Revision 1.7 2001-11-14 22:06:27 adam + * Rank-weight may be controlled via query. + * + * Revision 1.6 2000/03/15 15:00:30 adam * First work on threaded version. * * Revision 1.5 1999/05/26 07:49:13 adam @@ -44,6 +47,7 @@ struct rank_term_info { int global_occur; int global_inv; int rank_flag; + int rank_weight; }; struct rank_set_info { @@ -106,9 +110,12 @@ static void *begin (ZebraHandle zh, void *class_handle, RSET rset) for (i = 0; i < si->no_entries; i++) { int g = rset->rset_terms[i]->nn; - if (!strcmp (rset->rset_terms[i]->flags, "rank")) + if (!strncmp (rset->rset_terms[i]->flags, "rank,", 5)) { + yaz_log (LOG_LOG, "%s", rset->rset_terms[i]->flags); si->entries[i].rank_flag = 1; + si->entries[i].rank_weight = atoi (rset->rset_terms[i]->flags+5); + yaz_log (LOG_LOG, "i=%d weight=%d", i, si->entries[i].rank_weight); (si->no_rank_entries)++; } else @@ -163,10 +170,11 @@ static int calc (void *set_handle, int sysno) return -1; for (i = 0; i < si->no_entries; i++) if (si->entries[i].rank_flag && (lo = si->entries[i].local_occur)) - score += (8+log2_int (lo)) * si->entries[i].global_inv; - score *= 34; + score += (8+log2_int (lo)) * si->entries[i].global_inv * + si->entries[i].rank_weight; divisor = si->no_rank_entries * (8+log2_int (si->last_pos/si->no_entries)); score = score / divisor; + yaz_log (LOG_LOG, "score=%d", score); if (score > 1000) score = 1000; for (i = 0; i < si->no_entries; i++) diff --git a/index/zrpn.c b/index/zrpn.c index 28508e3..b8b2a76 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.107 2001-10-15 19:53:43 adam + * Revision 1.108 2001-11-14 22:06:27 adam + * Rank-weight may be controlled via query. + * + * Revision 1.107 2001/10/15 19:53:43 adam * POSIX thread updates. First work on term sets. * * Revision 1.106 2001/04/11 07:58:13 adam @@ -2252,13 +2255,13 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, { unsigned reg_id; char *search_type = NULL; - char *rank_type = NULL; + char rank_type[128]; int complete_flag; int sort_flag; char termz[IT_MAX_WORD+1]; zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type, - &rank_type, &complete_flag, &sort_flag); + rank_type, &complete_flag, &sort_flag); logf (LOG_DEBUG, "reg_id=%c", reg_id); logf (LOG_DEBUG, "complete_flag=%d", complete_flag); @@ -2583,7 +2586,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, unsigned reg_id; char *search_type = NULL; - char *rank_type = NULL; + char rank_type[128]; int complete_flag; int sort_flag; *list = 0; @@ -2597,7 +2600,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, use_value = attr_find (&use, &attributeset); if (zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type, - &rank_type, &complete_flag, &sort_flag)) + rank_type, &complete_flag, &sort_flag)) { *num_entries = 0; zh->errCode = 113; diff --git a/util/zebramap.c b/util/zebramap.c index 04446fb..976f5b4 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebramap.c,v $ - * Revision 1.21 2001-01-22 10:42:56 adam + * Revision 1.22 2001-11-14 22:06:27 adam + * Rank-weight may be controlled via query. + * + * Revision 1.21 2001/01/22 10:42:56 adam * Added numerical sort. * * Revision 1.20 2000/03/02 14:35:19 adam @@ -515,27 +518,31 @@ int zebra_maps_sort (ZebraMaps zms, Z_SortAttributes *sortAttributes, } int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, - unsigned *reg_id, char **search_type, char **rank_type, + unsigned *reg_id, char **search_type, char *rank_type, int *complete_flag, int *sort_flag) { AttrType completeness; AttrType structure; AttrType relation; AttrType sort_relation; + AttrType weight; int completeness_value; int structure_value; int relation_value; int sort_relation_value; + int weight_value; attr_init_APT (&structure, zapt, 4); attr_init_APT (&completeness, zapt, 6); attr_init_APT (&relation, zapt, 2); attr_init_APT (&sort_relation, zapt, 7); + attr_init_APT (&weight, zapt, 9); completeness_value = attr_find (&completeness, NULL); structure_value = attr_find (&structure, NULL); relation_value = attr_find (&relation, NULL); sort_relation_value = attr_find (&sort_relation, NULL); + weight_value = attr_find (&weight, NULL); if (completeness_value == 2 || completeness_value == 3) *complete_flag = 1; @@ -545,10 +552,13 @@ int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, *sort_flag = (sort_relation_value > 0) ? 1 : 0; *search_type = "phrase"; - *rank_type = "void"; + strcpy (rank_type, "void"); if (relation_value == 102) - *rank_type = "rank"; - + { + if (weight_value == -1) + weight_value == 34; + sprintf (rank_type, "rank,%d", weight_value); + } if (*complete_flag) *reg_id = 'p'; else -- 1.7.10.4