-/* $Id: sortidx.c,v 1.22 2006-12-19 16:57:38 adam Exp $
- Copyright (C) 1995-2006
- Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+ Copyright (C) 1995-2008 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
yaz_log(level, "%s " ZINT_FORMAT " %s", txt, a1.sysno, a1.term);
}
-int sort_term_compare(const void *a, const void *b)
+static int sort_term_compare(const void *a, const void *b)
{
struct sort_term a1, b1;
return 0;
}
-void *sort_term_code_start(void)
+static void *sort_term_code_start(void)
{
return 0;
}
-void sort_term_encode(void *p, char **dst, const char **src)
+static void sort_term_encode(void *p, char **dst, const char **src)
{
struct sort_term a1;
*dst += strlen(a1.term) + 1;
}
-void sort_term_decode(void *p, char **dst, const char **src)
+static void sort_term_decode(void *p, char **dst, const char **src)
{
struct sort_term a1;
*dst += sizeof(a1);
}
-void sort_term_code_reset(void *p)
+static void sort_term_code_reset(void *p)
{
}
-void sort_term_code_stop(void *p)
+static void sort_term_code_stop(void *p)
{
}
-
struct sort_term_stream {
int no;
int insert_flag;
struct sort_term st;
};
-int sort_term_code_read(void *vp, char **dst, int *insertMode)
+static int sort_term_code_read(void *vp, char **dst, int *insertMode)
{
struct sort_term_stream *s = (struct sort_term_stream *) vp;
return 1;
}
-
struct sortFileHead {
zint sysno_max;
};
int zebra_sort_type(zebra_sort_index_t si, int id)
{
int isam_block_size = 4096;
+
ISAMC_M method;
char fname[80];
struct sortFile *sf;
sf = (struct sortFile *) xmalloc(sizeof(*sf));
sf->id = id;
- method.compare_item = sort_term_compare;
- method.log_item = sort_term_log_item;
- method.codec.start = sort_term_code_start;
- method.codec.encode = sort_term_encode;
- method.codec.decode = sort_term_decode;
- method.codec.reset = sort_term_code_reset;
- method.codec.stop = sort_term_code_stop;
-
switch(si->type)
{
case ZEBRA_SORT_TYPE_FLAT:
}
break;
case ZEBRA_SORT_TYPE_ISAMB:
- sprintf(fname, "sortb%d", id);
+ method.compare_item = sort_term_compare;
+ method.log_item = sort_term_log_item;
+ method.codec.start = sort_term_code_start;
+ method.codec.encode = sort_term_encode;
+ method.codec.decode = sort_term_decode;
+ method.codec.reset = sort_term_code_reset;
+ method.codec.stop = sort_term_code_stop;
+ sprintf(fname, "sortb%d", id);
sf->u.isamb = isamb_open2(si->bfs, fname, si->write_flag, &method,
/* cache */ 0,
/* no_cat */ 1, &isam_block_size,
else
{
sf->isam_p = isamb_get_root_ptr(sf->u.isamb);
- sf->isam_pp = 0;
}
break;
}
+ sf->isam_pp = 0;
sf->no_inserted = 0;
sf->no_deleted = 0;
sf->next = si->files;
{
sf->no_inserted = 0;
sf->no_deleted = 0;
- if (new_sysno < si->sysno && sf->isam_pp)
+ if (sf->isam_pp && new_sysno < si->sysno && sf->isam_pp)
{
isamb_pp_close(sf->isam_pp);
sf->isam_pp = 0;
}
}
-void zebra_sort_read(zebra_sort_index_t si, char *buf)
+int zebra_sort_read(zebra_sort_index_t si, char *buf)
{
int r;
struct sortFile *sf = si->current_file;
assert(sf);
+ assert(sf->u.bf);
switch(si->type)
{
r = bf_read(sf->u.bf, si->sysno+1, 0, 0, buf);
if (!r)
memset(buf, 0, SORT_IDX_ENTRYSIZE);
+ if (buf[0] == 0)
+ return 0;
break;
case ZEBRA_SORT_TYPE_ISAMB:
memset(buf, 0, SORT_IDX_ENTRYSIZE);
- assert(sf->u.bf);
- if (sf->u.bf)
+ if (!sf->isam_p)
+ return 0;
+ else
{
struct sort_term st, st_untilbuf;
- st.sysno = 99999;
if (!sf->isam_pp)
- {
sf->isam_pp = isamb_pp_open(sf->u.isamb, sf->isam_p, 1);
- }
if (!sf->isam_pp)
- return;
+ return 0;
-#if 0
- while (1)
- {
- r = isamb_pp_read(sf->isam_pp, &st);
- if (!r)
- break;
- if (st.sysno == si->sysno)
- break;
- yaz_log(YLOG_LOG, "Received sysno=" ZINT_FORMAT " looking for "
- ZINT_FORMAT, st.sysno, si->sysno);
- }
-#else
st_untilbuf.sysno = si->sysno;
st_untilbuf.term[0] = '\0';
r = isamb_pp_forward(sf->isam_pp, &st, &st_untilbuf);
if (!r)
- return;
-#endif
+ return 0;
if (r)
{
if (st.sysno != si->sysno)
{
yaz_log(YLOG_LOG, "Received sysno=" ZINT_FORMAT " looking for "
ZINT_FORMAT, st.sysno, si->sysno);
- return;
+ return 0;
}
if (strlen(st.term) < SORT_IDX_ENTRYSIZE)
strcpy(buf, st.term);
}
break;
}
+ return 1;
}
/*
* Local variables: