23#include <yaz/options.h>
29#include <yaz/xmalloc.h>
30#include <yaz/marcdisp.h>
31#include <yaz/timing.h>
62 b->
nmem = nmem_create();
71 nmem_destroy((*bp)->nmem);
77static int cmp_ar(
const void *p1,
const void *p2)
115 memcpy(*dst, &key,
sizeof(key));
117 (*dst) +=
sizeof(key);
132 int no_words = 0, no_new_words = 0;
133 const char *dict_info = 0;
135 yaz_timing_t tim_dict = 0;
136 yaz_timing_t tim_isamb = 0;
150 tim_dict = yaz_timing_create();
161 assert(*dict_info ==
sizeof(word_id_seq));
162 memcpy(&word_id_seq, dict_info+1,
sizeof(word_id_seq));
168 assert(*dict_info ==
sizeof(isamc_p));
169 memcpy(&isamc_p, dict_info+1,
sizeof(isamc_p));
174 if (i > 0 && strcmp(b->
ar[i-1]->
term, b->
ar[i]->
term) == 0)
181 memcpy(&b->
ar[i]->
word_id, dict_info+1,
sizeof(
int));
195 yaz_timing_stop(tim_dict);
196 tim_isamb = yaz_timing_create();
213 yaz_timing_stop(tim_isamb);
221 printf(
"# run total dict-real user sys isam-real user sys "
222 " intsp leafsp docs postings words new d-spl\n");
225 printf(
"%5d %9.6f %9.6f %5.2f %5.2f %9.6f %5.2f %5.2f "
229 yaz_timing_get_real(tim_dict) + yaz_timing_get_real(tim_isamb),
230 yaz_timing_get_real(tim_dict),
231 yaz_timing_get_user(tim_dict),
232 yaz_timing_get_sys(tim_dict),
233 yaz_timing_get_real(tim_isamb),
234 yaz_timing_get_user(tim_isamb),
235 yaz_timing_get_sys(tim_isamb),
236 number_of_int_splits,
237 number_of_leaf_splits,
242 number_of_dict_splits
252 yaz_timing_destroy(&tim_isamb);
253 yaz_timing_destroy(&tim_dict);
259 int total = nmem_total(b->
nmem);
294 const char *cp = wrbuf_buf(wrbuf);
306 for (i = 0; i<6 && *cp; i++, cp++)
311 for (i = 0; i<4 && *cp; i++, cp++)
326 else if (*cp == subfield_char && cp[1])
335 else if (strchr(
"$*/-;,.:[]\"&(){} ", *cp))
346 unsigned ch = *(
const unsigned char *)cp;
347 if (sz <
sizeof(
term))
349 term[sz] = tolower(ch);
366 WRBUF wrbuf = wrbuf_alloc();
371 while(fgets(line,
sizeof(line)-1,
inf))
392 wrbuf_puts(wrbuf, line);
398 if (wrbuf_len(wrbuf))
403 if (line[0] !=
' ' && line[1] !=
' ' && line[2] !=
' ' &&
407 wrbuf_puts(wrbuf, line);
411 if (wrbuf_len(wrbuf))
427 int verbose,
int print_offset)
429 yaz_marc_t mt = yaz_marc_create();
430 WRBUF wrbuf = wrbuf_alloc();
440 r = fread (buf, 1, 5,
inf);
443 if (r && print_offset && verbose)
444 printf (
"<!-- Extra %ld bytes at end of file -->\n",
448 while (*buf <
'0' || *buf >
'9')
451 long off = ftell(
inf) - 5;
452 if (verbose || print_offset)
453 printf(
"<!-- Skipping bad byte %d (0x%02X) at offset "
455 *buf & 0xff, *buf & 0xff,
457 for (i = 0; i<4; i++)
459 r = fread(buf+4, 1, 1,
inf);
465 if (verbose || print_offset)
466 printf (
"<!-- End of file with data -->\n");
469 len = atoi_n(buf, 5);
470 if (len < 25 || len > 100000)
472 long off = ftell(
inf) - 5;
473 printf(
"Bad Length %ld read at offset %ld (%lx)\n",
474 (
long)len, (
long) off, (
long) off);
478 r = fread (buf + 5, 1, rlen,
inf);
481 yaz_marc_read_iso2709(mt, buf, len);
483 if (yaz_marc_write_line(mt, wrbuf))
494 wrbuf_destroy(wrbuf);
495 yaz_marc_destroy(mt);
501 fprintf(stderr,
"benchindex1 [-t type] [-c d:i] [-m mem] [-i] [inputfile]\n");
515 int isam_cache_size = 40;
516 int dict_cache_size = 50;
517 const char *fname = 0;
519 yaz_timing_t tim = 0;
521 const char *dict_info;
522 const char *type =
"iso2709";
523 int int_count_enable = 1;
524 char version_str[16];
527 while ((ret = options(
"im:t:c:N", argv, argc, &arg)) != -2)
538 if (!strcmp(arg,
"iso2709"))
540 else if (!strcmp(arg,
"line"))
544 fprintf(stderr,
"bad type: %s.\n", arg);
549 if (sscanf(arg,
"%d:%d", &dict_cache_size, &isam_cache_size)
552 fprintf(stderr,
"bad cache sizes for -c\n");
560 int_count_enable = 0;
563 fprintf(stderr,
"bad option.\n");
570 inf = fopen(fname,
"rb");
573 fprintf(stderr,
"Cannot open %s\n", fname);
577 printf(
"# benchindex1 %s\n", version_str);
578 printf(
"# isam_cache_size = %d\n", isam_cache_size);
579 printf(
"# dict_cache_size = %d\n", dict_cache_size);
580 printf(
"# int_count_enable = %d\n", int_count_enable);
581 printf(
"# memory = %d\n", memory);
593 method_postings.
debug = 0;
599 yaz_log(YLOG_WARN,
"bfs_create failed");
606 tim = yaz_timing_create();
608 isb_postings =
isamb_open (bfs,
"isamb", isam_cache_size ? 1 : 0,
609 &method_postings, 0);
612 yaz_log(YLOG_WARN,
"isamb_open failed");
622 assert(*dict_info ==
sizeof(docid_seq));
623 memcpy(&docid_seq, dict_info+1,
sizeof(docid_seq));
626 if (!strcmp(type,
"iso2709"))
629 else if (!strcmp(type,
"line"))
632 printf(
"# Total " ZINT_FORMAT " documents\n", docid_seq);
642 yaz_timing_stop(tim);
644 printf(
"# Total timings real=%8.6f user=%3.2f system=%3.2f\n",
645 yaz_timing_get_real(tim),
646 yaz_timing_get_user(tim),
647 yaz_timing_get_sys(tim));
649 yaz_timing_destroy(&tim);
void index_term(struct index_block *b, const char *term, zint docid, zint *seqno)
static int cmp_ar(const void *p1, const void *p2)
void index_block_add(struct index_block *b, const char *term, zint docid, zint seqno)
void index_block_flush(struct index_block *b, ISAMB isb, Dict dict, int no_docs)
int main(int argc, char **argv)
void index_marc_from_file(ISAMB isb, Dict dict, zint *docid_seq, FILE *inf, int memory, int verbose, int print_offset)
void index_marc_line_records(ISAMB isb, Dict dict, zint *docid_seq, FILE *inf, int memory)
void index_block_destroy(struct index_block **bp)
void index_wrbuf(struct index_block *b, WRBUF wrbuf, zint docid, int subfield_char)
void index_block_check_flush(struct index_block *b, ISAMB isb, Dict dict, int no_docs)
int code_read(void *vp, char **dst, int *insertMode)
struct index_block * index_block_new(int memory)
struct BFiles_struct * BFiles
A collection of BFile(s).
void bf_reset(BFiles bfs)
Removes register and shadow completely.
BFiles bfs_create(const char *spec, const char *base)
creates a Block files collection
void bfs_destroy(BFiles bfiles)
destroys a block files handle
zint dict_get_no_split(Dict dict)
get number of page split operations, since dict_open
Dict dict_open(BFiles bfs, const char *name, int cache, int rw, int compact_flag, int page_size)
open dictionary
struct Dict_struct * Dict
Dictionary handle.
int dict_insert(Dict dict, const char *p, int userlen, void *userinfo)
insert item into dictionary
char * dict_lookup(Dict dict, const char *p)
lookup item in dictionary
int dict_close(Dict dict)
closes dictionary
void isamb_set_int_count(ISAMB b, int v)
zint isamb_get_leaf_splits(ISAMB b)
ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method, int cache)
zint isamb_get_int_splits(ISAMB b)
void isamb_close(ISAMB isamb)
void isamb_set_cache_size(ISAMB b, int sz)
void isamb_merge(ISAMB b, ISAM_P *pos, ISAMC_I *data)
void iscz1_decode(void *vp, char **dst, const char **src)
void iscz1_encode(void *vp, char **dst, const char **src)
int key_compare(const void *p1, const void *p2)
void key_logdump_txt(int logmask, const void *p, const char *txt)
void iscz1_reset(void *vp)
int(* read_item)(void *clientData, char **dst, int *insertMode)
int(* compare_item)(const void *a, const void *b)
void(* log_item)(int logmask, const void *p, const char *txt)
void(* decode)(void *p, char **dst, const char **src)
void(* encode)(void *p, char **dst, const char **src)
struct index_term * terms
zint mem[IT_KEY_LEVEL_MAX]
void zebra_get_version(char *version_str, char *sha1_str)
Returns Zebra version and SHA1 ID as generated by Git.