33 #include <yaz/diagbib1.h>
36 #include <yaz/wrbuf.h>
37 #include <yaz/snprintf.h>
41 #include <yaz/oid_db.h>
43 #define RPN_MAX_ORDS 32
61 memcpy(termz, res_buf, res_len);
62 termz[res_len] =
'\0';
70 const char *cp = (
const char *) term_utf8;
71 const char *cp_end = cp + strlen(cp);
74 const char *space_map = NULL;
77 while ((len = (cp_end - cp)) > 0)
85 for (src = space_map; *src; src++)
88 for (src = *map; *src; src++)
104 size_t sysno_mem_index = 0;
109 yaz_log(YLOG_DEBUG,
"get_first_snippet_from_rset");
115 if (key.
mem[sysno_mem_index] != *sysno)
119 *sysno = key.
mem[sysno_mem_index];
124 for (ol = termid->
ol; ol; ol = ol->
next)
142 static int scan_handle2(
char *name,
const char *info,
int pos,
void *client)
154 wrbuf_puts(
scan_info->term, name+len_prefix);
156 assert(*info ==
sizeof(
ISAM_P));
164 Z_AttributesPlusTerm *zapt,
167 const char *index_type,
178 l =
attr_find(&global_hits_limit_attr, NULL);
182 for (i = 0; i < ord_no; i++)
195 zh, &ar[i].isam_p, 1,
196 wrbuf_buf(ar[i].term), wrbuf_len(ar[i].term),
197 NULL, 1, zapt->
term->which, nmem,
198 kc, kc->
scope, ol, index_type,
255 yaz_log(YLOG_WARN,
"zebra_snippets_lookup failed for pos=%d", pos);
267 if (!glist[pos].
term)
269 yaz_log(YLOG_WARN,
"Could not generate scan term for pos=%d",
271 glist[pos].
term =
"None";
287 Z_AttributesPlusTerm *zapt,
288 int *position,
int *num_entries,
290 int *is_partial,
RSET limit_set,
291 const char *index_type,
292 int ord_no,
int *ords)
302 odr_malloc(stream, *num_entries *
sizeof(*glist));
307 for (i = 0; i < ord_no; i++)
308 ar[i].term = wrbuf_alloc();
310 for (i = 0; i < ord_no; i++)
316 termz[prefix_len] = 0;
317 strcpy(ar[i].prefix, termz);
322 for (i = 0; i < ord_no; i++)
323 wrbuf_destroy(ar[i].term);
326 wrbuf_rewind(ar[i].term);
327 wrbuf_puts(ar[i].term, termz + prefix_len);
333 for (pos = *position-2; pos >= 0; )
338 for (i = 0; i < ord_no; i++)
340 if (ar[i].isam_p == 0)
348 strcpy(termz, ar[i].prefix);
349 strcat(termz, wrbuf_cstr(ar[i].term));
355 for (i = 0; i < ord_no; i++)
358 && (hi == 0 || strcmp(wrbuf_cstr(ar[i].term), hi) > 0))
359 hi = wrbuf_cstr(ar[i].term);
364 index_type, ar, ord_no, glist,
365 (pos >= 0 && pos < *num_entries) ? pos : -1))
374 if (dif < *num_entries)
384 for (i = 0; i < ord_no; i++)
390 termz[prefix_len] = 0;
391 strcpy(ar[i].prefix, termz);
396 wrbuf_rewind(ar[i].term);
397 wrbuf_puts(ar[i].term, termz + prefix_len);
403 for (pos = *position-1; pos < *num_entries; )
408 for (i = 0; i < ord_no; i++)
410 if (ar[i].isam_p == 0)
414 int after = after_pos;
418 strcpy(termz, ar[i].prefix);
419 strcat(termz, wrbuf_cstr(ar[i].term));
427 for (i = 0; i < ord_no; i++)
430 && (lo == 0 || strcmp(wrbuf_cstr(ar[i].term), lo) < 0))
431 lo = wrbuf_cstr(ar[i].term);
436 index_type, ar, ord_no, glist,
437 (pos >= 0 && pos < *num_entries) ? pos : -1))
441 if (pos < *num_entries)
452 for (i = 0; i < ord_no; i++)
453 wrbuf_destroy(ar[i].term);
471 const Odr_oid *attributeset,
472 int num_bases,
char **basenames,
474 int *is_partial,
const char *set_name)
479 const char *index_type;
480 char *search_type = NULL;
493 attributeset = yaz_oid_attset_bib_1;
499 int termset_value_numeric;
500 const char *termset_value_string = 0;
502 termset_value_numeric =
504 if (termset_value_numeric != -1)
506 if (termset_value_numeric != -2)
509 yaz_snprintf(resname,
sizeof(resname),
"%d", termset_value_numeric);
510 set_name = odr_strdup(stream, resname);
513 set_name = odr_strdup(stream, termset_value_string);
524 YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
530 yaz_log(YLOG_DEBUG,
"position = %d, num = %d",
531 *position, *num_entries);
534 rank_type, &complete_flag, &sort_flag))
545 for (base_no = 0; base_no < num_bases; base_no++)
559 ords[ord_no++] = ord;
566 if (*num_entries < 1)
571 nmem = nmem_create();
574 res =
rpn_scan_norm(zh, stream, nmem, kc, zapt, position, num_entries,
575 list, is_partial, limit_set,
576 index_type, ord_no, ords);
int attr_find(AttrType *src, const Odr_oid **attribute_set_oid)
void attr_init_APT(AttrType *src, Z_AttributesPlusTerm *zapt, int type)
int attr_find_ex(AttrType *src, const Odr_oid **attribute_set_oid, const char **string_value)
ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char *index_type, const char *xpath_use, const Odr_oid *curAttributeSet, int *ord)
int dict_scan(Dict dict, char *str, int *before, int *after, void *client, int(*f)(char *name, const char *info, int pos, void *client))
dictionary scan
RSET resultSetRef(ZebraHandle zh, const char *resultSetId)
void rpn_char_map_prepare(struct zebra_register *reg, zebra_map_t zm, struct rpn_char_map_info *map_info)
#define FIRST_IN_FIELD_STR
void zebra_count_set(ZebraHandle zh, RSET rset, zint *count, zint approx_limit)
ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt, char *termz)
void zebra_setError(ZebraHandle zh, int code, const char *addinfo)
RSET rset_trunc(ZebraHandle zh, ISAM_P *isam_p, int no, const char *term, int length_term, const char *flags, int preserve_position, int term_type, NMEM rset_nmem, struct rset_key_control *kctrl, int scope, struct ord_list *ol, const char *index_type, zint hits_limit, const char *term_ref_id)
int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, const char *index_type, char **dst, const char *src)
int zebra_get_rec_snippets(ZebraHandle zh, zint sysno, zebra_snippets *snippets)
struct rset_key_control * zebra_key_control_create(ZebraHandle zh)
int key_SU_encode(int ch, char *out)
ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, const Odr_oid *attributeset, int num_bases, char **basenames, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial, const char *set_name)
static void get_first_snippet_from_rset(ZebraHandle zh, RSET rset, zebra_snippets *snippets, zint *sysno)
static int scan_save_set(ZebraHandle zh, ODR stream, NMEM nmem, struct rset_key_control *kc, Z_AttributesPlusTerm *zapt, RSET limit_set, const char *term, const char *index_type, struct scan2_info_entry *ar, int ord_no, ZebraScanEntry *glist, int pos)
static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, char *termz, zebra_map_t zm)
static int scan_handle2(char *name, const char *info, int pos, void *client)
static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem, struct rset_key_control *kc, Z_AttributesPlusTerm *zapt, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial, RSET limit_set, const char *index_type, int ord_no, int *ords)
void rset_delete(RSET rs)
Destructor RSETs.
RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets)
RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol, int scope, int no_rsets, RSET *rsets)
#define rset_read(rfd, buf, term)
RSET rset_dup(RSET rs)
Duplicate an RSET.
struct ord_list * ord_list_append(NMEM nmem, struct ord_list *list, int ord)
struct ord_list * ord_list_create(NMEM nmem)
#define rset_open(rs, wflag)
void rset_close(RSFD rfd)
Closes a result set RFD handle.
void zebra_snippets_destroy(zebra_snippets *l)
void zebra_snippets_append(zebra_snippets *l, zint seqno, int ws, int ord, const char *term)
const struct zebra_snippet_word * zebra_snippets_lookup(const zebra_snippets *doc, const zebra_snippets *hit)
zebra_snippets * zebra_snippets_create(void)
zint mem[IT_KEY_LEVEL_MAX]
void(* dec)(struct rset_key_control *kc)
struct scan1_info_entry * list
struct zebra_register * reg
short ZEBRA_RES
Common return type for Zebra API.
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)
int zebra_maps_attr(zebra_maps_t zms, Z_AttributesPlusTerm *zapt, const char **reg_id, char **search_type, char *rank_type, int *complete_flag, int *sort_flag)
int zebra_maps_is_icu(zebra_map_t zm)
int zebra_map_tokenize_start(zebra_map_t zm, const char *buf, size_t len)
zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, const char *id)
const char ** zebra_maps_input(zebra_map_t zm, const char **from, int len, int first)
int zebraExplain_curDatabase(ZebraExplainInfo zei, const char *database)