From 6e184511abdad182c28bd6cb001e753ea3f31bd6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 1 Jun 2011 14:07:11 +0200 Subject: [PATCH] virt_db: work on query_encoding Not complete; only reading configuration. --- src/filter_virt_db.cpp | 115 ++++++++++++++++++++++++++++++------------------ src/filter_virt_db.hpp | 1 - 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index e6f2338..64ac19a 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -53,11 +53,14 @@ namespace metaproxy_1 { }; struct VirtualDB::Map { Map(std::string database, std::list targets, std::string route); + Map(std::string database, std::string target, std::string route); Map(); bool match(const std::string db) const; std::string m_dbpattern; std::list m_targets; std::string m_route; + public: + std::string m_query_encoding; }; struct VirtualDB::Backend { mp::Session m_backend_session; @@ -109,6 +112,7 @@ namespace metaproxy_1 { FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); + void refresh_torus(); private: std::listm_maps; typedef std::map::iterator Sets_it; @@ -439,52 +443,65 @@ void yf::VirtualDB::Rep::release_frontend(mp::Package &package) } } -void yf::VirtualDB::refresh_torus(void) +void yf::VirtualDB::Rep::refresh_torus(void) { - xmlDoc *doc = m_p->torus.get_doc(); - xmlNode *ptr1 = 0; - if (doc && (ptr1 = xmlDocGetRootElement(doc))) + xmlDoc *doc = torus.get_doc(); + if (!doc) + return; + + xmlNode *ptr1 = xmlDocGetRootElement(doc); + if (!ptr1) + return ; + + for (ptr1 = ptr1->children; ptr1; ptr1 = ptr1->next) { - for (ptr1 = ptr1->children; ptr1; ptr1 = ptr1->next) + if (ptr1->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((const char *) ptr1->name, "record")) { - if (ptr1->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) ptr1->name, "record")) + xmlNode *ptr2 = ptr1; + for (ptr2 = ptr2->children; ptr2; ptr2 = ptr2->next) { - xmlNode *ptr2 = ptr1; - for (ptr2 = ptr2->children; ptr2; ptr2 = ptr2->next) + if (ptr2->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((const char *) ptr2->name, "layer")) { - if (ptr2->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) ptr2->name, "layer")) + std::string database; + std::string target; + std::string route; + std::string solr; + std::string query_encoding; + xmlNode *ptr3 = ptr2; + for (ptr3 = ptr3->children; ptr3; ptr3 = ptr3->next) { - std::string database; - std::string target; - std::string route; - std::string solr; - xmlNode *ptr3 = ptr2; - for (ptr3 = ptr3->children; ptr3; ptr3 = ptr3->next) + if (ptr3->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((const char *) ptr3->name, "id")) { - if (ptr3->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) ptr3->name, "id")) - { - database = mp::xml::get_text(ptr3); - } - else if (!strcmp((const char *) ptr3->name, "zurl")) - { - target = mp::xml::get_text(ptr3); - } - else if (!strcmp((const char *) ptr3->name, "sru")) - { - solr = mp::xml::get_text(ptr3); - } + database = mp::xml::get_text(ptr3); } - if (solr.length() == 0 && - database.length() && target.length()) + else if (!strcmp((const char *) ptr3->name, "zurl")) { - add_map_db2target(database, target, route); + target = mp::xml::get_text(ptr3); } + else if (!strcmp((const char *) ptr3->name, "sru")) + { + solr = mp::xml::get_text(ptr3); + } + else if (!strcmp((const char *) ptr3->name, + "queryEncoding")) + { + query_encoding = mp::xml::get_text(ptr3); + } + } + if (solr.length() == 0 && + database.length() && target.length()) + { + VirtualDB::Map vmap( + mp::util::database_name_normalize(database), + target, route); + vmap.m_query_encoding = query_encoding; + m_maps.push_back(vmap); } } } @@ -513,6 +530,14 @@ yf::VirtualDB::Map::Map(std::string database, { } +yf::VirtualDB::Map::Map(std::string database, + std::string target, std::string route) + : m_dbpattern(database), m_route(route) +{ + m_targets.push_back(target); +} + + yf::VirtualDB::Map::Map() { } @@ -758,11 +783,10 @@ void yf::VirtualDB::add_map_db2targets(std::string db, void yf::VirtualDB::add_map_db2target(std::string db, std::string target, std::string route) -{ - std::list targets; - targets.push_back(target); - add_map_db2targets(db, targets, route); +{ + m_p->m_maps.push_back( + VirtualDB::Map(mp::util::database_name_normalize(db), target, route)); } void yf::VirtualDB::process(mp::Package &package) const @@ -888,6 +912,7 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) } else if (!strcmp((const char *) ptr->name, "virtual")) { + std::string query_encoding; std::string database; std::list targets; xmlNode *v_node = ptr->children; @@ -900,6 +925,8 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) database = mp::xml::get_text(v_node); else if (mp::xml::is_element_mp(v_node, "target")) targets.push_back(mp::xml::get_text(v_node)); + else if (mp::xml::is_element_mp(v_node, "query-encoding")) + targets.push_back(mp::xml::get_text(v_node)); else throw mp::filter::FilterException ("Bad element " @@ -908,7 +935,11 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) ); } std::string route = mp::xml::get_route(ptr); - add_map_db2targets(database, targets, route); + + VirtualDB::Map vmap(mp::util::database_name_normalize(database), + targets, route); + vmap.m_query_encoding = query_encoding; + m_p->m_maps.push_back(vmap); } else if (!strcmp((const char *) ptr->name, "torus")) { @@ -924,7 +955,7 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) attr->name)); } m_p->torus.read_searchables(url); - refresh_torus(); + m_p->refresh_torus(); } else { diff --git a/src/filter_virt_db.hpp b/src/filter_virt_db.hpp index e59f1a3..e4cb028 100644 --- a/src/filter_virt_db.hpp +++ b/src/filter_virt_db.hpp @@ -47,7 +47,6 @@ namespace metaproxy_1 { void add_map_db2target(std::string db, std::string target, std::string route); - void refresh_torus(); private: boost::scoped_ptr m_p; }; -- 1.7.10.4