X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fretrieve.c;h=ebea719ee9d9563aa9487001420b998bc3af0da5;hb=4b903c542156253ebb2a4f004b528fe9e3af5212;hp=d3ca5ad13531457a08fe0802bf29599f3d66e781;hpb=6988ba91e363565638c27a8d5895ad9afc409e75;p=idzebra-moved-to-github.git diff --git a/index/retrieve.c b/index/retrieve.c index d3ca5ad..ebea719 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -1,4 +1,4 @@ -/* $Id: retrieve.c,v 1.71 2007-08-21 11:06:47 adam Exp $ +/* $Id: retrieve.c,v 1.73 2007-10-29 09:25:40 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -62,8 +62,8 @@ static int zebra_create_record_stream(ZebraHandle zh, else strcpy(full_rep, (*rec)->info[recInfo_filename]); - if ((fd = open (full_rep, O_BINARY|O_RDONLY)) == -1){ - yaz_log (YLOG_WARN|YLOG_ERRNO, "Retrieve fail; missing file: %s", + if ((fd = open(full_rep, O_BINARY|O_RDONLY)) == -1){ + yaz_log(YLOG_WARN|YLOG_ERRNO, "Retrieve fail; missing file: %s", full_rep); rec_free(rec); return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; @@ -444,17 +444,11 @@ static void snippet_xml_record(ZebraHandle zh, WRBUF wrbuf, zebra_snippets *doc) wrbuf_printf(wrbuf, ""); } -int zebra_special_snippet_fetch(ZebraHandle zh, const char *setname, - zint sysno, ODR odr, - const char *elemsetname, - const Odr_oid *input_format, - const Odr_oid **output_format, - char **rec_bufp, int *rec_lenp) +int zebra_get_rec_snippets(ZebraHandle zh, zint sysno, + zebra_snippets *snippets) { int return_code = 0; - Record rec; - - rec = rec_get(zh->reg->records, sysno); + Record rec = rec_get(zh->reg->records, sysno); if (!rec) { yaz_log(YLOG_WARN, "rec_get fail on sysno=" ZINT_FORMAT, sysno); @@ -466,60 +460,73 @@ int zebra_special_snippet_fetch(ZebraHandle zh, const char *setname, void *recTypeClientData; RecType rt = recType_byName(zh->reg->recTypes, zh->res, file_type, &recTypeClientData); - zebra_snippets *hit_snippet = zebra_snippets_create(); - WRBUF wrbuf = wrbuf_alloc(); - zebra_snippets_hit_vector(zh, setname, sysno, hit_snippet); - if (!rt) return_code = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; else { struct ZebraRecStream stream; - return_code = zebra_create_record_stream(zh, &rec, &stream); if (return_code == 0) { - zebra_snippets *rec_snippet = zebra_snippets_create(); - extract_snippet(zh, rec_snippet, &stream, + extract_snippet(zh, snippets, &stream, rt, recTypeClientData); -#if 0 - /* for debugging purposes */ - yaz_log(YLOG_LOG, "---------------------------"); - yaz_log(YLOG_LOG, "REC SNIPPET:"); - zebra_snippets_log(rec_snippet, YLOG_LOG, 1); - yaz_log(YLOG_LOG, "---------------------------"); - yaz_log(YLOG_LOG, "HIT SNIPPET:"); - zebra_snippets_log(hit_snippet, YLOG_LOG, 1); -#endif + stream.destroy(&stream); + } + } + rec_free(&rec); + } + return return_code; +} + +int zebra_special_snippet_fetch(ZebraHandle zh, const char *setname, + zint sysno, ODR odr, + const char *elemsetname, + const Odr_oid *input_format, + const Odr_oid **output_format, + char **rec_bufp, int *rec_lenp) +{ + zebra_snippets *rec_snippets = zebra_snippets_create(); + int return_code = zebra_get_rec_snippets(zh, sysno, rec_snippets); + + if (!return_code) + { + WRBUF wrbuf = wrbuf_alloc(); + zebra_snippets *hit_snippet = zebra_snippets_create(); - zebra_snippets_ring(rec_snippet, hit_snippet, 5, 5); + zebra_snippets_hit_vector(zh, setname, sysno, hit_snippet); #if 0 - yaz_log(YLOG_LOG, "---------------------------"); - yaz_log(YLOG_LOG, "RING SNIPPET:"); - zebra_snippets_log(rec_snippet, YLOG_LOG, 1); + /* for debugging purposes */ + yaz_log(YLOG_LOG, "---------------------------"); + yaz_log(YLOG_LOG, "REC SNIPPET:"); + zebra_snippets_log(rec_snippet, YLOG_LOG, 1); + yaz_log(YLOG_LOG, "---------------------------"); + yaz_log(YLOG_LOG, "HIT SNIPPET:"); + zebra_snippets_log(hit_snippet, YLOG_LOG, 1); #endif - - snippet_xml_record(zh, wrbuf, rec_snippet); - - *output_format = yaz_oid_recsyn_xml; - - - zebra_snippets_destroy(rec_snippet); - } - stream.destroy(&stream); - } + + zebra_snippets_ring(rec_snippets, hit_snippet, 5, 5); + +#if 0 + yaz_log(YLOG_LOG, "---------------------------"); + yaz_log(YLOG_LOG, "RING SNIPPET:"); + zebra_snippets_log(rec_snippets, YLOG_LOG, 1); +#endif + snippet_xml_record(zh, wrbuf, rec_snippets); + + *output_format = yaz_oid_recsyn_xml; + if (return_code == 0) { *rec_lenp = wrbuf_len(wrbuf); *rec_bufp = odr_strdup(odr, wrbuf_cstr(wrbuf)); } wrbuf_destroy(wrbuf); - rec_free(&rec); zebra_snippets_destroy(hit_snippet); } + zebra_snippets_destroy(rec_snippets); return return_code; } @@ -733,8 +740,8 @@ int zebra_record_fetch(ZebraHandle zh, const char *setname, file_type = rec->info[recInfo_fileType]; fname = rec->info[recInfo_filename]; basename = rec->info[recInfo_databaseName]; - *basenamep = (char *) odr_malloc (odr, strlen(basename)+1); - strcpy (*basenamep, basename); + *basenamep = (char *) odr_malloc(odr, strlen(basename)+1); + strcpy(*basenamep, basename); yaz_log(YLOG_DEBUG, "retrieve localno=" ZINT_FORMAT " score=%d", sysno, score);