return code;
}
-
-
void ZOOM_set_error(ZOOM_connection c, int error, const char *addinfo)
{
ZOOM_set_dset_error(c, error, "ZOOM", addinfo, 0);
c->cookies = 0;
c->saveAPDU_wrbuf = 0;
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
- c->mc_st = 0;
-#endif
+ ZOOM_memcached_init(c);
return c;
}
yaz_cookies_destroy(c->cookies);
c->cookies = yaz_cookies_create();
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
- if (c->mc_st)
- {
- memcached_free(c->mc_st);
- c->mc_st = 0;
- }
-#endif
- val = ZOOM_options_get(c->options, "memcached");
- if (val && *val)
+ if (ZOOM_memcached_configure(c))
{
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
- c->mc_st = memcached(val, strlen(val));
- if (!c->mc_st)
- {
- ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, val);
- return;
- }
-#else
- ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, "not enabled");
+ ZOOM_connection_remove_tasks(c);
return;
-#endif
}
-
if (c->sru_mode == zoom_sru_error)
{
ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, val);
return;
yaz_log(c->log_api, "%p ZOOM_connection_destroy", c);
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
- if (c->mc_st)
- memcached_free(c->mc_st);
-#endif
+ ZOOM_memcached_destroy(c);
if (c->cs)
cs_close(c->cs);
r->connection = 0;
r->databaseNames = 0;
r->num_databaseNames = 0;
- r->facets = 0;
- r->num_facets = 0;
+ r->req_facets = 0;
+ r->res_facets = 0;
+ r->num_res_facets = 0;
r->facets_names = 0;
r->mutex = 0;
yaz_mutex_create(&r->mutex);
ZOOM_connection_search(ZOOM_connection c, ZOOM_query q)
{
ZOOM_resultset r = ZOOM_resultset_create();
- const char *cp;
ZOOM_task task;
int start, count;
const char *syntax, *elementSetName, *schema;
r->options = ZOOM_options_create_with_parent(c->options);
+ r->req_facets = odr_strdup_null(r->odr,
+ ZOOM_options_get(r->options, "facets"));
start = ZOOM_options_get_int(r->options, "start", 0);
count = ZOOM_options_get_int(r->options, "count", 0);
{
(cp != 0 ? "presentChunk": "step"), 0);
}
r->piggyback = ZOOM_options_get_bool(r->options, "piggyback", 1);
- cp = ZOOM_options_get(r->options, "setname");
- if (cp)
- r->setname = xstrdup(cp);
-
- r->databaseNames = ZOOM_connection_get_databases(c, c->options, &r->num_databaseNames,
- r->odr);
-
+ r->setname = odr_strdup_null(r->odr,
+ ZOOM_options_get(r->options, "setname"));
+ r->databaseNames = ZOOM_connection_get_databases(c, c->options,
+ &r->num_databaseNames,
+ r->odr);
r->connection = c;
r->next = c->resultsets;
c->resultsets = r;
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
- r->mc_key = wrbuf_alloc();
- wrbuf_puts(r->mc_key, "0;");
- wrbuf_puts(r->mc_key, c->host_port);
- wrbuf_puts(r->mc_key, ";");
- if (c->user)
- wrbuf_puts(r->mc_key, c->user);
- wrbuf_puts(r->mc_key, ";");
- if (c->group)
- wrbuf_puts(r->mc_key, c->group);
- wrbuf_puts(r->mc_key, ";");
- if (c->password)
- wrbuf_sha1_puts(r->mc_key, c->password, 1);
- wrbuf_puts(r->mc_key, ";");
- wrbuf_sha1_puts(r->mc_key, ZOOM_query_get_query_string(q), 1);
- wrbuf_puts(r->mc_key, ";");
- /* TODO: add sorting */
- if (c->mc_st)
- {
- size_t v_len;
- uint32_t flags;
- memcached_return_t rc;
- char *v = memcached_get(c->mc_st, wrbuf_buf(r->mc_key),
- wrbuf_len(r->mc_key), &v_len, &flags, &rc);
- if (v)
- {
- ZOOM_Event event;
- WRBUF w = wrbuf_alloc();
-
- wrbuf_write(w, v, v_len);
- free(v);
- r->size = odr_atoi(wrbuf_cstr(w));
-
- yaz_log(YLOG_LOG, "For key %s got value %s",
- wrbuf_cstr(r->mc_key), wrbuf_cstr(w));
-
- wrbuf_destroy(w);
- event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
- ZOOM_connection_put_event(c, event);
- r->live_set = 1;
- return r;
- }
- else
- {
- yaz_log(YLOG_LOG, "For key %s got NO value", wrbuf_cstr(r->mc_key));
- }
- }
-#endif
+ ZOOM_memcached_resultset(r, q);
if (c->host_port && c->proto == PROTO_HTTP)
{
ZOOM_query_destroy(r->query);
ZOOM_options_destroy(r->options);
odr_destroy(r->odr);
- xfree(r->setname);
yaz_mutex_destroy(&r->mutex);
#if SHPTR
YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy);
}
ZOOM_API(size_t)
- ZOOM_resultset_facets_size(ZOOM_resultset r) {
- return r->num_facets;
+ ZOOM_resultset_facets_size(ZOOM_resultset r)
+{
+ return r->num_res_facets;
}
ZOOM_API(ZOOM_facet_field)
- ZOOM_resultset_get_facet_field(ZOOM_resultset r, const char *name) {
- int num = r->num_facets;
- ZOOM_facet_field *facets = r->facets;
- int index;
- for (index = 0; index < num; index++) {
- if (!strcmp(facets[index]->facet_name, name)) {
- return facets[index];
- }
- }
+ ZOOM_resultset_get_facet_field(ZOOM_resultset r, const char *name)
+{
+ int num = r->num_res_facets;
+ ZOOM_facet_field *facets = r->res_facets;
+ int i;
+ for (i = 0; i < num; i++)
+ if (!strcmp(facets[i]->facet_name, name))
+ return facets[i];
return 0;
}
ZOOM_API(ZOOM_facet_field)
- ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r, int index) {
- int num = r->num_facets;
- ZOOM_facet_field *facets = r->facets;
- if (index >= 0 && index < num) {
- return facets[index];
- }
+ ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r, int idx)
+{
+ int num = r->num_res_facets;
+ ZOOM_facet_field *facets = r->res_facets;
+ if (idx >= 0 && idx < num)
+ return facets[idx];
return 0;
}
ZOOM_API(ZOOM_facet_field *)
ZOOM_resultset_facets(ZOOM_resultset r)
{
- return r->facets;
+ return r->res_facets;
}
ZOOM_API(const char**)
}
ZOOM_API(const char*)
- ZOOM_facet_field_get_term(ZOOM_facet_field field, size_t idx, int *freq) {
+ ZOOM_facet_field_get_term(ZOOM_facet_field field, size_t idx, int *freq)
+{
*freq = field->facet_terms[idx].frequency;
return field->facet_terms[idx].term;
}
const char *schema =
ZOOM_options_get(s->options, "schema");
- return ZOOM_record_cache_lookup(s, pos, syntax, elementSetName, schema);
+ return ZOOM_record_cache_lookup_i(s, pos, syntax, elementSetName, schema);
}
ZOOM_API(ZOOM_record)
if (c->proto == PROTO_HTTP)
ret = ZOOM_connection_srw_send_search(c);
else
- ret = ZOOM_connection_Z3950_send_search(c);
+ ret = ZOOM_connection_Z3950_search(c);
break;
case ZOOM_TASK_CONNECT:
ret = do_connect(c);