From 8d18c2ba52018f0a4149abb5e2bd2bb2c75fe14e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 5 Dec 2007 09:55:10 +0000 Subject: [PATCH] Allow facet size to be specified. A facet size may be specified by appending colon and number after index type, e.g. zebra::facet::title:w:10 . --- index/retrieve.c | 27 +++++++++++++++++++++------ test/api/safari1.c | 15 ++++++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/index/retrieve.c b/index/retrieve.c index ea16718..ff3bced 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -1,4 +1,4 @@ -/* $Id: retrieve.c,v 1.81 2007-12-05 09:29:52 adam Exp $ +/* $Id: retrieve.c,v 1.82 2007-12-05 09:55:57 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -80,6 +80,7 @@ static int zebra_create_record_stream(ZebraHandle zh, struct index_spec { const char *index_name; const char *index_type; + const char *extra; struct index_spec *next; }; @@ -103,6 +104,7 @@ struct index_spec *parse_index_spec(const char *elem, NMEM nmem, struct index_spec *spec = nmem_malloc(nmem, sizeof(*spec)); spec->index_type = 0; spec->next = 0; + spec->extra = 0; if (!first) first = spec; @@ -119,10 +121,19 @@ struct index_spec *parse_index_spec(const char *elem, NMEM nmem, cp++; cp0 = cp; - while (*cp != '\0' && *cp != ',') + while (*cp != '\0' && *cp != ',' && *cp != ':') cp++; spec->index_type = nmem_strdupn(nmem, cp0, cp - cp0); } + if (*cp == ':') /* extra arguments */ + { + cp++; + cp0 = cp; + + while (*cp != '\0' && *cp != ',' && *cp != ':') + cp++; + spec->extra = nmem_strdupn(nmem, cp0, cp - cp0); + } if (*cp != ',') break; } @@ -710,7 +721,6 @@ static ZEBRA_RES facet_fetch(ZebraHandle zh, const char *setname, zint *pos_array; int i; int num_recs = 10; /* number of records to analyze */ - int no_collect_terms = 20; /* number of term candidates */ ZebraMetaRecord *poset; ZEBRA_RES ret = ZEBRA_OK; int *ord_array; @@ -843,9 +853,14 @@ static ZEBRA_RES facet_fetch(ZebraHandle zh, const char *setname, { int j; NMEM nmem = nmem_create(); - struct term_collect *col = term_collect_create(map_array[i], - no_collect_terms, - nmem); + struct term_collect *col; + int no_collect_terms = 20; + + if (spec->extra) + no_collect_terms = atoi(spec->extra); + if (no_collect_terms < 1) + no_collect_terms = 1; + col = term_collect_create(map_array[i], no_collect_terms, nmem); term_collect_freq(zh, col, no_collect_terms, ord_array[i], resultSetRef(zh, setname)); diff --git a/test/api/safari1.c b/test/api/safari1.c index 4d2337b..3ae9231 100644 --- a/test/api/safari1.c +++ b/test/api/safari1.c @@ -1,4 +1,4 @@ -/* $Id: safari1.c,v 1.22 2007-12-05 09:29:53 adam Exp $ +/* $Id: safari1.c,v 1.23 2007-12-05 09:55:10 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -96,15 +96,12 @@ static void tst(int argc, char **argv) ids[2] = 24340; YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids)); -#if 1 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "R", yaz_oid_recsyn_sutrs, myrec[0]), ZEBRA_OK); YAZ_CHECK_EQ(tl_fetch_compare(zh, 2, "R", yaz_oid_recsyn_sutrs, myrec[2]), ZEBRA_OK); YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs, myrec[4]), ZEBRA_OK); -#endif -#if 1 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0", yaz_oid_recsyn_xml, "\n" @@ -116,7 +113,15 @@ static void tst(int argc, char **argv) " old\n" " \n" "\n"), ZEBRA_OK); -#endif + YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2", + yaz_oid_recsyn_xml, + "\n" + " \n" + " mand\n" + " the\n" + " \n" + "\n"), ZEBRA_OK); + /* limit to 125061 */ limits[0] = 125061; limits[1] = 0; -- 1.7.10.4