Show command may re-search for targets that support it
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 7 Oct 2011 13:12:16 +0000 (15:12 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 7 Oct 2011 13:12:16 +0000 (15:12 +0200)
12 files changed:
etc/default.xml
src/client.c
src/client.h
src/http_command.c
src/reclists.c
src/reclists.h
src/session.c
src/session.h
src/settings.c
src/settings.h
test/test_url.urls
test/test_url_7.res [new file with mode: 0644]

index 6dc9cae..5a9b299 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <service  xmlns="http://www.indexdata.com/pazpar2/1.0">
   <timeout session="60" z3950_operation="30" z3950_session="180"/>
-  <settings src="settings/sru-test.xml"/>
+  <settings src="settings/testserver.xml"/>
   
   <icu_chain id="relevance" locale="en">
     <transform rule="[:Control:] Any-Remove"/>
index 825d900..bf3e04c 100644 (file)
@@ -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;
index 743a509..d7da767 100644 (file)
@@ -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);
index 088a502..9874653 100644 (file)
@@ -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)
index b4e2a6d..99c9c87 100644 (file)
@@ -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++;
index 6f13e50..26ddd4b 100644 (file)
@@ -31,6 +31,7 @@ struct reclist_sortparms
     int offset;
     enum conf_sortkey_type type;
     int increasing;
+    char *name;
     struct reclist_sortparms *next;
 };
 
index 9614f15..684cd8e 100644 (file)
@@ -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);
index 2cb6289..a815446 100644 (file)
@@ -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,
index ac66c5a..d355cf3 100644 (file)
@@ -77,6 +77,7 @@ static char *hard_settings[] = {
     "pz:facetmap:",
     "pz:limitmap:",
     "pz:url",
+    "pz:sortmap:",
     0
 };
 
index 5a56750..3451588 100644 (file)
@@ -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
 {
index a79a454..eab827f 100644 (file)
@@ -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 (file)
index 0000000..eab1d5b
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<show><status>OK</status>
+<activeclients>0</activeclients>
+<merged>3</merged>
+<total>3</total>
+<start>0</start>
+<num>3</num>
+<hit>
+
+<md-title>BIBLIOGRAPHY OF MAINE GEOLOGY</md-title>
+<md-description>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</md-description><location id="my" name="marcserver">
+<md-title>BIBLIOGRAPHY OF MAINE GEOLOGY</md-title>
+<md-description tag="520">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</md-description>
+<md-description tag="513">1692-PRESENT</md-description></location>
+<recid>title bibliography of maine geology author medium book</recid>
+</hit>
+<hit>
+
+<md-title>GROUNDWATER RESOURCE MAPS - COUNTY SERIES</md-title>
+<md-description>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&apos;s comprises this data set.  Some series also show bedrock topography and potentiometric surface.  Geographic coverage is restricted to Southern Maine</md-description><location id="my" name="marcserver">
+<md-title>GROUNDWATER RESOURCE MAPS - COUNTY SERIES</md-title>
+<md-description tag="520">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&apos;s comprises this data set.  Some series also show bedrock topography and potentiometric surface.  Geographic coverage is restricted to Southern Maine</md-description>
+<md-description tag="513">1972-1978</md-description></location>
+<recid>title groundwater resource maps county series author medium book</recid>
+</hit>
+<hit>
+
+<md-title>OIL/GAS DRILLING</md-title>
+<md-description>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</md-description><location id="my" name="marcserver">
+<md-title>OIL/GAS DRILLING</md-title>
+<md-description tag="520">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</md-description>
+<md-description tag="513">1907-PRESENT</md-description></location>
+<recid>title oil gas drilling author medium book</recid>
+</hit>
+</show>
\ No newline at end of file