From: Adam Dickmeiss Date: Tue, 17 Jan 2006 17:55:40 +0000 (+0000) Subject: Added piggyback support for filters backend_test + multi. X-Git-Tag: YP2.0.0.2~35 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=33243335d807707f1ae5eb0468cc74b574eb4b69;p=metaproxy-moved-to-github.git Added piggyback support for filters backend_test + multi. --- diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index 1f60334..0bac12a 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_backend_test.cpp,v 1.16 2006-01-17 16:45:49 adam Exp $ +/* $Id: filter_backend_test.cpp,v 1.17 2006-01-17 17:55:40 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -214,30 +214,19 @@ void yf::Backend_test::process(Package &package) const int next_position = 0; int error_code = 0; std::string addinfo; + + int number = 0; + yp2::util::piggyback(*req->smallSetUpperBound, + *req->largeSetLowerBound, + *req->mediumSetPresentNumber, + result_set_size, + number); - if (result_set_size < *req->smallSetUpperBound) - { - // small set . Return all records in set - records = m_p->fetch( - odr, req->preferredRecordSyntax, - 1, result_set_size, - error_code, addinfo, - &number_returned, - &next_position); - } - else if (result_set_size > *req->largeSetLowerBound) - { - // large set . Return no records - } - else + if (number) { - // medium set .Return mediumSetPresentNumber records - int to_get = *req->mediumSetPresentNumber; - if (to_get > result_set_size) - to_get = result_set_size; records = m_p->fetch( odr, req->preferredRecordSyntax, - 1, to_get, + 1, number, error_code, addinfo, &number_returned, &next_position); diff --git a/src/filter_multi.cpp b/src/filter_multi.cpp index 778a527..0ee4bb8 100644 --- a/src/filter_multi.cpp +++ b/src/filter_multi.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_multi.cpp,v 1.4 2006-01-17 13:34:51 adam Exp $ +/* $Id: filter_multi.cpp,v 1.5 2006-01-17 17:55:40 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -59,7 +59,6 @@ namespace yp2 { struct Multi::Frontend { Frontend(Rep *rep); ~Frontend(); - yp2::Session m_session; bool m_is_multi; bool m_in_use; std::list m_backend_list; @@ -392,8 +391,13 @@ void yf::Multi::Frontend::search(Package &package, Z_APDU *apdu_req) { // create search request Z_SearchRequest *req = apdu_req->u.searchRequest; - - // deal with piggy back (for now disable) + + // save these for later + int smallSetUpperBound = *req->smallSetUpperBound; + int largeSetLowerBound = *req->largeSetLowerBound; + int mediumSetPresentNumber = *req->mediumSetPresentNumber; + + // they are altered now - to disable piggyback *req->smallSetUpperBound = 0; *req->largeSetLowerBound = 1; *req->mediumSetPresentNumber = 1; @@ -422,7 +426,7 @@ void yf::Multi::Frontend::search(Package &package, Z_APDU *apdu_req) // look at each response FrontendSet resultSet(std::string(req->resultSetName)); - int total_count = 0; + int result_set_size = 0; Z_Records *z_records_diag = 0; // no diagnostics (yet) for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++) { @@ -449,7 +453,7 @@ void yf::Multi::Frontend::search(Package &package, Z_APDU *apdu_req) BackendSet backendSet; backendSet.m_backend = *bit; backendSet.m_count = *b_resp->resultCount; - total_count += *b_resp->resultCount; + result_set_size += *b_resp->resultCount; resultSet.m_backend_sets.push_back(backendSet); } else @@ -464,18 +468,57 @@ void yf::Multi::Frontend::search(Package &package, Z_APDU *apdu_req) Z_APDU *f_apdu = odr.create_searchResponse(apdu_req, 0, 0); Z_SearchResponse *f_resp = f_apdu->u.searchResponse; + *f_resp->resultCount = result_set_size; if (z_records_diag) { // search error f_resp->records = z_records_diag; + package.response() = f_apdu; + return; } - else - { // assume OK - m_sets[resultSet.m_setname] = resultSet; + // assume OK + m_sets[resultSet.m_setname] = resultSet; + + int number; + yp2::util::piggyback(smallSetUpperBound, + largeSetLowerBound, + mediumSetPresentNumber, + result_set_size, + number); + Package pp(package.session(), package.origin()); + if (number > 0) + { + pp.copy_filter(package); + Z_APDU *p_apdu = zget_APDU(odr, Z_APDU_presentRequest); + Z_PresentRequest *p_req = p_apdu->u.presentRequest; + p_req->preferredRecordSyntax = req->preferredRecordSyntax; + p_req->resultSetId = req->resultSetName; + *p_req->resultSetStartPoint = 1; + *p_req->numberOfRecordsRequested = number; + pp.request() = p_apdu; + present(pp, p_apdu); + + if (pp.session().is_closed()) + package.session().close(); + + Z_GDU *gdu = pp.response().get(); + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == + Z_APDU_presentResponse) + { + Z_PresentResponse *p_res = gdu->u.z3950->u.presentResponse; + f_resp->records = p_res->records; + *f_resp->numberOfRecordsReturned = + *p_res->numberOfRecordsReturned; + *f_resp->nextResultSetPosition = + *p_res->nextResultSetPosition; + } + else + { + package.response() = pp.response(); + return; + } } - *f_resp->resultCount = total_count; - - package.response() = f_apdu; + package.response() = f_apdu; // in this scope because of p } void yf::Multi::Frontend::present(Package &package, Z_APDU *apdu_req) diff --git a/src/util.cpp b/src/util.cpp index 38fd9e2..15aa7ae 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.8 2006-01-17 16:56:48 adam Exp $ +/* $Id: util.cpp,v 1.9 2006-01-17 17:55:40 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -11,6 +11,32 @@ #include #include "util.hpp" +void yp2::util::piggyback(int smallSetUpperBound, + int largeSetLowerBound, + int mediumSetPresentNumber, + int result_set_size, + int &number_to_present) +{ + // deal with piggyback + + if (result_set_size < smallSetUpperBound) + { + // small set . Return all records in set + number_to_present = result_set_size; + } + else if (result_set_size > largeSetLowerBound) + { + // large set . Return no records + number_to_present = 0; + } + else + { + // medium set . Return mediumSetPresentNumber records + number_to_present = mediumSetPresentNumber; + if (number_to_present > result_set_size) + number_to_present = result_set_size; + } +} bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); diff --git a/src/util.hpp b/src/util.hpp index 6d0d224..3ee0249 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -1,4 +1,4 @@ -/* $Id: util.hpp,v 1.7 2006-01-17 16:43:29 adam Exp $ +/* $Id: util.hpp,v 1.8 2006-01-17 17:55:40 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -30,6 +30,12 @@ namespace yp2 { int &error_code, std::string &addinfo); void get_default_diag(Z_DefaultDiagFormat *r, int &error_code, std::string &addinfo); + + void piggyback(int smallSetUpperBound, + int largeSetLowerBound, + int mediumSetPresentNumber, + int result_set_size, + int &number_to_present); }; class odr : public boost::noncopyable {