-/* $Id: rpnscan.c,v 1.23 2007-12-03 11:49:11 adam Exp $
- Copyright (C) 1995-2007
- Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+ Copyright (C) 1994-2011 Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdio.h>
#include <assert.h>
#ifdef WIN32
static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
char *termz, zebra_map_t zm)
{
- char termz0[IT_MAX_WORD];
+ char term_utf8[IT_MAX_WORD];
- if (zapt_term_to_utf8(zh, zapt, termz0) == ZEBRA_FAIL)
+ if (zapt_term_to_utf8(zh, zapt, term_utf8) == ZEBRA_FAIL)
return ZEBRA_FAIL; /* error */
+ else if (zebra_maps_is_icu(zm))
+ {
+ const char *res_buf;
+ size_t res_len;
+ zebra_map_tokenize_start(zm, term_utf8, strlen(term_utf8));
+
+ if (zebra_map_tokenize_next(zm, &res_buf, &res_len, 0, 0))
+ {
+ memcpy(termz, res_buf, res_len);
+ termz[res_len] = '\0';
+ }
+ else
+ termz[0] = '\0';
+ }
else
{
const char **map;
- const char *cp = (const char *) termz0;
+ const char *cp = (const char *) term_utf8;
const char *cp_end = cp + strlen(cp);
const char *src;
int i = 0;
len_prefix = strlen(scan_info->prefix);
if (memcmp(name, scan_info->prefix, len_prefix))
return 1;
-
- /* skip special terms such as first-in-field specials */
- if (name[len_prefix] < CHR_BASE_CHAR)
- return 1;
-
wrbuf_rewind(scan_info->term);
wrbuf_puts(scan_info->term, name+len_prefix);
{
if (ar[i].isam_p && strcmp(wrbuf_cstr(ar[i].term), term) == 0)
{
- struct ord_list *ol = ord_list_create(nmem);
- RSET rset_t;
-
- ol = ord_list_append(nmem, ol, ar[i].ord);
-
- assert(ol);
- rset_t = rset_trunc(
+ if (strcmp(term, FIRST_IN_FIELD_STR))
+ {
+ struct ord_list *ol = ord_list_create(nmem);
+ RSET rset_t;
+
+ ol = ord_list_append(nmem, ol, ar[i].ord);
+
+ assert(ol);
+ rset_t = rset_trunc(
zh, &ar[i].isam_p, 1,
wrbuf_buf(ar[i].term), wrbuf_len(ar[i].term),
NULL, 1, zapt->term->which, nmem,
kc, kc->scope, ol, index_type,
0 /* hits_limit_value */,
0 /* term_ref_id_str */);
- if (!rset)
- rset = rset_t;
- else
- {
- RSET rsets[2];
-
- rsets[0] = rset;
- rsets[1] = rset_t;
- rset = rset_create_or(nmem, kc, kc->scope, 0 /* termid */,
- 2, rsets);
+ if (!rset)
+ rset = rset_t;
+ else
+ {
+ RSET rsets[2];
+
+ rsets[0] = rset;
+ rsets[1] = rset_t;
+ rset = rset_create_or(nmem, kc, kc->scope, 0 /* termid */,
+ 2, rsets);
+ }
}
ar[i].isam_p = 0;
}
if (pos != -1)
{
zint sysno;
- int code = -1;
- zebra_snippets *rec_snippets = zebra_snippets_create();
zebra_snippets *hit_snippets = zebra_snippets_create();
glist[pos].term = 0;
get_first_snippet_from_rset(zh, rset, hit_snippets, &sysno);
if (sysno)
- code = zebra_get_rec_snippets(zh, sysno, rec_snippets);
-
- if (code == 0)
{
- const struct zebra_snippet_word *w =
- zebra_snippets_lookup(rec_snippets, hit_snippets);
- if (w)
+ zebra_snippets *rec_snippets = zebra_snippets_create();
+ int code = zebra_get_rec_snippets(zh, sysno, rec_snippets);
+ if (code == 0)
{
- glist[pos].display_term = odr_strdup(stream, w->term);
+ const struct zebra_snippet_word *w =
+ zebra_snippets_lookup(rec_snippets, hit_snippets);
+ if (w)
+ {
+ glist[pos].display_term = odr_strdup(stream, w->term);
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "zebra_snippets_lookup failed for pos=%d", pos);
+ }
}
+ zebra_snippets_destroy(rec_snippets);
}
+ if (zebra_term_untrans_iconv(zh, stream->mem, index_type,
+ &glist[pos].term, term))
+ {
+ /* failed.. use display_term instead (which could be 0) */
+ glist[pos].term = glist[pos].display_term;
+ }
+
if (!glist[pos].term)
- zebra_term_untrans_iconv(zh, stream->mem, index_type,
- &glist[pos].term, term);
+ {
+ yaz_log(YLOG_WARN, "Could not generate scan term for pos=%d",
+ pos);
+ glist[pos].term = "None";
+ }
glist[pos].occurrences = count;
- zebra_snippets_destroy(rec_snippets);
zebra_snippets_destroy(hit_snippets);
}
rset_delete(rset);
odr_malloc(stream, *num_entries * sizeof(*glist));
*is_partial = 0;
- if (*position > *num_entries+1)
- {
- *is_partial = 1;
- *position = 1;
- *num_entries = 0;
- return ZEBRA_OK;
- }
rpn_char_map_prepare(zh->reg, zm, &rcmi);
for (i = 0; i < ord_no; i++)
{
/* did not get all terms; adjust the real position and reduce
number of entries */
- yaz_log(YLOG_LOG, "before terms dif=%d", dif);
- glist = glist + dif;
- *num_entries -= dif;
+ if (dif < *num_entries)
+ {
+ glist = glist + dif;
+ *num_entries -= dif;
+ }
+ else
+ *num_entries = 0;
*position -= dif;
*is_partial = 1;
}
pos++;
}
- if (pos != *num_entries)
+ if (pos < *num_entries)
{
if (pos >= 0)
*num_entries = pos;
zebra_setError(zh, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0);
return ZEBRA_FAIL;
}
- if (sort_flag)
- {
- return rpn_facet(zh, stream, zapt, attributeset, position, num_entries,
- list, is_partial, set_name);
- }
for (base_no = 0; base_no < num_bases; base_no++)
{
int ord;
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab