From d54caf29766776a237d07c93e8f2bc76f5dc9c5e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 28 Sep 2009 10:54:36 +0200 Subject: [PATCH] Implemented pz:recordfilter facility. Value of pz:recordfilter may only have one element for now. --- src/logic.c | 56 +++++++++++++++++++++- src/settings.c | 1 + src/settings.h | 1 + test/test_http_33.res | 1 + test/test_http_34.res | 1 + test/test_http_35.res | 1 + test/test_http_36.res | 126 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_http_urls | 6 ++- 8 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 test/test_http_33.res create mode 100644 test/test_http_34.res create mode 100644 test/test_http_35.res create mode 100644 test/test_http_36.res diff --git a/src/logic.c b/src/logic.c index d559670..7f23b27 100644 --- a/src/logic.c +++ b/src/logic.c @@ -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) { diff --git a/src/settings.c b/src/settings.c index a829e6d..155dac7 100644 --- a/src/settings.c +++ b/src/settings.c @@ -66,6 +66,7 @@ static char *hard_settings[] = { "pz:sru_version", "pz:pqf_prefix", "pz:sort", + "pz:recordfilter", 0 }; diff --git a/src/settings.h b/src/settings.h index 42ac11a..eb06910 100644 --- a/src/settings.h +++ b/src/settings.h @@ -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 index 0000000..5ca42b3 --- /dev/null +++ b/test/test_http_33.res @@ -0,0 +1 @@ +OK51 \ No newline at end of file diff --git a/test/test_http_34.res b/test/test_http_34.res new file mode 100644 index 0000000..523d190 --- /dev/null +++ b/test/test_http_34.res @@ -0,0 +1 @@ +OK \ No newline at end of file diff --git a/test/test_http_35.res b/test/test_http_35.res new file mode 100644 index 0000000..d2e0e58 --- /dev/null +++ b/test/test_http_35.res @@ -0,0 +1 @@ +OK \ No newline at end of file diff --git a/test/test_http_36.res b/test/test_http_36.res new file mode 100644 index 0000000..3ae8abf --- /dev/null +++ b/test/test_http_36.res @@ -0,0 +1,126 @@ + +OK +0 +8 +10 +0 +8 + + +The use of passwords for controlled access to computer resources +1977 +Wood, Helen M +The use of passwords for controlled access to computer resources +1977 +Wood, Helen M +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +title the use of passwords for controlled access to computer resources author wood helen m medium book + + + +A plan for community college computer development +1971 +Cover title +A plan for community college computer development +1971 +Cover title +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +title a plan for community college computer development author medium book + + + +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +"Contract DOT-UT-10003." +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +"Contract DOT-UT-10003." +XXXXXXXXXX +test-usersetting-2 data: + YYYYYYYYY +title washington metropolitan area rail computer feasibility study author englund carl r medium book + + + +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 +title the computer bible 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 +title computer science technology 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 +title the puget sound region author mairs john w 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 +title computer processing of dynamic images from an anger scintillation camera author 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 +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + diff --git a/test/test_http_urls b/test/test_http_urls index b2c7e15..bc45cd1 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -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 -- 1.7.10.4