X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fzebramap.c;h=239d05d84d14682a179dc6878b7aa1c6b54b7c78;hb=a20e59c5087fb92c419f2330c786367f9ce8ccd2;hp=0dc705ee0656e336d37a483ae3f5f39f0a4d4590;hpb=deec5ea01546cfdbc2d7a2b9e85c8eeeace21d11;p=idzebra-moved-to-github.git diff --git a/util/zebramap.c b/util/zebramap.c index 0dc705e..239d05d 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -4,7 +4,28 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebramap.c,v $ - * Revision 1.18 1999-10-15 08:27:46 adam + * Revision 1.25 2002-04-05 12:54:29 adam + * Using yaz_fclose + * + * Revision 1.24 2002/04/04 20:50:37 adam + * Multi register works with record paths and data1 profile path + * + * Revision 1.23 2001/11/15 08:41:24 adam + * Fix for weight (bug introduced by previous commit). + * + * 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 + * Added structure year and date. + * + * Revision 1.19 1999/11/30 13:48:04 adam + * Improved installation. Updated for inclusion of YAZ header files. + * + * Revision 1.18 1999/10/15 08:27:46 adam * Fixed replace handler. 8-bit fix. * * Revision 1.17 1999/09/08 12:13:21 adam @@ -69,7 +90,7 @@ #include #include -#include +#include #include #include @@ -106,6 +127,7 @@ struct zebra_map { struct zebra_maps { char *tabpath; + char *tabroot; NMEM nmem; struct zebra_map *map_list; char temp_map_str[2]; @@ -138,7 +160,7 @@ static void zebra_map_read (ZebraMaps zms, const char *name) int lineno = 0; struct zebra_map **zm = 0, *zp; - if (!(f = yaz_path_fopen(zms->tabpath, name, "r"))) + if (!(f = yaz_fopen(zms->tabpath, name, "r", zms->tabroot))) { logf(LOG_WARN|LOG_ERRNO, "%s", name); return ; @@ -248,7 +270,7 @@ static void zebra_map_read (ZebraMaps zms, const char *name) } if (zm) (*zm)->next = NULL; - fclose (f); + yaz_fclose (f); for (zp = zms->map_list; zp; zp = zp->next) zms->lookup_array[zp->reg_id] = zp; @@ -261,7 +283,7 @@ static void zms_map_handle (void *p, const char *name, const char *value) zebra_map_read (zms, value); } -ZebraMaps zebra_maps_open (Res res) +ZebraMaps zebra_maps_open (Res res, const char *base) { ZebraMaps zms = (ZebraMaps) xmalloc (sizeof(*zms)); int i; @@ -269,6 +291,9 @@ ZebraMaps zebra_maps_open (Res res) zms->nmem = nmem_create (); zms->tabpath = nmem_strdup (zms->nmem, res_get_def (res, "profilePath", ".")); + zms->tabroot = 0; + if (base) + zms->tabroot = nmem_strdup (zms->nmem, base); zms->map_list = NULL; zms->temp_map_str[0] = '\0'; @@ -286,6 +311,7 @@ ZebraMaps zebra_maps_open (Res res) zms->wrbuf_1 = wrbuf_alloc(); zms->wrbuf_2 = wrbuf_alloc(); + return zms; } @@ -303,7 +329,7 @@ chrmaptab zebra_charmap_get (ZebraMaps zms, unsigned reg_id) logf (LOG_WARN, "Unknown register type: %c", reg_id); zm->reg_id = reg_id; - zm->maptab_name = NULL; + zm->maptab_name = nmem_strdup (zms->nmem, "@"); zm->maptab = NULL; zm->type = ZEBRA_MAP_TYPE_INDEX; zm->completeness = 0; @@ -317,7 +343,8 @@ chrmaptab zebra_charmap_get (ZebraMaps zms, unsigned reg_id) if (!zm->maptab_name || !yaz_matchstr (zm->maptab_name, "@")) return NULL; if (!(zm->maptab = chrmaptab_create (zms->tabpath, - zm->maptab_name, 0))) + zm->maptab_name, 0, + zms->tabroot))) logf(LOG_WARN, "Failed to read character table %s", zm->maptab_name); else @@ -489,36 +516,48 @@ 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); } 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; @@ -528,10 +567,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 @@ -569,6 +611,14 @@ int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, *reg_id = '0'; *search_type = "phrase"; break; + case 4: /* year */ + *reg_id = 'y'; + *search_type = "phrase"; + break; + case 5: /* date */ + *reg_id = 'd'; + *search_type = "phrase"; + break; default: return -1; } @@ -585,7 +635,7 @@ WRBUF zebra_replace(ZebraMaps zms, unsigned reg_id, const char *ex_list, wrbuf_rewind(zms->wrbuf_1); wrbuf_write(zms->wrbuf_1, input_str, input_len); - if (!zm->replace_tokens) + if (!zm || !zm->replace_tokens) return zms->wrbuf_1; #if 0