29 #include <yaz/yaz-util.h>
30 #include <yaz/snprintf.h>
37 #define ZEBRA_MAP_TYPE_SORT 1
38 #define ZEBRA_MAP_TYPE_INDEX 2
39 #define ZEBRA_MAP_TYPE_STATICRANK 3
41 #define ZEBRA_REPLACE_ANY 300
64 struct icu_chain *icu_chain;
93 icu_chain_destroy(zm->icu_chain);
103 nmem_destroy(zms->
nmem);
113 zm->
id = nmem_strdup(zms->
nmem, index_type);
142 const char *fname,
int lineno)
147 yaz_log(YLOG_WARN,
"%s:%d: Missing arguments for '%s'",
148 fname, lineno, argv[0]);
153 yaz_log(YLOG_WARN,
"%s:%d: Too many arguments for '%s'",
154 fname, lineno, argv[0]);
157 if (!yaz_matchstr(argv[0],
"index"))
162 else if (!yaz_matchstr(argv[0],
"sort"))
165 zm->
u.
sort.entry_size = 80;
167 else if (!yaz_matchstr(argv[0],
"staticrank"))
174 yaz_log(YLOG_WARN,
"%s:%d: Missing sort/index before '%s'",
175 fname, lineno, argv[0]);
178 else if (!yaz_matchstr(argv[0],
"charmap") && argc == 2)
184 yaz_log(YLOG_WARN|YLOG_FATAL,
"%s:%d: charmap for "
185 "staticrank is invalid", fname, lineno);
186 yaz_log(YLOG_LOG,
"Type is %d", zm->
type);
190 else if (!yaz_matchstr(argv[0],
"completeness") && argc == 2)
194 else if (!yaz_matchstr(argv[0],
"position") && argc == 2)
198 else if (!yaz_matchstr(argv[0],
"alwaysmatches") && argc == 2)
204 yaz_log(YLOG_WARN|YLOG_FATAL,
"%s:%d: alwaysmatches for "
205 "staticrank is invalid", fname, lineno);
209 else if (!yaz_matchstr(argv[0],
"firstinfield") && argc == 2)
213 else if (!yaz_matchstr(argv[0],
"entrysize") && argc == 2)
216 zm->
u.
sort.entry_size = atoi(argv[1]);
220 "%s:%d: entrysize only valid in sort section",
225 else if (!yaz_matchstr(argv[0],
"simplechain"))
232 else if (!yaz_matchstr(argv[0],
"icuchain"))
234 char full_path[1024];
238 yaz_log(YLOG_WARN,
"%s:%d: Could not locate icuchain config '%s'",
239 fname, lineno, argv[1]);
243 zm->doc = xmlParseFile(full_path);
246 yaz_log(YLOG_WARN,
"%s:%d: Could not load icuchain config '%s'",
247 fname, lineno, argv[1]);
254 xmlNode *xml_node = xmlDocGetRootElement(zm->doc);
256 icu_chain_xml_config(xml_node,
266 yaz_log(YLOG_WARN,
"%s:%d: Failed to load ICU chain %s",
267 fname, lineno, argv[1]);
271 yaz_log(YLOG_WARN,
"%s:%d: ICU support unavailable",
277 yaz_log(YLOG_WARN,
"%s:%d: XML support unavailable",
282 else if (!yaz_matchstr(argv[0],
"debug") && argc == 2)
284 zm->
debug = atoi(argv[1]);
288 yaz_log(YLOG_WARN,
"%s:%d: Unrecognized directive '%s'",
289 fname, lineno, argv[0]);
306 yaz_log(YLOG_ERRNO|YLOG_FATAL,
"%s", fname);
309 while ((argc = readconf_line(f, &lineno, line, 512, argv, 10)))
325 const char *profile_path)
329 zms->
nmem = nmem_create();
330 zms->
tabpath = profile_path ? nmem_strdup(zms->
nmem, profile_path) : 0;
352 zm->
u.
sort.entry_size = 80;
359 if (!strcmp(zm->
id,
id))
373 yaz_log(YLOG_WARN,
"Unknown register type: %s",
id);
391 yaz_log(YLOG_WARN,
"Failed to read character table %s",
394 yaz_log(YLOG_DEBUG,
"Read character table %s", zm->
maptab_name);
400 const char **from,
int len,
int first)
413 const char **from,
int len,
int *q_map_match)
509 structure_value =
attr_find(&structure, 0);
510 if (structure_value == 109)
516 const char **index_type,
char **search_type,
char *rank_type,
517 int *complete_flag,
int *sort_flag)
525 int completeness_value;
527 const char *structure_str = 0;
529 int sort_relation_value;
541 structure_value =
attr_find_ex(&structure, NULL, &structure_str);
542 relation_value =
attr_find(&relation, NULL);
543 sort_relation_value =
attr_find(&sort_relation, NULL);
547 if (completeness_value == 2 || completeness_value == 3)
553 *sort_flag =(sort_relation_value > 0) ? 1 : 0;
554 *search_type =
"phrase";
555 strcpy(rank_type,
"void");
556 if (relation_value == 102)
558 if (weight_value == -1)
560 yaz_snprintf(rank_type, 128,
"rank,w=%d,u=%d", weight_value, use_value);
566 switch (structure_value)
569 *search_type =
"and-list";
572 *search_type =
"or-list";
575 *search_type =
"or-list";
581 *search_type =
"phrase";
584 *search_type =
"local";
589 *search_type =
"numeric";
593 *search_type =
"phrase";
597 *search_type =
"phrase";
601 *search_type =
"phrase";
605 *search_type =
"phrase";
608 if (structure_str && *structure_str)
609 *index_type = structure_str;
627 #define SE_CHARS ";,.()-/?<> \r\n\t"
630 const char **result_buf,
size_t *result_len)
637 while (i < len && strchr(
SE_CHARS, buf[i]))
640 while (i < len && !strchr(
SE_CHARS, buf[i]))
642 if (buf[i] > 32 && buf[i] < 127)
643 buf[i] = tolower(buf[i]);
650 *result_buf = buf + start;
651 *result_len = i - start;
659 const char **result_buf,
size_t *result_len,
660 const char **display_buf,
size_t *display_len)
670 while (icu_chain_next_token(zm->icu_chain, &status))
672 if (!U_SUCCESS(status))
674 *result_buf = icu_chain_token_sortkey(zm->icu_chain);
677 *result_len = strlen(*result_buf);
681 *display_buf = icu_chain_token_display(zm->icu_chain);
683 *display_len = strlen(*display_buf);
688 wrbuf_write_escaped(zm->
print_str, *result_buf, *result_len);
689 yaz_log(YLOG_LOG,
"output %s", wrbuf_cstr(zm->
print_str));
692 if (**result_buf !=
'\0')
703 const char *buf,
size_t len)
723 yaz_log(YLOG_LOG,
"input %s",
726 ret = icu_chain_assign_cstr(zm->icu_chain,
728 if (!ret && !U_SUCCESS(status))
732 yaz_log(YLOG_WARN,
"bad encoding for input");
int attr_find(AttrType *src, const Odr_oid **attribute_set_oid)
void attr_init_APT(AttrType *src, Z_AttributesPlusTerm *zapt, int type)
void attr_init_AttrList(AttrType *src, Z_AttributeList *list, int type)
int attr_find_ex(AttrType *src, const Odr_oid **attribute_set_oid, const char **string_value)
void chrmaptab_destroy(chrmaptab tab)
const char ** chr_map_q_input(chrmaptab maptab, const char **from, int len, int first)
const char ** chr_map_input(chrmaptab t, const char **from, int len, int first)
const char * chr_map_output(chrmaptab t, const char **from, int len)
chrmaptab chrmaptab_create(const char *tabpath, const char *name, const char *tabroot)
struct zebra_map::@11::@12 sort
const char * temp_map_ptr[2]
short ZEBRA_RES
Common return type for Zebra API.
int zebra_maps_is_index(zebra_map_t zm)
zebra_map_t zebra_map_get(zebra_maps_t zms, const char *id)
static int parse_command(zebra_maps_t zms, int argc, char **argv, const char *fname, int lineno)
zebra_map_t zebra_add_map(zebra_maps_t zms, const char *index_type, int map_type)
int zebra_maps_is_alwaysmatches(zebra_map_t zm)
int zebra_maps_is_first_in_field(zebra_map_t zm)
int zebra_map_tokenize_next(zebra_map_t zm, const char **result_buf, size_t *result_len, const char **display_buf, size_t *display_len)
void zebra_maps_define_default_sort(zebra_maps_t zms)
chrmaptab zebra_charmap_get(zebra_map_t zm)
#define ZEBRA_MAP_TYPE_INDEX
int zebra_maps_is_sort(zebra_map_t zm)
void zebra_maps_close(zebra_maps_t zms)
int zebra_maps_is_staticrank(zebra_map_t zm)
int zebra_maps_is_positioned(zebra_map_t zm)
#define ZEBRA_MAP_TYPE_SORT
int zebra_maps_is_icu(zebra_map_t zm)
#define ZEBRA_MAP_TYPE_STATICRANK
int zebra_map_tokenize_start(zebra_map_t zm, const char *buf, size_t len)
const char * zebra_maps_output(zebra_map_t zm, const char **from)
int zebra_maps_sort(zebra_maps_t zms, Z_SortAttributes *sortAttributes, int *numerical)
const char ** zebra_maps_search(zebra_map_t zm, const char **from, int len, int *q_map_match)
int zebra_maps_is_complete(zebra_map_t zm)
ZEBRA_RES zebra_maps_read_file(zebra_maps_t zms, const char *fname)
WRBUF zebra_replace(zebra_map_t zm, const char *ex_list, const char *input_str, int input_len)
int zebra_maps_attr(zebra_maps_t zms, Z_AttributesPlusTerm *zapt, const char **index_type, char **search_type, char *rank_type, int *complete_flag, int *sort_flag)
zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, const char *id)
static int tokenize_simple(zebra_map_t zm, const char **result_buf, size_t *result_len)
const char ** zebra_maps_input(zebra_map_t zm, const char **from, int len, int first)
zebra_maps_t zebra_maps_open(Res res, const char *base_path, const char *profile_path)
struct zebra_map * zebra_map_t
struct zebra_maps_s * zebra_maps_t