#include <yaz/query-charset.h>
#include <yaz/copy_types.h>
#include <yaz/snprintf.h>
+#include <yaz/facet.h>
#include <yaz/shptr.h>
static zoom_ret do_write(ZOOM_connection c);
+ZOOM_API(void) ZOOM_resultset_release(ZOOM_resultset r)
+{
+#if ZOOM_RESULT_LISTS
+#else
+ if (r->connection)
+ {
+ /* remove ourselves from the resultsets in connection */
+ ZOOM_resultset *rp = &r->connection->resultsets;
+ while (1)
+ {
+ assert(*rp); /* we must be in this list!! */
+ if (*rp == r)
+ { /* OK, we're here - take us out of it */
+ *rp = (*rp)->next;
+ break;
+ }
+ rp = &(*rp)->next;
+ }
+ r->connection = 0;
+ }
+#endif
+}
+
ZOOM_API(void)
ZOOM_connection_destroy(ZOOM_connection c)
{
r->connection = 0;
r->databaseNames = 0;
r->num_databaseNames = 0;
+ r->facets = 0;
+ r->num_facets = 0;
+ r->facets_names = 0;
r->mutex = 0;
yaz_mutex_create(&r->mutex);
#if SHPTR
yaz_log(log_details, "%p ZOOM_connection resultset_destroy: Deleting resultset (%p) ", r->connection, r);
ZOOM_resultset_cache_reset(r);
-#if ZOOM_RESULT_LISTS
-#else
- if (r->connection)
- {
- /* remove ourselves from the resultsets in connection */
- ZOOM_resultset *rp = &r->connection->resultsets;
- while (1)
- {
- assert(*rp); /* we must be in this list!! */
- if (*rp == r)
- { /* OK, we're here - take us out of it */
- *rp = (*rp)->next;
- break;
- }
- rp = &(*rp)->next;
- }
- }
-#endif
+ ZOOM_resultset_release(r);
ZOOM_query_destroy(r->query);
ZOOM_options_destroy(r->options);
odr_destroy(r->odr);
}
}
+ZOOM_API(size_t)
+ ZOOM_resultset_facets_size(ZOOM_resultset r) {
+ return r->num_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];
+ }
+ }
+ return 0;
+}
+
+
+ZOOM_API(ZOOM_facet_field *)
+ ZOOM_resultset_facets(ZOOM_resultset r)
+{
+ return r->facets;
+}
+
+ZOOM_API(const char**)
+ ZOOM_resultset_facet_names(ZOOM_resultset r)
+{
+ return (const char **) r->facets_names;
+}
+
+ZOOM_API(const char*)
+ ZOOM_facet_field_name(ZOOM_facet_field field)
+{
+ return field->facet_name;
+}
+
+ZOOM_API(size_t)
+ ZOOM_facet_field_term_count(ZOOM_facet_field field)
+{
+ return field->num_terms;
+}
+
+ZOOM_API(const char*)
+ 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;
+}
+
+
static void get_cert(ZOOM_connection c)
{
char *cert_buf;
const char *elementSetName;
const char *smallSetElementSetName;
const char *mediumSetElementSetName;
+ const char *facets;
assert(c->tasks);
assert(c->tasks->which == ZOOM_TASK_SEARCH);
if (!mediumSetElementSetName)
mediumSetElementSetName = elementSetName;
+ facets = ZOOM_options_get(r->options, "facets");
+ if (facets) {
+ Z_FacetList *facet_list = yaz_pqf_parse_facet_list(c->odr_out, facets);
+ if (facet_list) {
+ Z_OtherInformation **oi;
+ yaz_oi_APDU(apdu, &oi);
+ if (facet_list) {
+ yaz_oi_set_facetlist_oid(oi, c->odr_out, yaz_oid_userinfo_facet_1, 1, facet_list);
+ }
+ }
+ }
+
assert(r);
assert(r->query);
}
}
-static void handle_searchResult(ZOOM_connection c, ZOOM_resultset resultset,
+static void handle_search_result(ZOOM_connection c, ZOOM_resultset resultset,
Z_OtherInformation *o)
{
int i;
}
}
+static char *get_term_cstr(ODR odr, Z_Term *term) {
+
+ switch (term->which) {
+ case Z_Term_general:
+ return odr_strdupn(odr, (const char *) term->u.general->buf, (size_t) term->u.general->len);
+ break;
+ case Z_Term_characterString:
+ return odr_strdup(odr, term->u.characterString);
+ }
+ return 0;
+}
+
+static ZOOM_facet_field get_zoom_facet_field(ODR odr, Z_FacetField *facet) {
+ int term_index;
+ struct yaz_facet_attr attr_values;
+ ZOOM_facet_field facet_field = odr_malloc(odr, sizeof(*facet_field));
+ memset(&attr_values, 0, sizeof(attr_values));
+ facetattrs(facet->attributes, &attr_values);
+ facet_field->facet_name = odr_strdup(odr, attr_values.useattr);
+ facet_field->num_terms = facet->num_terms;
+ yaz_log(YLOG_DEBUG, "ZOOM_facet_field %s %d terms %d", attr_values.useattr, attr_values.limit, facet->num_terms);
+ facet_field->facet_terms = odr_malloc(odr, facet_field->num_terms * sizeof(*facet_field->facet_terms));
+ for (term_index = 0 ; term_index < facet->num_terms; term_index++) {
+ Z_FacetTerm *facetTerm = facet->terms[term_index];
+ facet_field->facet_terms[term_index].frequency = *facetTerm->count;
+ facet_field->facet_terms[term_index].term = get_term_cstr(odr, facetTerm->term);
+ yaz_log(YLOG_DEBUG, " term[%d] %s %d",
+ term_index, facet_field->facet_terms[term_index].term, facet_field->facet_terms[term_index].frequency);
+ }
+ return facet_field;
+}
+
+static void handle_facet_result(ZOOM_connection c, ZOOM_resultset r,
+ Z_OtherInformation *o)
+{
+ int i;
+ for (i = 0; o && i < o->num_elements; i++)
+ {
+ if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
+ {
+ Z_External *ext = o->list[i]->information.externallyDefinedInfo;
+ if (ext->which == Z_External_userFacets)
+ {
+ int j;
+ Z_FacetList *fl = ext->u.facetList;
+ r->num_facets = fl->num;
+ yaz_log(YLOG_DEBUG, "Facets found: %d", fl->num);
+ r->facets = odr_malloc(r->odr, r->num_facets * sizeof(*r->facets));
+ r->facets_names = odr_malloc(r->odr, r->num_facets * sizeof(*r->facets_names));
+ for (j = 0; j < fl->num; j++)
+ {
+ r->facets[j] = get_zoom_facet_field(r->odr, fl->elements[j]);
+ if (!r->facets[j])
+ yaz_log(YLOG_DEBUG, "Facet field missing on index %d !", j);
+ r->facets_names[j] = (char *) ZOOM_facet_field_name(r->facets[j]);
+ }
+ }
+ }
+ }
+}
+
+
static void handle_search_response(ZOOM_connection c, Z_SearchResponse *sr)
{
ZOOM_resultset resultset;
ZOOM_options_set_int(resultset->options, "presentStatus",
*sr->presentStatus);
}
- handle_searchResult(c, resultset, sr->additionalSearchInfo);
+ handle_search_result(c, resultset, sr->additionalSearchInfo);
+
+ handle_facet_result(c, resultset, sr->additionalSearchInfo);
resultset->size = *sr->resultCount;
handle_records(c, sr->records, 0);
{
struct Z_HTTP_Header *h;
Z_GDU *gdu = get_HTTP_Request_url(c->odr_out, uri);
+ char *combined_cookies;
+ int combined_cookies_len = 0;
gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET");
z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "Accept",
"text/xml");
-
+
for (h = cookie_hres->headers; h; h = h->next)
{
if (!strcmp(h->name, "Set-Cookie"))
- z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
- "Cookie", h->value);
+ {
+ char *cp;
+
+ if (!(cp = strchr(h->value, ';')))
+ cp = h->value + strlen(h->value);
+ if (cp - h->value >= 1) {
+ combined_cookies = xrealloc(combined_cookies, combined_cookies_len + cp - h->value + 3);
+ memcpy(combined_cookies+combined_cookies_len, h->value, cp - h->value);
+ combined_cookies[combined_cookies_len + cp - h->value] = '\0';
+ strcat(combined_cookies,"; ");
+ combined_cookies_len = strlen(combined_cookies);
+ }
+ }
}
+
+ if (combined_cookies_len)
+ {
+ z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
+ "Cookie", combined_cookies);
+ xfree(combined_cookies);
+ }
+
if (c->user && c->password)
{
z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,