+Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu)
+{
+ if (apdu->which != Z_APDU_searchRequest)
+ return apdu;
+ Z_SearchRequest *sr = apdu->u.searchRequest;
+ Yaz_Z_Query *this_query = new Yaz_Z_Query;
+
+ this_query->set_Z_Query(sr->query);
+
+ if (m_client->m_last_query &&
+ m_client->m_last_query->match(this_query))
+ {
+ delete this_query;
+ if (*sr->smallSetUpperBound == 0)
+ {
+ Z_APDU *new_apdu;
+ logf (LOG_LOG, "query match");
+ new_apdu = create_Z_PDU(Z_APDU_searchResponse);
+ new_apdu->u.searchResponse->referenceId = sr->referenceId;
+ new_apdu->u.searchResponse->resultCount =
+ &m_client->m_last_resultCount;
+ send_Z_PDU(new_apdu);
+ return 0;
+ }
+ else
+ {
+ logf (LOG_LOG, "query match (piggy back)");
+ }
+ }
+ else
+ {
+ logf (LOG_LOG, "query doesn't match");
+ delete m_client->m_last_query;
+ m_client->m_last_query = this_query;
+ }
+ return apdu;
+}
+