From 5c017d34db6ea43ee6a95b8c462b9b824c26fbb8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 12 Oct 2009 12:22:40 +0200 Subject: [PATCH] New optional argument, maxrecs, for cmd=search --- src/client.c | 21 +++++++++--- src/client.h | 1 + src/http_command.c | 3 +- src/logic.c | 6 +++- src/pazpar2.h | 3 +- test/test_http_40.res | 65 +----------------------------------- test/test_http_41.res | 65 ++++++++++++++++++++++++++++++++++++ test/test_http_42.res | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_http_urls | 2 ++ 9 files changed, 183 insertions(+), 72 deletions(-) create mode 100644 test/test_http_41.res create mode 100644 test/test_http_42.res diff --git a/src/client.c b/src/client.c index 716651c..a7d069d 100644 --- a/src/client.c +++ b/src/client.c @@ -74,6 +74,7 @@ struct client { char *cqlquery; // used for SRU targets only int hits; int record_offset; + int maxrecs; int diagnostic; enum client_state state; struct show_raw *show_raw; @@ -497,6 +498,7 @@ void client_start_search(struct client *cl) 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); + char maxrecs_str[24]; assert(link); @@ -517,19 +519,22 @@ void client_start_search(struct client *cl) ZOOM_connection_option_set(link, "elementSetName", opt_elements); if (*opt_requestsyn) ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn); - if (!*opt_maxrecs) - opt_maxrecs = "100"; + if (!*opt_maxrecs) + { + sprintf(maxrecs_str, "%d", cl->maxrecs); + opt_maxrecs = maxrecs_str; + } ZOOM_connection_option_set(link, "count", opt_maxrecs); - if (databaseName) - ZOOM_connection_option_set(link, "databaseName", databaseName); - if (atoi(opt_maxrecs) > 20) ZOOM_connection_option_set(link, "presentChunk", "20"); else ZOOM_connection_option_set(link, "presentChunk", opt_maxrecs); + if (databaseName) + ZOOM_connection_option_set(link, "databaseName", databaseName); + if (cl->cqlquery) { ZOOM_query q = ZOOM_query_create(); @@ -560,6 +565,7 @@ struct client *client_create(void) } else r = xmalloc(sizeof(struct client)); + r->maxrecs = 100; r->pquery = 0; r->cqlquery = 0; r->database = 0; @@ -783,6 +789,11 @@ const char *client_get_url(struct client *cl) return client_get_database(cl)->database->url; } +void client_set_maxrecs(struct client *cl, int v) +{ + cl->maxrecs = v; +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/client.h b/src/client.h index c16c369..d996cd6 100644 --- a/src/client.h +++ b/src/client.h @@ -85,6 +85,7 @@ int client_get_diagnostic(struct client *cl); void client_set_database(struct client *cl, struct session_database *db); struct host *client_get_host(struct client *cl); const char *client_get_url(struct client *cl); +void client_set_maxrecs(struct client *cl, int v); #endif diff --git a/src/http_command.c b/src/http_command.c index c8bf0ba..7cbcda6 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -870,6 +870,7 @@ static void cmd_search(struct http_channel *c) struct http_session *s = locate_session(rq, rs); const char *query = http_argbyname(rq, "query"); const char *filter = http_argbyname(rq, "filter"); + const char *maxrecs = http_argbyname(rq, "maxrecs"); enum pazpar2_error_code code; const char *addinfo = 0; @@ -885,7 +886,7 @@ static void cmd_search(struct http_channel *c) error(rs, PAZPAR2_MALFORMED_PARAMETER_ENCODING, "query"); return; } - code = search(s->psession, query, filter, &addinfo); + code = search(s->psession, query, maxrecs, filter, &addinfo); if (code) { error(rs, code, addinfo); diff --git a/src/logic.c b/src/logic.c index db5b06d..2ee1203 100644 --- a/src/logic.c +++ b/src/logic.c @@ -470,7 +470,9 @@ static struct database_criterion *parse_filter(NMEM m, const char *buf) } enum pazpar2_error_code search(struct session *se, - const char *query, const char *filter, + const char *query, + const char *maxrecs, + const char *filter, const char **addinfo) { int live_channels = 0; @@ -498,6 +500,8 @@ enum pazpar2_error_code search(struct session *se, for (cl = se->clients; cl; cl = client_next_in_session(cl)) { + if (maxrecs) + client_set_maxrecs(cl, atoi(maxrecs)); if (prepare_session_database(se, client_get_database(cl)) < 0) continue; // Parse query for target diff --git a/src/pazpar2.h b/src/pazpar2.h index 738774e..028e5a7 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -162,7 +162,8 @@ void destroy_session(struct session *s); void session_init_databases(struct session *s); int load_targets(struct session *s, const char *fn); void statistics(struct session *s, struct statistics *stat); -enum pazpar2_error_code search(struct session *s, const char *query, +enum pazpar2_error_code search(struct session *s, const char *query, + const char *maxrecs, const char *filter, const char **addinfo); struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start, int *num, int *total, int *sumhits, NMEM nmem_show); diff --git a/test/test_http_40.res b/test/test_http_40.res index c78186c..ab63fe6 100644 --- a/test/test_http_40.res +++ b/test/test_http_40.res @@ -1,65 +1,2 @@ - -OK -0 -8 -30 -0 -8 - - -UTAH EARTHQUAKE EPICENTERS -UTAH EARTHQUAKE EPICENTERS -0 -title utah earthquake epicenters author medium book - - - -UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS -UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS -0 -title utah geological and mineral survey publications author medium book - - - -APPLIED GEOLOGY FILE -APPLIED GEOLOGY FILE -0 -title applied geology file author medium book - - - -UTAH CRIB FILE -UTAH CRIB FILE -0 -title utah crib file author medium book - - - -MINE MAP INDEX -MINE MAP INDEX -0 -title mine map index author medium book - - - -UTAH GEOLOGIC MAP BIBLIOGRAPHY -UTAH GEOLOGIC MAP BIBLIOGRAPHY -0 -title utah geologic map bibliography author medium book - - - -ELECTRIC LOG LIBRARY -ELECTRIC LOG LIBRARY -0 -title electric log library author medium book - - - -ISOTOPIC DATES OF ROCKS AND MINERALS -ISOTOPIC DATES OF ROCKS AND MINERALS -0 -title isotopic dates of rocks and minerals author medium book - - +OK \ No newline at end of file diff --git a/test/test_http_41.res b/test/test_http_41.res new file mode 100644 index 0000000..c78186c --- /dev/null +++ b/test/test_http_41.res @@ -0,0 +1,65 @@ + + +OK +0 +8 +30 +0 +8 + + +UTAH EARTHQUAKE EPICENTERS +UTAH EARTHQUAKE EPICENTERS +0 +title utah earthquake epicenters author medium book + + + +UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS +UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS +0 +title utah geological and mineral survey publications author medium book + + + +APPLIED GEOLOGY FILE +APPLIED GEOLOGY FILE +0 +title applied geology file author medium book + + + +UTAH CRIB FILE +UTAH CRIB FILE +0 +title utah crib file author medium book + + + +MINE MAP INDEX +MINE MAP INDEX +0 +title mine map index author medium book + + + +UTAH GEOLOGIC MAP BIBLIOGRAPHY +UTAH GEOLOGIC MAP BIBLIOGRAPHY +0 +title utah geologic map bibliography author medium book + + + +ELECTRIC LOG LIBRARY +ELECTRIC LOG LIBRARY +0 +title electric log library author medium book + + + +ISOTOPIC DATES OF ROCKS AND MINERALS +ISOTOPIC DATES OF ROCKS AND MINERALS +0 +title isotopic dates of rocks and minerals author medium book + + diff --git a/test/test_http_42.res b/test/test_http_42.res new file mode 100644 index 0000000..da57585 --- /dev/null +++ b/test/test_http_42.res @@ -0,0 +1,89 @@ + + +OK +0 +5 +11 +0 +5 + + +The Computer Bible +1973-1980 +Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates +The Computer Bible +1973-1980 +Hebrew and Greek; introductions in English +Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +30000 +title the computer bible author medium book + + + +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +Scale of maps ca. 1:1,000,000 +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +Scale of maps ca. 1:1,000,000 +Bibliography: p. 4 +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +30000 +title the puget sound region author mairs john w medium book + + + +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Includes bibliographical references and index +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Includes bibliographical references and index +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +27777 +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + + +Computer science & technology +proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976 +1977 +Computer science & technology +proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976 +1977 +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +25000 +title computer science technology author medium book + + + +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Includes bibliographical references and index +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Includes bibliographical references and index +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +17857 +title computer processing of dynamic images from an anger scintillation camera author medium book + + diff --git a/test/test_http_urls b/test/test_http_urls index 90f104e..ebc6be9 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -44,5 +44,7 @@ http://localhost:9763/search.pz2?session=5&command=show&start=0&number=1&block=1 http://localhost:9763/search.pz2?session=5&command=search&query=computer&filter=pz%3Aid%3Dunknown http://localhost:9763/search.pz2?session=3&command=settings&pz:maxrecs%5Bz3950.indexdata.com%2Fgils%5D=8 http://localhost:9763/search.pz2?session=3&command=search&query=the +http://localhost:9763/search.pz2?session=5&command=search&query=the&maxrecs=5 2 http://localhost:9763/search.pz2?session=3&command=show&start=0&number=1&block=1 +http://localhost:9763/search.pz2?session=5&command=show&start=0&number=1&block=1 -- 1.7.10.4