From d9efeb647dc1dd2ff8045306605f2d90beabf3cd Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 1 Nov 2007 16:01:33 +0000 Subject: [PATCH] Beginnings of facets --- index/index.h | 11 +++----- index/rpnfacet.c | 74 +++++++++++++++++++++++++++++++++++++++++++----------- index/rpnscan.c | 19 ++++++-------- 3 files changed, 71 insertions(+), 33 deletions(-) diff --git a/index/index.h b/index/index.h index 76e1bd4..2024239 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.206 2007-11-01 14:56:07 adam Exp $ +/* $Id: index.h,v 1.207 2007-11-01 16:01:33 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -436,15 +436,12 @@ ZEBRA_RES zebra_term_limits_APT(ZebraHandle zh, const char **term_ref_id_str, NMEM nmem); -ZEBRA_RES rpn_facet(ZebraHandle zh, ODR stream, NMEM nmem, - struct rset_key_control *kc, +ZEBRA_RES rpn_facet(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, + const Odr_oid *attributeset, int *position, int *num_entries, ZebraScanEntry **list, - int *is_partial, RSET limit_set, - const char *index_type, - int ord_no, int *ords); - + int *is_partial, RSET limit_set); YAZ_END_CDECL #endif diff --git a/index/rpnfacet.c b/index/rpnfacet.c index 49d4ad0..b928f2a 100644 --- a/index/rpnfacet.c +++ b/index/rpnfacet.c @@ -1,4 +1,4 @@ -/* $Id: rpnfacet.c,v 1.1 2007-11-01 14:56:07 adam Exp $ +/* $Id: rpnfacet.c,v 1.2 2007-11-01 16:01:33 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -36,22 +36,66 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -ZEBRA_RES rpn_facet(ZebraHandle zh, ODR stream, NMEM nmem, - struct rset_key_control *kc, - Z_AttributesPlusTerm *zapt, +ZEBRA_RES rpn_facet(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, + const Odr_oid *attributeset, int *position, int *num_entries, - ZebraScanEntry **list, - int *is_partial, RSET limit_set, - const char *index_type, - int ord_no, int *ords) + ZebraScanEntry **list, int *is_partial, RSET rset) { - /* for each ord .. */ - /* check that sort idx exist for ord */ - /* sweep through result set and sort_idx at the same time */ - zebra_setError(zh, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, - "facet not implemented"); - - return ZEBRA_FAIL; + int ord; + ZEBRA_RES res = zebra_attr_list_get_ord(zh, + zapt->attributes, + zinfo_index_category_sort, + 0 /* index_type */, + attributeset, &ord); + if (res != ZEBRA_OK) + return res; + else + { + const char *index_type = 0; + const char *db = 0; + const char *string_index = 0; + /* for each ord .. */ + /* check that sort idx exist for ord */ + /* sweep through result set and sort_idx at the same time */ + char *this_entry_buf = xmalloc(SORT_IDX_ENTRYSIZE); + char *dst_buf = xmalloc(SORT_IDX_ENTRYSIZE); + size_t sysno_mem_index = 0; + + zint p_this_sys = 0; + RSFD rfd; + TERMID termid; + struct it_key key; + + if (zebraExplain_lookup_ord(zh->reg->zei, + ord, &index_type, &db, &string_index)) + { + yaz_log(YLOG_WARN, "zebraExplain_lookup_ord failed"); + } + + if (zh->m_staticrank) + sysno_mem_index = 1; + + rfd = rset_open(rset, RSETF_READ); + while (rset_read(rfd, &key, &termid)) + { + zint sysno = key.mem[sysno_mem_index]; + if (sysno != p_this_sys) + { + p_this_sys = sysno; + zebra_sort_sysno(zh->reg->sort_index, sysno); + zebra_sort_type(zh->reg->sort_index, ord); + zebra_sort_read(zh->reg->sort_index, this_entry_buf); + + zebra_term_untrans(zh, index_type, dst_buf, this_entry_buf); + yaz_log(YLOG_LOG, "dst_buf=%s", dst_buf); + } + } + rset_close(rfd); + xfree(this_entry_buf); + xfree(dst_buf); + zebra_setError(zh, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "facet not done"); + return ZEBRA_FAIL; + } } /* diff --git a/index/rpnscan.c b/index/rpnscan.c index 670a30d..79b12aa 100644 --- a/index/rpnscan.c +++ b/index/rpnscan.c @@ -1,4 +1,4 @@ -/* $Id: rpnscan.c,v 1.19 2007-11-01 14:56:07 adam Exp $ +/* $Id: rpnscan.c,v 1.20 2007-11-01 16:01:33 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -41,8 +41,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define RPN_MAX_ORDS 32 -static int log_scan = YLOG_LOG; - /* convert APT SCAN term to internal cmap */ static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, char *termz, zebra_map_t zm) @@ -526,7 +524,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, } } } - + yaz_log(YLOG_DEBUG, "position = %d, num = %d", *position, *num_entries); @@ -542,7 +540,11 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, zebra_setError(zh, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0); return ZEBRA_FAIL; } - + if (sort_flag) + { + return rpn_facet(zh, stream, zapt, attributeset, position, num_entries, + list, is_partial, limit_set); + } for (base_no = 0; base_no < num_bases; base_no++) { int ord; @@ -572,14 +574,9 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, nmem = nmem_create(); kc = zebra_key_control_create(zh); - if (sort_flag) - res = rpn_facet(zh, stream, nmem, kc, zapt, position, num_entries, + res = rpn_scan_norm(zh, stream, nmem, kc, zapt, position, num_entries, list, is_partial, limit_set, index_type, ord_no, ords); - else - res = rpn_scan_norm(zh, stream, nmem, kc, zapt, position, num_entries, - list, - is_partial, limit_set, index_type, ord_no, ords); nmem_destroy(nmem); (*kc->dec)(kc); return res; -- 1.7.10.4