-/* $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%
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);
-/* $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%
struct Multi::Frontend {
Frontend(Rep *rep);
~Frontend();
- yp2::Session m_session;
bool m_is_multi;
bool m_in_use;
std::list<BackendPtr> m_backend_list;
{
// 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;
// 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++)
{
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
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)
-/* $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%
#include <yaz/otherinfo.h>
#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();
-/* $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%
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 {