From 646158a86d80e5ef0221ef7d7ce2cfc6ba31eacc Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 7 Oct 2011 15:12:16 +0200 Subject: [PATCH] Show command may re-search for targets that support it --- etc/default.xml | 2 +- src/client.c | 21 ++++++++++++++++++-- src/client.h | 3 ++- src/http_command.c | 14 +++++++++++++ src/reclists.c | 1 + src/reclists.h | 1 + src/session.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/session.h | 3 +++ src/settings.c | 1 + src/settings.h | 3 ++- test/test_url.urls | 3 ++- test/test_url_7.res | 35 ++++++++++++++++++++++++++++++++ 12 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 test/test_url_7.res diff --git a/etc/default.xml b/etc/default.xml index 6dc9cae..5a9b299 100644 --- a/etc/default.xml +++ b/etc/default.xml @@ -1,7 +1,7 @@ - + diff --git a/src/client.c b/src/client.c index 825d900..bf3e04c 100644 --- a/src/client.c +++ b/src/client.c @@ -665,7 +665,8 @@ int client_has_facet(struct client *cl, const char *name) return 0; } -void client_start_search(struct client *cl) +void client_start_search(struct client *cl, const char *sort_strategy, + const char *sort_spec) { struct session_database *sdb = client_get_database(cl); struct connection *co = client_get_connection(cl); @@ -741,13 +742,29 @@ void client_start_search(struct client *cl) ZOOM_query_cql(q, cl->cqlquery); if (*opt_sort) ZOOM_query_sortby(q, opt_sort); + if (sort_strategy && sort_spec) + { + yaz_log(YLOG_LOG, "applying %s %s", sort_strategy, sort_spec); + ZOOM_query_sortby2(q, sort_strategy, sort_spec); + } rs = ZOOM_connection_search(link, q); ZOOM_query_destroy(q); } else { + ZOOM_query q = ZOOM_query_create(); + yaz_log(YLOG_LOG, "Search %s PQF: %s", client_get_id(cl), cl->pquery); - rs = ZOOM_connection_search_pqf(link, cl->pquery); + + ZOOM_query_prefix(q, cl->pquery); + + if (sort_strategy && sort_spec) + { + yaz_log(YLOG_LOG, "applying %s %s", sort_strategy, sort_spec); + ZOOM_query_sortby2(q, sort_strategy, sort_spec); + } + rs = ZOOM_connection_search(link, q); + ZOOM_query_destroy(q); } ZOOM_resultset_destroy(cl->resultset); cl->resultset = rs; diff --git a/src/client.h b/src/client.h index 743a509..d7da767 100644 --- a/src/client.h +++ b/src/client.h @@ -76,7 +76,8 @@ int client_prep_connection(struct client *cl, int operation_timeout, int session_timeout, iochan_man_t iochan, const struct timeval *abstime); -void client_start_search(struct client *cl); +void client_start_search(struct client *cl, const char *sort_strategy, + const char *sort_spec); void client_set_session(struct client *cl, struct session *se); int client_is_active(struct client *cl); int client_is_active_preferred(struct client *cl); diff --git a/src/http_command.c b/src/http_command.c index 088a502..9874653 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -898,6 +898,7 @@ static void show_records(struct http_channel *c, int active) error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort"); release_session(c, s); return; + } @@ -950,13 +951,26 @@ static void cmd_show(struct http_channel *c) struct http_request *rq = c->request; struct http_session *s = locate_session(c); const char *block = http_argbyname(rq, "block"); + const char *sort = http_argbyname(rq, "sort"); + struct reclist_sortparms *sp; int status; if (!s) return; + if (!sort) + sort = "relevance"; + status = session_active_clients(s->psession); + if (!(sp = reclist_parse_sortparms(c->nmem, sort, s->psession->service))) + { + error(c->response, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort"); + release_session(c, s); + return; + } + search_sort(s->psession, sp->name, sp->increasing); + if (block) { if (!strcmp(block, "preferred") && !session_is_preferred_clients_ready(s->psession) && reclist_get_num_records(s->psession->reclist) == 0) diff --git a/src/reclists.c b/src/reclists.c index b4e2a6d..99c9c87 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -116,6 +116,7 @@ struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms, new->offset = offset; new->type = type; new->increasing = increasing; + new->name = nmem_strdup(nmem, parm); rp = &new->next; if (*(parms = cpp)) parms++; diff --git a/src/reclists.h b/src/reclists.h index 6f13e50..26ddd4b 100644 --- a/src/reclists.h +++ b/src/reclists.h @@ -31,6 +31,7 @@ struct reclist_sortparms int offset; enum conf_sortkey_type type; int increasing; + char *name; struct reclist_sortparms *next; }; diff --git a/src/session.c b/src/session.c index 9614f15..684cd8e 100644 --- a/src/session.c +++ b/src/session.c @@ -591,6 +591,59 @@ int session_is_preferred_clients_ready(struct session *s) return res == 0; } +void search_sort(struct session *se, const char *field, int increasing) +{ + struct client_list *l; + struct timeval tval; + + session_enter(se); + for (l = se->clients; l; l = l->next) + { + struct client *cl = l->client; + struct session_database *sdb = client_get_database(cl); + struct setting *s; + const char *strategy_plus_sort = 0; + + for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next) + { + char *p = strchr(s->name + 3, ':'); + if (!p) + { + yaz_log(YLOG_WARN, "Malformed sortmap name: %s", s->name); + continue; + } + p++; + if (!strcmp(p, field)) + { + strategy_plus_sort = s->value; + break; + } + } + + if (strategy_plus_sort) + { + if (client_prep_connection(cl, se->service->z3950_operation_timeout, + se->service->z3950_session_timeout, + se->service->server->iochan_man, + &tval)) + { + char **array; + int num; + nmem_strsplit(se->nmem, ":", strategy_plus_sort, &array, &num); + + if (num == 2) + { + const char *sort_spec = array[1]; + while (*sort_spec == ' ') + sort_spec++; + client_start_search(cl, array[0], sort_spec); + } + } + } + } + session_leave(se); +} + enum pazpar2_error_code search(struct session *se, const char *query, const char *startrecs, const char *maxrecs, @@ -656,7 +709,7 @@ enum pazpar2_error_code search(struct session *se, se->service->z3950_session_timeout, se->service->server->iochan_man, &tval)) - client_start_search(cl); + client_start_search(cl, 0, 0); } } facet_limits_destroy(facet_limits); diff --git a/src/session.h b/src/session.h index 2cb6289..a815446 100644 --- a/src/session.h +++ b/src/session.h @@ -146,6 +146,9 @@ struct session *new_session(NMEM nmem, struct conf_service *service, void destroy_session(struct session *s); void session_init_databases(struct session *s); void statistics(struct session *s, struct statistics *stat); + +void search_sort(struct session *se, const char *field, int increasing); + enum pazpar2_error_code search(struct session *s, const char *query, const char *startrecs, const char *maxrecs, const char *filter, const char *limit, diff --git a/src/settings.c b/src/settings.c index ac66c5a..d355cf3 100644 --- a/src/settings.c +++ b/src/settings.c @@ -77,6 +77,7 @@ static char *hard_settings[] = { "pz:facetmap:", "pz:limitmap:", "pz:url", + "pz:sortmap:", 0 }; diff --git a/src/settings.h b/src/settings.h index 5a56750..3451588 100644 --- a/src/settings.h +++ b/src/settings.h @@ -50,7 +50,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define PZ_FACETMAP 27 #define PZ_LIMITMAP 28 #define PZ_URL 29 -#define PZ_MAX_EOF 30 +#define PZ_SORTMAP 30 +#define PZ_MAX_EOF 31 struct setting { diff --git a/test/test_url.urls b/test/test_url.urls index a79a454..eab827f 100644 --- a/test/test_url.urls +++ b/test/test_url.urls @@ -1,6 +1,7 @@ http://localhost:9763/search.pz2?command=init&clear=1&pz:elements%5Bmy%5D=F&pz:requestsyntax%5Bmy%5D=usmarc&pz:nativesyntax%5Bmy%5D=iso2709&pz:xslt%5Bmy%5D=marc21_test.xsl&pz:name%5Bmy%5D=marcserver&pz:url%5Bmy%5D=z3950.indexdata.com%2Fmarc http://localhost:9763/search.pz2?session=1&command=search&query=computer 2 http://localhost:9763/search.pz2?session=1&command=show&block=1 -http://localhost:9763/search.pz2?session=1&command=settings&pz:url%5Bmy%5D=z3950.indexdata.com%2Fgils +http://localhost:9763/search.pz2?session=1&command=settings&pz:url%5Bmy%5D=z3950.indexdata.com%2Fgils&pz:sortmap:title%5Bmy%5D=type7:title+%3C http://localhost:9763/search.pz2?session=1&command=search&query=computer 2 http://localhost:9763/search.pz2?session=1&command=show&block=1 +2 http://localhost:9763/search.pz2?session=1&command=show&block=1&sort=title:1 diff --git a/test/test_url_7.res b/test/test_url_7.res new file mode 100644 index 0000000..eab1d5b --- /dev/null +++ b/test/test_url_7.res @@ -0,0 +1,35 @@ + +OK +0 +3 +3 +0 +3 + + +BIBLIOGRAPHY OF MAINE GEOLOGY +This data base is a computer based bibliography of marine geology. It allows searching by topic and geographic location, similar to GEOREF. It is currently under development to replace the printed Bibliography of Marine Geology +BIBLIOGRAPHY OF MAINE GEOLOGY +This data base is a computer based bibliography of marine geology. It allows searching by topic and geographic location, similar to GEOREF. It is currently under development to replace the printed Bibliography of Marine Geology +1692-PRESENT +title bibliography of maine geology author medium book + + + +GROUNDWATER RESOURCE MAPS - COUNTY SERIES +A series of 1:250,000 scale maps showing well yield, well depth, and depth to bedrock for a large number of bedrock wells inventoried by the Maine Geological Survey in the mid-to late 1970's comprises this data set. Some series also show bedrock topography and potentiometric surface. Geographic coverage is restricted to Southern Maine +GROUNDWATER RESOURCE MAPS - COUNTY SERIES +A series of 1:250,000 scale maps showing well yield, well depth, and depth to bedrock for a large number of bedrock wells inventoried by the Maine Geological Survey in the mid-to late 1970's comprises this data set. Some series also show bedrock topography and potentiometric surface. Geographic coverage is restricted to Southern Maine +1972-1978 +title groundwater resource maps county series author medium book + + + +OIL/GAS DRILLING +This database contains information on oil and gas drilling such as well name, operator, driller, location, depth, copies of logs run, permits, samples (cuttings, core), completion records +OIL/GAS DRILLING +This database contains information on oil and gas drilling such as well name, operator, driller, location, depth, copies of logs run, permits, samples (cuttings, core), completion records +1907-PRESENT +title oil gas drilling author medium book + + \ No newline at end of file -- 1.7.10.4