X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fclient.c;h=37cef18bfc046fdf74a20ab89a297640ad32d9b4;hb=3de3ea11e6756214a2e2d1e8f3631aac10ec266c;hp=98a2916f3d3fbbbd78e45652dadb54cb1838f338;hpb=29891cb3f3ed0507d9c0c86414b61adc23ca623f;p=pazpar2-moved-to-github.git diff --git a/src/client.c b/src/client.c index 98a2916..37cef18 100644 --- a/src/client.c +++ b/src/client.c @@ -58,6 +58,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #define USE_TIMING 0 #if USE_TIMING @@ -80,6 +81,7 @@ struct client { struct connection *connection; struct session *session; char *pquery; // Current search + char *cqlquery; // used for SRU targets only int hits; int records; int setno; @@ -311,7 +313,6 @@ static int nativesyntax_to_type(struct session_database *sdb, char *type) } else return -1; - yaz_log(YLOG_LOG, "Returned type %s", type); return 0; } return -1; @@ -378,8 +379,6 @@ void client_record_response(struct client *cl) ZOOM_record rec = 0; const char *msg, *addinfo; - yaz_log(YLOG_LOG, "show_raw=%p show_raw->active=%d", - cl->show_raw, cl->show_raw ? cl->show_raw->active : 0); if (cl->show_raw && cl->show_raw->active) { if ((rec = ZOOM_resultset_record(resultset, @@ -439,6 +438,7 @@ void client_start_search(struct client *cl) 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); assert(link); @@ -452,7 +452,9 @@ void client_start_search(struct client *cl) ZOOM_connection_option_set(link, "piggyback", "1"); if (*opt_queryenc) ZOOM_connection_option_set(link, "rpnCharset", opt_queryenc); - if (*opt_elements) + if (*opt_sru && *opt_elements) + ZOOM_connection_option_set(link, "schema", opt_elements); + else if (*opt_elements) ZOOM_connection_option_set(link, "elementSetName", opt_elements); if (*opt_requestsyn) ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn); @@ -464,13 +466,19 @@ void client_start_search(struct client *cl) sprintf(n, "%d", global_parameters.toget); ZOOM_connection_option_set(link, "count", n); } - if (!databaseName || !*databaseName) - databaseName = "Default"; - ZOOM_connection_option_set(link, "databaseName", databaseName); + if (databaseName) + ZOOM_connection_option_set(link, "databaseName", databaseName); ZOOM_connection_option_set(link, "presentChunk", "20"); - rs = ZOOM_connection_search_pqf(link, cl->pquery); + if (cl->cqlquery) + { + ZOOM_query q = ZOOM_query_create(); + ZOOM_query_cql(q, cl->cqlquery); + rs = ZOOM_connection_search(link, q); + } + else + rs = ZOOM_connection_search_pqf(link, cl->pquery); connection_set_resultset(co, rs); connection_continue(co); } @@ -486,6 +494,7 @@ struct client *client_create(void) else r = xmalloc(sizeof(struct client)); r->pquery = 0; + r->cqlquery = 0; r->database = 0; r->connection = 0; r->session = 0; @@ -514,6 +523,7 @@ void client_destroy(struct client *c) cc->next = c->next; } xfree(c->pquery); + xfree(c->cqlquery); if (c->connection) connection_release(c->connection); @@ -567,13 +577,38 @@ static CCL_bibset prepare_cclmap(struct client *cl) return res; } +// returns a xmalloced CQL query corresponding to the pquery in client +static char *make_cqlquery(struct client *cl) +{ + cql_transform_t cqlt = cql_transform_create(); + Z_RPNQuery *zquery; + char *r; + WRBUF wrb = wrbuf_alloc(); + int status; + + zquery = p_query_rpn(global_parameters.odr_out, cl->pquery); + if ((status = cql_transform_rpn2cql_wrbuf(cqlt, wrb, zquery))) + { + yaz_log(YLOG_WARN, "failed to generate CQL query, code=%d", status); + return 0; + } + r = xstrdup(wrbuf_cstr(wrb)); + + wrbuf_destroy(wrb); + odr_reset(global_parameters.odr_out); // releases the zquery + cql_transform_close(cqlt); + return r; +} + // Parse the query given the settings specific to this client int client_parse_query(struct client *cl, const char *query) { struct session *se = client_get_session(cl); + struct session_database *sdb = client_get_database(cl); struct ccl_rpn_node *cn; int cerror, cpos; CCL_bibset ccl_map = prepare_cclmap(cl); + const char *sru = session_setting_oneval(sdb, PZ_SRU); if (!ccl_map) return -1; @@ -592,6 +627,15 @@ int client_parse_query(struct client *cl, const char *query) xfree(cl->pquery); cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf)); + xfree(cl->cqlquery); + if (*sru) + { + if (!(cl->cqlquery = make_cqlquery(cl))) + return -1; + } + else + cl->cqlquery = 0; + if (!se->relevance) { // Initialize relevance structure with query terms