-/* $Id: rpnscan.c,v 1.8 2007-04-16 21:54:37 adam Exp $
+/* $Id: rpnscan.c,v 1.13 2007-09-18 18:57:29 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
*count = rset->hits_count;
}
+static void get_first_snippet_from_rset(ZebraHandle zh,
+ RSET rset, zebra_snippets *snippets,
+ zint *sysno)
+{
+ struct it_key key;
+ RSFD rfd;
+ TERMID termid;
+ size_t sysno_mem_index = 0;
+
+ if (zh->m_staticrank)
+ sysno_mem_index = 1;
+
+ yaz_log(YLOG_DEBUG, "get_first_snippet_from_rset");
+
+ rfd = rset_open(rset, RSETF_READ);
+ *sysno = 0;
+ while (rset_read(rfd, &key, &termid))
+ {
+ if (key.mem[sysno_mem_index] != *sysno)
+ {
+ if (*sysno)
+ break;
+ *sysno = key.mem[sysno_mem_index];
+ }
+ if (termid)
+ {
+ struct ord_list *ol;
+ for (ol = termid->ol; ol; ol = ol->next)
+ {
+ zebra_snippets_append(snippets, key.mem[key.len-1], 0,
+ ol->ord, termid->name);
+ }
+ }
+ }
+ rset_close (rfd);
+}
+
struct scan2_info_entry {
WRBUF term;
char prefix[20];
ISAM_P isam_p;
int pos_to_save;
+ int ord;
};
static int scan_handle2(char *name, const char *info, int pos, void *client)
{
if (ar[i].isam_p && strcmp(wrbuf_cstr(ar[i].term), term) == 0)
{
- RSET rset_t = rset_trunc(
+ 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, 0, zapt->term->which, nmem,
- kc, kc->scope, 0, index_type,
+ NULL, 1, zapt->term->which, nmem,
+ kc, kc->scope, ol, index_type,
0 /* hits_limit */,
0 /* term_ref_id_str */);
if (!rset)
}
/* count it */
count_set(zh, rset, &count);
- rset_delete(rset);
- if (count > 0)
+
+ if (pos != -1)
{
- 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;
+ glist[pos].display_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)
+ {
+ glist[pos].display_term = odr_strdup(stream, w->term);
+ }
+ }
+ if (!glist[pos].term)
zebra_term_untrans_iconv(zh, stream->mem, index_type,
&glist[pos].term, term);
- glist[pos].occurrences = count;
- }
- return 1;
+ glist[pos].occurrences = count;
+ zebra_snippets_destroy(rec_snippets);
+ zebra_snippets_destroy(hit_snippets);
}
+ rset_delete(rset);
+ if (count > 0)
+ return 1;
+ else
+ return 0;
}
return 0;
}
struct scan2_info_entry *ar = nmem_malloc(nmem, sizeof(*ar) * ord_no);
struct rpn_char_map_info rcmi;
int i, dif;
+ int after_pos;
int pos = 0;
ZebraScanEntry *glist = (ZebraScanEntry *)
if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) ==
ZEBRA_FAIL)
+ {
+ for (i = 0; i < ord_no; i++)
+ wrbuf_destroy(ar[i].term);
return ZEBRA_FAIL;
+ }
wrbuf_rewind(ar[i].term);
wrbuf_puts(ar[i].term, termz + prefix_len);
ar[i].isam_p = 0;
+ ar[i].ord = ords[i];
}
/** deal with terms before position .. */
/* the glist index starts at zero (unlike scan positions */
wrbuf_rewind(ar[i].term);
wrbuf_puts(ar[i].term, termz + prefix_len);
ar[i].isam_p = 0;
+ ar[i].ord = ords[i];
}
+ after_pos = 1; /* immediate term first.. */
for (pos = *position-1; pos < *num_entries; )
{
const char *lo = 0;
{
char termz[IT_MAX_WORD+20];
int before = 0;
- int after = (pos == *position-1) ? 1 : 2;
+ int after = after_pos;
ar[i].pos_to_save = 1;
ar+i, scan_handle2);
}
}
+ after_pos = 2; /* next round we grab following term */
+
/* get minimum after scan */
for (i = 0; i < ord_no; i++)
{
*list = glist;
+ for (i = 0; i < ord_no; i++)
+ wrbuf_destroy(ar[i].term);
+
return ZEBRA_OK;
}
};
ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
- const int *attributeset,
+ const Odr_oid *attributeset,
int num_bases, char **basenames,
int *position, int *num_entries, ZebraScanEntry **list,
int *is_partial, RSET limit_set)
if (termset_value_numeric != -2)
{
-
sprintf(resname, "%d", termset_value_numeric);
termset_name = resname;
}
termset_name = termset_value_string;
limit_set = resultSetRef (zh, termset_name);
+
+ if (!limit_set)
+ {
+ zebra_setError(zh,
+ YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ termset_name);
+ return ZEBRA_FAIL;
+ }
}
}