Implemented pz:recordfilter facility.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 28 Sep 2009 08:54:36 +0000 (10:54 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 28 Sep 2009 08:54:36 +0000 (10:54 +0200)
Value of pz:recordfilter may only have one element for now.

src/logic.c
src/settings.c
src/settings.h
test/test_http_33.res [new file with mode: 0644]
test/test_http_34.res [new file with mode: 0644]
test/test_http_35.res [new file with mode: 0644]
test/test_http_36.res [new file with mode: 0644]
test/test_http_urls

index d559670..7f23b27 100644 (file)
@@ -1032,6 +1032,50 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no,
     return mergekey_norm;
 }
 
+/** \brief see if metadata for pz:recordfilter exists 
+    \param root xml root element of normalized record
+    \param sdb session database for client
+    \retval 0 if there is no metadata for pz:recordfilter
+    \retval 1 if there is metadata for pz:recordfilter
+
+    If there is no pz:recordfilter defined, this function returns 1
+    as well.
+*/
+    
+static int check_record_filter(xmlNode *root, struct session_database *sdb)
+{
+    int match = 0;
+    xmlNode *n;
+    const char *s;
+    s = session_setting_oneval(sdb, PZ_RECORDFILTER);
+
+    if (!s || !*s)
+        return 1;
+
+    for (n = root->children; n; n = n->next)
+    {
+        if (n->type != XML_ELEMENT_NODE)
+            continue;
+        if (!strcmp((const char *) n->name, "metadata"))
+        {
+            xmlChar *type = xmlGetProp(n, (xmlChar *) "type");
+            
+            if (!type)
+                continue;
+            if (!strcmp((const char *) type, s))
+            {
+                xmlChar *value = xmlNodeGetContent(n);
+                if (value && *value)
+                {
+                    xmlFree(value);
+                    match = 1;
+                }
+            }
+            xmlFree(type);
+        }
+    }
+    return match;
+}
 
 
 /** \brief ingest XML record
@@ -1043,8 +1087,8 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no,
 struct record *ingest_record(struct client *cl, const char *rec,
                              int record_no)
 {
-    xmlDoc *xdoc = normalize_record(client_get_database(cl),
-                                    client_get_session(cl), rec);
+    struct session_database *sdb = client_get_database(cl);
+    xmlDoc *xdoc = normalize_record(sdb, client_get_session(cl), rec);
     xmlNode *root, *n;
     struct record *record;
     struct record_cluster *cluster;
@@ -1059,6 +1103,14 @@ struct record *ingest_record(struct client *cl, const char *rec,
 
     root = xmlDocGetRootElement(xdoc);
 
+    if (!check_record_filter(root, sdb))
+    {
+        yaz_log(YLOG_WARN, "Filtered out record no %d from %s", record_no,
+            sdb->database->url);
+        xmlFreeDoc(xdoc);
+        return 0;
+    }
+
     mergekey_norm = get_mergekey(xdoc, cl, record_no, service, se->nmem);
     if (!mergekey_norm)
     {
index a829e6d..155dac7 100644 (file)
@@ -66,6 +66,7 @@ static char *hard_settings[] = {
     "pz:sru_version",
     "pz:pqf_prefix",
     "pz:sort",
+    "pz:recordfilter",
     0
 };
 
index 42ac11a..eb06910 100644 (file)
@@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #define PZ_SRU_VERSION   16
 #define PZ_PQF_PREFIX    17
 #define PZ_SORT                 18
+#define PZ_RECORDFILTER         19
 
 struct setting
 {
diff --git a/test/test_http_33.res b/test/test_http_33.res
new file mode 100644 (file)
index 0000000..5ca42b3
--- /dev/null
@@ -0,0 +1 @@
+<init><status>OK</status><session>5</session><protocol>1</protocol></init>
\ No newline at end of file
diff --git a/test/test_http_34.res b/test/test_http_34.res
new file mode 100644 (file)
index 0000000..523d190
--- /dev/null
@@ -0,0 +1 @@
+<settings><status>OK</status></settings>
\ No newline at end of file
diff --git a/test/test_http_35.res b/test/test_http_35.res
new file mode 100644 (file)
index 0000000..d2e0e58
--- /dev/null
@@ -0,0 +1 @@
+<search><status>OK</status></search>
\ No newline at end of file
diff --git a/test/test_http_36.res b/test/test_http_36.res
new file mode 100644 (file)
index 0000000..3ae8abf
--- /dev/null
@@ -0,0 +1,126 @@
+<show>
+<status>OK</status>
+<activeclients>0</activeclients>
+<merged>8</merged>
+<total>10</total>
+<start>0</start>
+<num>8</num>
+<hit>
+
+<md-title>The use of passwords for controlled access to computer resources</md-title>
+<md-date>1977</md-date>
+<md-author>Wood, Helen M</md-author><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>The use of passwords for controlled access to computer resources</md-title>
+<md-date>1977</md-date>
+<md-author>Wood, Helen M</md-author>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<recid>title the use of passwords for controlled access to computer resources author wood helen m medium book</recid>
+</hit>
+<hit>
+
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description>Cover title</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<recid>title a plan for community college computer development author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Washington metropolitan area rail computer feasibility study;</md-title>
+<md-title-remainder>final report</md-title-remainder>
+<md-date>1971</md-date>
+<md-author>Englund, Carl R</md-author>
+<md-description>&quot;Contract DOT-UT-10003.&quot;</md-description><location id="z3950.indexdata.com/marc" name="marc">
+<md-title>Washington metropolitan area rail computer feasibility study;</md-title>
+<md-title-remainder>final report</md-title-remainder>
+<md-date>1971</md-date>
+<md-author>Englund, Carl R</md-author>
+<md-description>&quot;Contract DOT-UT-10003.&quot;</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<recid>title washington metropolitan area rail computer feasibility study author englund carl r medium book</recid>
+</hit>
+<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>
+<recid>title the computer bible 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>
+<recid>title computer science technology 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>
+<recid>title the puget sound region author mairs john w 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>
+<recid>title computer processing of dynamic images from an anger scintillation camera author 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>
+<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+</hit>
+</show>
index b2c7e15..bc45cd1 100644 (file)
@@ -1,4 +1,4 @@
-http://localhost:9763/search.pz2?command=init
+http://localhost:9763/search.pz2?command=init&pz:elements[z3950.indexdata.com%2Fmarc]=F&pz:elements[z3950.indexdata.com%2Fgils]=F
 http://localhost:9763/search.pz2?session=1&command=stat
 http://localhost:9763/search.pz2?session=1&command=ping
 http://localhost:9763/search.pz2?session=1&command=search&query=computer
@@ -36,3 +36,7 @@ http://localhost:9763/search.pz2?session=4&command=settings&pz:name[z3950.indexd
 http://localhost:9763/search.pz2?session=4&command=search&query=computer
 2
 http://localhost:9763/search.pz2?session=4&command=show&start=0&number=1&block=1
+http://localhost:9763/search.pz2?command=init&clear=1
+http://localhost:9763/search.pz2?session=5&command=settings&pz:name[z3950.indexdata.com%2Fmarc]=marc&pz:requestsyntax[z3950.indexdata.com%2Fmarc]=usmarc&pz:nativesyntax[z3950.indexdata.com%2Fmarc]=iso2709&pz:xslt[z3950.indexdata.com%2Fmarc]=marc21.xsl&pz:recordfilter[z3950.indexdata.com%2Fmarc]=date
+http://localhost:9763/search.pz2?session=5&command=search&query=computer
+http://localhost:9763/search.pz2?session=5&command=show&start=0&number=1&block=1