{
YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
struct yaz_pqf_parser *li = pqf_parser;
- Odr_oid *attributeSetId;
+ Odr_oid *attributeSetId = 0;
Z_FacetField *facet_field = 0;
Z_AttributeList *attribute_list;
void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset resultset)
{
#if HAVE_LIBMEMCACHED_MEMCACHED_H
- /* TODO: add sorting */
if (c->mc_st && resultset->live_set == 0)
{
size_t v_len;
char *v = memcached_get(c->mc_st, wrbuf_buf(resultset->mc_key),
wrbuf_len(resultset->mc_key),
&v_len, &flags, &rc);
+ /* count;precision (ASCII) + '\0' + BER buffer for otherInformation */
if (v)
{
ZOOM_Event event;
- WRBUF w = wrbuf_alloc();
+ size_t lead_len = strlen(v) + 1;
- wrbuf_write(w, v, v_len);
- free(v);
- resultset->size = odr_atoi(wrbuf_cstr(w));
-
- yaz_log(YLOG_LOG, "For key %s got value %s",
- wrbuf_cstr(resultset->mc_key), wrbuf_cstr(w));
+ resultset->size = odr_atoi(v);
- wrbuf_destroy(w);
+ yaz_log(YLOG_LOG, "For key %s got value %s lead_len=%d len=%d",
+ wrbuf_cstr(resultset->mc_key), v, (int) lead_len,
+ (int) v_len);
+ if (v_len > lead_len)
+ {
+ Z_OtherInformation *oi = 0;
+ int oi_len = v_len - lead_len;
+ odr_setbuf(resultset->odr, v + lead_len, oi_len, 0);
+ if (!z_OtherInformation(resultset->odr, &oi, 0, 0))
+ {
+ yaz_log(YLOG_WARN, "oi decoding failed");
+ free(v);
+ return;
+ }
+ ZOOM_handle_search_result(c, resultset, oi);
+ ZOOM_handle_facet_result(c, resultset, oi);
+ }
+ free(v);
event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
ZOOM_connection_put_event(c, event);
resultset->live_set = 1;
#endif
}
-void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset)
+void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset,
+ Z_OtherInformation *oi, const char *precision)
{
#if HAVE_LIBMEMCACHED_MEMCACHED_H
if (c->mc_st && resultset->live_set == 0)
uint32_t flags = 0;
memcached_return_t rc;
time_t expiration = 36000;
- char str[40];
+ char *str;
+ ODR odr = odr_createmem(ODR_ENCODE);
+ char *oi_buf = 0;
+ int oi_len = 0;
+ char *key;
+
+ str = odr_malloc(odr, 20 + strlen(precision));
+ /* count;precision (ASCII) + '\0' + BER buffer for otherInformation */
+ sprintf(str, ODR_INT_PRINTF ";%s", resultset->size, precision);
+ if (oi)
+ {
+ z_OtherInformation(odr, &oi, 0, 0);
+ oi_buf = odr_getbuf(odr, &oi_len, 0);
+ }
+ key = odr_malloc(odr, strlen(str) + 1 + oi_len);
+ strcpy(key, str);
+ if (oi_len)
+ memcpy(key + strlen(str) + 1, oi_buf, oi_len);
- sprintf(str, ODR_INT_PRINTF, resultset->size);
rc = memcached_set(c->mc_st,
- wrbuf_buf(resultset->mc_key),wrbuf_len(resultset->mc_key),
- str, strlen(str), expiration, flags);
- yaz_log(YLOG_LOG, "Store hit count key=%s value=%s rc=%u %s",
- wrbuf_cstr(resultset->mc_key), str, (unsigned) rc,
+ wrbuf_buf(resultset->mc_key),
+ wrbuf_len(resultset->mc_key),
+ key, strlen(str) + 1 + oi_len, expiration, flags);
+ yaz_log(YLOG_LOG, "Store hit count key=%s value=%s oi_len=%d rc=%u %s",
+ wrbuf_cstr(resultset->mc_key), str, oi_len, (unsigned) rc,
memcached_last_error_message(c->mc_st));
+ odr_destroy(odr);
}
#endif
}
void ZOOM_memcached_destroy(ZOOM_connection c);
void ZOOM_memcached_resultset(ZOOM_resultset r, ZOOM_query q);
void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset r);
-void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset result);
+void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset result,
+ Z_OtherInformation *oi, const char *precision);
void ZOOM_memcached_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
int pos,
const char *syntax, const char *elementSetName,
const char *elementSetName,
const char *schema);
+void ZOOM_handle_facet_result(ZOOM_connection c, ZOOM_resultset r,
+ Z_OtherInformation *o);
+void ZOOM_handle_search_result(ZOOM_connection c, ZOOM_resultset resultset,
+ Z_OtherInformation *o);
+
/*
* Local variables:
* c-basic-offset: 4
{
if (res->numberOfRecords)
{
+ Z_OtherInformation *oi = 0;
+ if (res->facetList)
+ {
+ ODR o = c->odr_in;
+ Z_External *ext = (Z_External *)
+ odr_malloc(o, sizeof(*ext));
+
+ ext->which = Z_External_userFacets;
+ ext->u.facetList = res->facetList;
+ ext->direct_reference =
+ odr_oiddup(o, yaz_oid_userinfo_facet_1);
+ ext->indirect_reference = 0;
+ ext->descriptor = 0;
+ oi = (Z_OtherInformation *) odr_malloc(o, sizeof(*oi));
+ oi->num_elements = 1;
+ oi->list = (Z_OtherInformationUnit **)
+ odr_malloc(o, sizeof(*oi->list));
+ oi->list[0] = (Z_OtherInformationUnit *)
+ odr_malloc(o, sizeof(**oi->list));
+ oi->list[0]->category = 0;
+ oi->list[0]->which = Z_OtherInfo_externallyDefinedInfo;
+ oi->list[0]->information.externallyDefinedInfo = ext;
+ }
resultset->size = *res->numberOfRecords;
- ZOOM_memcached_hitcount(c, resultset);
+ ZOOM_memcached_hitcount(c, resultset, oi,
+ res->resultCountPrecision ?
+ res->resultCountPrecision : "exact");
}
resultset->live_set = 2;
if (res->suggestions)
}
}
-static void handle_facet_result(ZOOM_connection c, ZOOM_resultset r,
- Z_OtherInformation *o)
+void ZOOM_handle_facet_result(ZOOM_connection c, ZOOM_resultset r,
+ Z_OtherInformation *o)
{
int i;
for (i = 0; o && i < o->num_elements; i++)
}
-static void handle_search_result(ZOOM_connection c, ZOOM_resultset resultset,
- Z_OtherInformation *o)
+void ZOOM_handle_search_result(ZOOM_connection c, ZOOM_resultset resultset,
+ Z_OtherInformation *o)
{
int i;
for (i = 0; o && i < o->num_elements; i++)
{
ZOOM_resultset resultset;
ZOOM_Event event;
+ const char *resultCountPrecision = "exact";
if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
return;
}
if (sr->resultSetStatus)
{
+ if (*sr->resultSetStatus == Z_SearchResponse_estimate)
+ resultCountPrecision = "estimate";
ZOOM_options_set_int(resultset->options, "resultSetStatus",
*sr->resultSetStatus);
}
ZOOM_options_set_int(resultset->options, "presentStatus",
*sr->presentStatus);
}
- handle_search_result(c, resultset, sr->additionalSearchInfo);
+ ZOOM_options_set(resultset->options, "resultCountPrecision",
+ resultCountPrecision);
+ ZOOM_handle_search_result(c, resultset, sr->additionalSearchInfo);
- handle_facet_result(c, resultset, sr->additionalSearchInfo);
+ ZOOM_handle_facet_result(c, resultset, sr->additionalSearchInfo);
resultset->size = *sr->resultCount;
- ZOOM_memcached_hitcount(c, resultset);
+ ZOOM_memcached_hitcount(c, resultset, sr->additionalSearchInfo,
+ resultCountPrecision);
resultset->live_set = 2;
handle_Z3950_records(c, sr->records, 0);
}