X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=util%2Fzebramap.c;h=3d75a4160ea8b2a51c9e2a0fb26ccc8459f7ed9f;hb=4cd4460739e2cf4919c32623534d2cdebea455c6;hp=53632d50384f438c401bbe08da30926f91c39b1e;hpb=25476b7e1a0e7dbbe261a88fd7f14869aa27e237;p=idzebra-moved-to-github.git diff --git a/util/zebramap.c b/util/zebramap.c index 53632d5..3d75a41 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -1,10 +1,29 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: zebramap.c,v $ - * Revision 1.9 1998-04-02 14:35:30 adam + * Revision 1.15 1999-05-26 07:49:14 adam + * C++ compilation. + * + * Revision 1.14 1999/02/19 10:37:40 adam + * Minor fix. + * + * Revision 1.13 1999/02/18 15:01:04 adam + * Structure=key uses register type 0. + * + * Revision 1.12 1999/02/12 13:29:25 adam + * Implemented position-flag for registers. + * + * Revision 1.11 1998/10/13 20:09:19 adam + * Changed call to readconf_line. + * + * Revision 1.10 1998/06/23 15:33:37 adam + * Added feature to specify sort criteria in query (type 7 specifies + * sort flags). + * + * Revision 1.9 1998/04/02 14:35:30 adam * First version of Zebra that works with compiled ASN.1. * * Revision 1.8 1998/03/05 08:42:44 adam @@ -51,6 +70,7 @@ struct zebra_map { unsigned reg_id; int completeness; + int positioned; int type; union { struct { @@ -93,6 +113,7 @@ static void zebra_map_read (ZebraMaps zms, const char *name) char line[512]; char *argv[10]; int argc; + int lineno = 0; struct zebra_map **zm = 0, *zp; if (!(f = yaz_path_fopen(zms->tabpath, name, "r"))) @@ -100,7 +121,7 @@ static void zebra_map_read (ZebraMaps zms, const char *name) logf(LOG_WARN|LOG_ERRNO, "%s", name); return ; } - while ((argc = readconf_line(f, line, 512, argv, 10))) + while ((argc = readconf_line(f, &lineno, line, 512, argv, 10))) { if (!yaz_matchstr (argv[0], "index") && argc == 2) { @@ -108,12 +129,13 @@ static void zebra_map_read (ZebraMaps zms, const char *name) zm = &zms->map_list; else zm = &(*zm)->next; - *zm = nmem_malloc (zms->nmem, sizeof(**zm)); + *zm = (struct zebra_map *) nmem_malloc (zms->nmem, sizeof(**zm)); (*zm)->reg_id = argv[1][0]; (*zm)->maptab_name = NULL; (*zm)->maptab = NULL; (*zm)->type = ZEBRA_MAP_TYPE_INDEX; (*zm)->completeness = 0; + (*zm)->positioned = 1; } else if (!yaz_matchstr (argv[0], "sort") && argc == 2) { @@ -121,13 +143,14 @@ static void zebra_map_read (ZebraMaps zms, const char *name) zm = &zms->map_list; else zm = &(*zm)->next; - *zm = nmem_malloc (zms->nmem, sizeof(**zm)); + *zm = (struct zebra_map *) nmem_malloc (zms->nmem, sizeof(**zm)); (*zm)->reg_id = argv[1][0]; (*zm)->maptab_name = NULL; (*zm)->type = ZEBRA_MAP_TYPE_SORT; (*zm)->u.sort.entry_size = 80; (*zm)->maptab = NULL; (*zm)->completeness = 0; + (*zm)->positioned = 0; } else if (zm && !yaz_matchstr (argv[0], "charmap") && argc == 2) { @@ -137,6 +160,10 @@ static void zebra_map_read (ZebraMaps zms, const char *name) { (*zm)->completeness = atoi (argv[1]); } + else if (zm && !yaz_matchstr (argv[0], "position") && argc == 2) + { + (*zm)->positioned = atoi (argv[1]); + } else if (zm && !yaz_matchstr (argv[0], "entrysize") && argc == 2) { if ((*zm)->type == ZEBRA_MAP_TYPE_SORT) @@ -153,18 +180,18 @@ static void zebra_map_read (ZebraMaps zms, const char *name) static void zms_map_handle (void *p, const char *name, const char *value) { - ZebraMaps zms = p; + ZebraMaps zms = (ZebraMaps) p; zebra_map_read (zms, value); } ZebraMaps zebra_maps_open (Res res) { - ZebraMaps zms = xmalloc (sizeof(*zms)); + ZebraMaps zms = (ZebraMaps) xmalloc (sizeof(*zms)); int i; zms->nmem = nmem_create (); - zms->tabpath = nmem_strdup (zms->nmem, res_get (res, "profilePath")); + zms->tabpath = nmem_strdup (zms->nmem, res_get_def (res, "profilePath", ".")); zms->map_list = NULL; zms->temp_map_str[0] = '\0'; @@ -173,7 +200,7 @@ ZebraMaps zebra_maps_open (Res res) zms->temp_map_ptr[0] = zms->temp_map_str; zms->temp_map_ptr[1] = NULL; - zms->lookup_array = + zms->lookup_array = (struct zebra_map**) nmem_malloc (zms->nmem, sizeof(*zms->lookup_array)*256); for (i = 0; i<256; i++) zms->lookup_array[i] = 0; @@ -192,7 +219,7 @@ chrmaptab zebra_charmap_get (ZebraMaps zms, unsigned reg_id) struct zebra_map *zm = zebra_map_get (zms, reg_id); if (!zm) { - zm = nmem_malloc (zms->nmem, sizeof(*zm)); + zm = (struct zebra_map *) nmem_malloc (zms->nmem, sizeof(*zm)); logf (LOG_WARN, "Unknown register type: %c", reg_id); zm->reg_id = reg_id; @@ -338,6 +365,14 @@ int zebra_maps_is_complete (ZebraMaps zms, unsigned reg_id) return 0; } +int zebra_maps_is_positioned (ZebraMaps zms, unsigned reg_id) +{ + struct zebra_map *zm = zebra_map_get (zms, reg_id); + if (zm) + return zm->positioned; + return 0; +} + int zebra_maps_is_sort (ZebraMaps zms, unsigned reg_id) { struct zebra_map *zm = zebra_map_get (zms, reg_id); @@ -356,22 +391,26 @@ 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, - int *complete_flag) + int *complete_flag, int *sort_flag) { AttrType completeness; AttrType structure; AttrType relation; + AttrType sort_relation; int completeness_value; int structure_value; int relation_value; + int sort_relation_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); 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); if (completeness_value == 2 || completeness_value == 3) *complete_flag = 1; @@ -379,6 +418,7 @@ int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, *complete_flag = 0; *reg_id = 0; + *sort_flag = (sort_relation_value > 0) ? 1 : 0; *search_type = "phrase"; *rank_type = "void"; if (relation_value == 102) @@ -402,7 +442,6 @@ int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, case -1: case 1: /* phrase */ case 2: /* word */ - case 3: /* key */ case 108: /* string */ *search_type = "phrase"; break; @@ -412,12 +451,16 @@ int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt, break; case 109: /* numeric string */ *reg_id = 'n'; - *search_type = "phrase"; + *search_type = "numeric"; break; case 104: /* urx */ *reg_id = 'u'; *search_type = "phrase"; break; + case 3: /* key */ + *reg_id = '0'; + *search_type = "phrase"; + break; default: return -1; }