New optional argument, maxrecs, for cmd=search
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 12 Oct 2009 10:22:40 +0000 (12:22 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 12 Oct 2009 10:22:40 +0000 (12:22 +0200)
src/client.c
src/client.h
src/http_command.c
src/logic.c
src/pazpar2.h
test/test_http_40.res
test/test_http_41.res [new file with mode: 0644]
test/test_http_42.res [new file with mode: 0644]
test/test_http_urls

index 716651c..a7d069d 100644 (file)
@@ -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
index c16c369..d996cd6 100644 (file)
@@ -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
 
index c8bf0ba..7cbcda6 100644 (file)
@@ -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);
index db5b06d..2ee1203 100644 (file)
@@ -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
index 738774e..028e5a7 100644 (file)
@@ -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);
index c78186c..ab63fe6 100644 (file)
@@ -1,65 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<show>
-<status>OK</status>
-<activeclients>0</activeclients>
-<merged>8</merged>
-<total>30</total>
-<start>0</start>
-<num>8</num>
-<hit>
-
-<md-title>UTAH EARTHQUAKE EPICENTERS</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>UTAH EARTHQUAKE EPICENTERS</md-title></location>
-<relevance>0</relevance>
-<recid>title utah earthquake epicenters author medium book</recid>
-</hit>
-<hit>
-
-<md-title>UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS</md-title></location>
-<relevance>0</relevance>
-<recid>title utah geological and mineral survey publications author medium book</recid>
-</hit>
-<hit>
-
-<md-title>APPLIED GEOLOGY FILE</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>APPLIED GEOLOGY FILE</md-title></location>
-<relevance>0</relevance>
-<recid>title applied geology file author medium book</recid>
-</hit>
-<hit>
-
-<md-title>UTAH CRIB FILE</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>UTAH CRIB FILE</md-title></location>
-<relevance>0</relevance>
-<recid>title utah crib file author medium book</recid>
-</hit>
-<hit>
-
-<md-title>MINE MAP INDEX</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>MINE MAP INDEX</md-title></location>
-<relevance>0</relevance>
-<recid>title mine map index author medium book</recid>
-</hit>
-<hit>
-
-<md-title>UTAH GEOLOGIC MAP BIBLIOGRAPHY</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>UTAH GEOLOGIC MAP BIBLIOGRAPHY</md-title></location>
-<relevance>0</relevance>
-<recid>title utah geologic map bibliography author medium book</recid>
-</hit>
-<hit>
-
-<md-title>ELECTRIC LOG LIBRARY</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>ELECTRIC LOG LIBRARY</md-title></location>
-<relevance>0</relevance>
-<recid>title electric log library author medium book</recid>
-</hit>
-<hit>
-
-<md-title>ISOTOPIC DATES OF ROCKS AND MINERALS</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
-<md-title>ISOTOPIC DATES OF ROCKS AND MINERALS</md-title></location>
-<relevance>0</relevance>
-<recid>title isotopic dates of rocks and minerals author medium book</recid>
-</hit>
-</show>
+<search><status>OK</status></search>
\ No newline at end of file
diff --git a/test/test_http_41.res b/test/test_http_41.res
new file mode 100644 (file)
index 0000000..c78186c
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<show>
+<status>OK</status>
+<activeclients>0</activeclients>
+<merged>8</merged>
+<total>30</total>
+<start>0</start>
+<num>8</num>
+<hit>
+
+<md-title>UTAH EARTHQUAKE EPICENTERS</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>UTAH EARTHQUAKE EPICENTERS</md-title></location>
+<relevance>0</relevance>
+<recid>title utah earthquake epicenters author medium book</recid>
+</hit>
+<hit>
+
+<md-title>UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>UTAH GEOLOGICAL AND MINERAL SURVEY PUBLICATIONS</md-title></location>
+<relevance>0</relevance>
+<recid>title utah geological and mineral survey publications author medium book</recid>
+</hit>
+<hit>
+
+<md-title>APPLIED GEOLOGY FILE</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>APPLIED GEOLOGY FILE</md-title></location>
+<relevance>0</relevance>
+<recid>title applied geology file author medium book</recid>
+</hit>
+<hit>
+
+<md-title>UTAH CRIB FILE</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>UTAH CRIB FILE</md-title></location>
+<relevance>0</relevance>
+<recid>title utah crib file author medium book</recid>
+</hit>
+<hit>
+
+<md-title>MINE MAP INDEX</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>MINE MAP INDEX</md-title></location>
+<relevance>0</relevance>
+<recid>title mine map index author medium book</recid>
+</hit>
+<hit>
+
+<md-title>UTAH GEOLOGIC MAP BIBLIOGRAPHY</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>UTAH GEOLOGIC MAP BIBLIOGRAPHY</md-title></location>
+<relevance>0</relevance>
+<recid>title utah geologic map bibliography author medium book</recid>
+</hit>
+<hit>
+
+<md-title>ELECTRIC LOG LIBRARY</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>ELECTRIC LOG LIBRARY</md-title></location>
+<relevance>0</relevance>
+<recid>title electric log library author medium book</recid>
+</hit>
+<hit>
+
+<md-title>ISOTOPIC DATES OF ROCKS AND MINERALS</md-title><location id="z3950.indexdata.com/gils" name="Index Data GILS test server">
+<md-title>ISOTOPIC DATES OF ROCKS AND MINERALS</md-title></location>
+<relevance>0</relevance>
+<recid>title isotopic dates of rocks and minerals author medium book</recid>
+</hit>
+</show>
diff --git a/test/test_http_42.res b/test/test_http_42.res
new file mode 100644 (file)
index 0000000..da57585
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<show>
+<status>OK</status>
+<activeclients>0</activeclients>
+<merged>5</merged>
+<total>11</total>
+<start>0</start>
+<num>5</num>
+<hit>
+
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description>Hebrew and Greek; introductions in English</md-description>
+<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<relevance>30000</relevance>
+<recid>title the computer bible author medium book</recid>
+</hit>
+<hit>
+
+<md-title>The Puget Sound Region</md-title>
+<md-title-remainder>a portfolio of thematic computer maps</md-title-remainder>
+<md-date>1974</md-date>
+<md-author>Mairs, John W</md-author>
+<md-description>Scale of maps ca. 1:1,000,000</md-description><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>The Puget Sound Region</md-title>
+<md-title-remainder>a portfolio of thematic computer maps</md-title-remainder>
+<md-date>1974</md-date>
+<md-author>Mairs, John W</md-author>
+<md-description>Scale of maps ca. 1:1,000,000</md-description>
+<md-description>Bibliography: p. 4</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<relevance>30000</relevance>
+<recid>title the puget sound region author mairs john w medium book</recid>
+</hit>
+<hit>
+
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description>Includes bibliographical references and index</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<relevance>27777</relevance>
+<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Computer science &amp; technology</md-title>
+<md-title-remainder>proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976</md-title-remainder>
+<md-date>1977</md-date><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>Computer science &amp; technology</md-title>
+<md-title-remainder>proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976</md-title-remainder>
+<md-date>1977</md-date>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<relevance>25000</relevance>
+<recid>title computer science technology author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Computer processing of dynamic images from an Anger scintillation camera</md-title>
+<md-title-remainder>the proceedings of a workshop</md-title-remainder>
+<md-date>1974</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>Computer processing of dynamic images from an Anger scintillation camera</md-title>
+<md-title-remainder>the proceedings of a workshop</md-title-remainder>
+<md-date>1974</md-date>
+<md-description>Includes bibliographical references and index</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<relevance>17857</relevance>
+<recid>title computer processing of dynamic images from an anger scintillation camera author medium book</recid>
+</hit>
+</show>
index 90f104e..ebc6be9 100644 (file)
@@ -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