From 30b0943d4387c7a70dd0095503eca7c9721dfa9c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 7 Sep 2011 14:38:24 +0200 Subject: [PATCH] zoom: new target profile setting: sortmap_field If sortmap_field is given the field is mapped to the value for the sortmap. Values not matching sortmap_field are passed verbatim. --- etc/config-zoom.xml | 1 + src/filter_zoom.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- xml/schema/filter_zoom.rnc | 5 ++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/etc/config-zoom.xml b/etc/config-zoom.xml index 451ceb3..96ed5b8 100644 --- a/etc/config-zoom.xml +++ b/etc/config-zoom.xml @@ -47,6 +47,7 @@ tmarc.xsl localhost:9998/db01 embed + dc.title diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index de2c0b2..1e013eb 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -47,6 +47,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -74,6 +75,7 @@ namespace metaproxy_1 { bool use_turbomarc; bool piggyback; CCL_bibset ccl_bibset; + std::map sortmap; Searchable(CCL_bibset base); ~Searchable(); }; @@ -473,6 +475,12 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr) ccl_qual_fitem(s->ccl_bibset, value.c_str(), (const char *) ptr->name + 7); } + else if (!strncmp((const char *) ptr->name, + "sortmap_", 8)) + { + std::string value = mp::xml::get_text(ptr); + s->sortmap[(const char *) ptr->name + 8] = value; + } else if (!strcmp((const char *) ptr->name, "sortStrategy")) { @@ -1355,9 +1363,41 @@ void yf::Zoom::Frontend::handle_search(mp::Package &package) WRBUF sort_spec_wrbuf = wrbuf_alloc(); yaz_srw_sortkeys_to_sort_spec(wrbuf_cstr(sru_sortkeys_wrbuf), sort_spec_wrbuf); - sortkeys.assign(wrbuf_cstr(sort_spec_wrbuf)); - wrbuf_destroy(sort_spec_wrbuf); wrbuf_destroy(sru_sortkeys_wrbuf); + + yaz_tok_cfg_t tc = yaz_tok_cfg_create(); + yaz_tok_parse_t tp = + yaz_tok_parse_buf(tc, wrbuf_cstr(sort_spec_wrbuf)); + yaz_tok_cfg_destroy(tc); + + /* go through sortspec and map fields */ + int token = yaz_tok_move(tp); + while (token != YAZ_TOK_EOF) + { + if (token == YAZ_TOK_STRING) + { + const char *field = yaz_tok_parse_string(tp); + std::map::iterator it; + it = b->sptr->sortmap.find(field); + if (it != b->sptr->sortmap.end()) + sortkeys += it->second; + else + sortkeys += field; + } + sortkeys += " "; + token = yaz_tok_move(tp); + if (token == YAZ_TOK_STRING) + { + sortkeys += yaz_tok_parse_string(tp); + } + if (token != YAZ_TOK_EOF) + { + sortkeys += " "; + token = yaz_tok_move(tp); + } + } + yaz_tok_parse_destroy(tp); + wrbuf_destroy(sort_spec_wrbuf); } cql_parser_destroy(cp); if (r) diff --git a/xml/schema/filter_zoom.rnc b/xml/schema/filter_zoom.rnc index d8df770..144efd1 100644 --- a/xml/schema/filter_zoom.rnc +++ b/xml/schema/filter_zoom.rnc @@ -36,7 +36,10 @@ filter_zoom = element mp:cfProxy { xsd:string }?, element mp:cfSubDb { xsd:string }?, element mp:contentConnector { xsd:string }?, - element mp:sortStrategy { xsd:string }? + element mp:sortStrategy { xsd:string }?, + element mp:sortmap_author { xsd:string }?, + element mp:sortmap_date { xsd:string }?, + element mp:sortmap_title { xsd:string }? }* }? }?, -- 1.7.10.4