#include <yaz/diagbib1.h>
#include <yaz/snprintf.h>
#include <yaz/rpn2cql.h>
+#include <yaz/rpn2solr.h>
#define USE_TIMING 0
#if USE_TIMING
int maxrecs;
int startrecs;
int diagnostic;
+ int preferred;
enum client_state state;
struct show_raw *show_raw;
ZOOM_resultset resultset;
if (was_active && !client_is_active(cl) && cl->session)
{
int no_active = session_active_clients(cl->session);
- if (no_active == 0)
+ if (no_active == 0) {
session_alert_watch(cl->session, SESSION_WATCH_SHOW);
+ session_alert_watch(cl->session, SESSION_WATCH_SHOW_PREF);
+ }
}
}
client_show_raw_dequeue(cl);
}
+static void client_check_preferred_watch(struct client *cl)
+{
+ struct session *se = cl->session;
+ if (se)
+ {
+ client_unlock(cl);
+ if (session_preferred_clients_ready(se))
+ session_alert_watch(se, SESSION_WATCH_SHOW_PREF);
+ client_lock(cl);
+ }
+}
+
void client_search_response(struct client *cl)
{
struct connection *co = cl->connection;
cl->hits = ZOOM_resultset_size(resultset);
if (se)
se->total_hits += cl->hits;
+ if (cl->preferred)
+ client_check_preferred_watch(cl);
}
}
const char *opt_facet_term_sort = session_setting_oneval(sdb, PZ_TERMLIST_TERM_SORT);
const char *opt_facet_term_count = session_setting_oneval(sdb, PZ_TERMLIST_TERM_COUNT);
/* Disable when no count is set */
+ /* TODO Verify: Do we need to reset the ZOOM facets if a ZOOM Connection is being reused??? */
if (opt_facet_term_count && *opt_facet_term_count)
{
int index = 0;
ZOOM_connection link = connection_get_link(co);
ZOOM_resultset rs;
char *databaseName = sdb->database->databases[0];
- const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
- const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
- const char *opt_elements = session_setting_oneval(sdb, PZ_ELEMENTS);
- const char *opt_requestsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
- const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
- const char *opt_sru = session_setting_oneval(sdb, PZ_SRU);
- const char *opt_sort = session_setting_oneval(sdb, PZ_SORT);
+ const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
+ const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
+ const char *opt_elements = session_setting_oneval(sdb, PZ_ELEMENTS);
+ const char *opt_requestsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
+ const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
+ const char *opt_sru = session_setting_oneval(sdb, PZ_SRU);
+ const char *opt_sort = session_setting_oneval(sdb, PZ_SORT);
+ const char *opt_preferred = session_setting_oneval(sdb, PZ_PREFERRED);
char maxrecs_str[24], startrecs_str[24];
assert(link);
cl->hits = -1;
cl->record_offset = 0;
cl->diagnostic = 0;
+
+ if (opt_preferred) {
+ cl->preferred = atoi(opt_preferred);
+ yaz_log(YLOG_LOG, "Target %s has preferred: %d", sdb->database->url, cl->preferred);
+ }
client_set_state(cl, Client_Working);
if (*opt_piggyback)
if (databaseName)
ZOOM_connection_option_set(link, "databaseName", databaseName);
+ /* TODO Verify does it break something for CQL targets(non-SOLR) ? */
+ /* facets definition is in PQF */
+ client_set_facets_request(cl, link);
+
if (cl->cqlquery)
{
ZOOM_query q = ZOOM_query_create();
}
else
{
- client_set_facets_request(cl, link);
yaz_log(YLOG_LOG, "Search %s PQF: %s", sdb->database->url, cl->pquery);
rs = ZOOM_connection_search_pqf(link, cl->pquery);
}
r->resultset = 0;
r->mutex = 0;
pazpar2_mutex_create(&r->mutex, "client");
-
+ r->preferred = 0;
r->ref_count = 1;
client_use(1);
// TODO Could prob. be merge with the similar make_cqlquery
static char *make_solrquery(struct client *cl)
{
- cql_transform_t sqlt = solr_transform_create();
+ solr_transform_t sqlt = solr_transform_create();
Z_RPNQuery *zquery;
char *r;
WRBUF wrb = wrbuf_alloc();
}
wrbuf_destroy(wrb);
odr_destroy(odr_out);
- cql_transform_close(sqlt);
+ solr_transform_close(sqlt);
return r;
}
xfree(cl->cqlquery);
if (*sru)
{
- if (!strcmp(sru, "solr")
-
- if (!(cl->cqlquery = make_cqlquery(cl)))
- return -1;
+ if (!strcmp(sru, "solr")) {
+ if (!(cl->cqlquery = make_solrquery(cl)))
+ return -1;
+ }
+ else {
+ if (!(cl->cqlquery = make_cqlquery(cl)))
+ return -1;
+ }
}
else
cl->cqlquery = 0;
return 0;
}
+int client_is_active_preferred(struct client *cl)
+{
+ /* only count if this is a preferred target. */
+ if (!cl->preferred)
+ return 0;
+ /* TODO No sure this the condition that Seb wants */
+ if (cl->connection && (cl->state == Client_Connecting ||
+ cl->state == Client_Working))
+ return 1;
+ return 0;
+}
+
+
Odr_int client_get_hits(struct client *cl)
{
return cl->hits;
cl->startrecs = v;
}
+void client_set_preferred(struct client *cl, int v)
+{
+ cl->preferred = v;
+}
+
+
/*
* Local variables:
* c-basic-offset: 4