FrontendPtr get_frontend(mp::Package &package);
void release_frontend(mp::Package &package);
SearchablePtr parse_torus(const xmlNode *ptr);
-
+ struct cql_node *convert_cql_fields(struct cql_node *cn, ODR odr);
std::map<mp::Session, FrontendPtr> m_clients;
boost::mutex m_mutex;
boost::condition m_cond_session_ready;
std::string torus_url;
+ std::map<std::string,std::string> fieldmap;
+ std::string xsldir;
};
}
}
(const char *) ptr3->name + 7);
}
}
- if (s->database.length() && s->target.length())
- {
- yaz_log(YLOG_LOG, "add db=%s target=%s",
- s->database.c_str(), s->target.c_str());
- }
return s;
}
}
continue;
else if (!strcmp((const char *) ptr->name, "torus"))
{
- std::string url;
const struct _xmlAttr *attr;
for (attr = ptr->properties; attr; attr = attr->next)
{
if (!strcmp((const char *) attr->name, "url"))
- url = mp::xml::get_text(attr->children);
+ torus_url = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "xsldir"))
+ xsldir = mp::xml::get_text(attr->children);
+ else
+ throw mp::filter::FilterException(
+ "Bad attribute " + std::string((const char *)
+ attr->name));
+ }
+ }
+ else if (!strcmp((const char *) ptr->name, "fieldmap"))
+ {
+ const struct _xmlAttr *attr;
+ std::string ccl_field;
+ std::string cql_field;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "ccl"))
+ ccl_field = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "cql"))
+ cql_field = mp::xml::get_text(attr->children);
else
throw mp::filter::FilterException(
"Bad attribute " + std::string((const char *)
attr->name));
}
- torus_url = url;
+ if (cql_field.length())
+ fieldmap[cql_field] = ccl_field;
}
else if (!strcmp((const char *) ptr->name, "records"))
{
xsltStylesheetPtr xsp = 0;
if (sptr->transform_xsl_fname.length())
{
- xmlDoc *xsp_doc = xmlParseFile(sptr->transform_xsl_fname.c_str());
+ std::string fname;
+
+ if (m_p->xsldir.length())
+ fname = m_p->xsldir + "/" + sptr->transform_xsl_fname;
+ else
+ fname = sptr->transform_xsl_fname;
+ xmlDoc *xsp_doc = xmlParseFile(fname.c_str());
if (!xsp_doc)
{
*error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
return records;
}
+struct cql_node *yf::Zoom::Impl::convert_cql_fields(struct cql_node *cn,
+ ODR odr)
+{
+ struct cql_node *r = 0;
+ if (!cn)
+ return 0;
+ switch (cn->which)
+ {
+ case CQL_NODE_ST:
+ if (cn->u.st.index)
+ {
+ std::map<std::string,std::string>::const_iterator it;
+ it = fieldmap.find(cn->u.st.index);
+ if (it == fieldmap.end())
+ return cn;
+ if (it->second.length())
+ cn->u.st.index = odr_strdup(odr, it->second.c_str());
+ else
+ cn->u.st.index = 0;
+ }
+ break;
+ case CQL_NODE_BOOL:
+ r = convert_cql_fields(cn->u.boolean.left, odr);
+ if (!r)
+ r = convert_cql_fields(cn->u.boolean.right, odr);
+ break;
+ case CQL_NODE_SORT:
+ r = convert_cql_fields(cn->u.sort.search, odr);
+ break;
+ }
+ return r;
+}
void yf::Zoom::Frontend::handle_search(mp::Package &package)
{
int error = 0;
const char *addinfo = 0;
std::string db(sr->databaseNames[0]);
- BackendPtr b = get_backend_from_databases(db, &error, &addinfo);
+ std::string torus_db;
+ size_t db_arg_pos = db.find(',');
+ if (db_arg_pos != std::string::npos)
+ torus_db = db.substr(0, db_arg_pos);
+ else
+ torus_db = db;
+
+ BackendPtr b = get_backend_from_databases(torus_db, &error, &addinfo);
if (error)
{
apdu_res =
return;
}
struct cql_node *cn = cql_parser_result(cp);
+ struct cql_node *cn_error = m_p->convert_cql_fields(cn, odr);
+ if (cn_error)
+ {
+ // hopefully we are getting a ptr to a index+relation+term node
+ addinfo = 0;
+ if (cn_error->which == CQL_NODE_ST)
+ addinfo = cn_error->u.st.index;
+
+ apdu_res =
+ odr.create_searchResponse(apdu_req,
+ YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
+ addinfo);
+ package.response() = apdu_res;
+ return;
+ }
char ccl_buf[1024];
r = cql_to_ccl_buf(cn, ccl_buf, sizeof(ccl_buf));
- yaz_log(YLOG_LOG, "cql_to_ccl_buf returned %d", r);
if (r == 0)
{
ccl_wrbuf = wrbuf_alloc();
assert(pqf_wrbuf == 0);
int cerror, cpos;
struct ccl_rpn_node *cn;
+ yaz_log(YLOG_LOG, "CCL: %s", wrbuf_cstr(ccl_wrbuf));
cn = ccl_find_str(b->sptr->ccl_bibset, wrbuf_cstr(ccl_wrbuf),
&cerror, &cpos);
wrbuf_destroy(ccl_wrbuf);
if (!cn)
{
char *addinfo = odr_strdup(odr, ccl_err_msg(cerror));
+ int z3950_diag = YAZ_BIB1_MALFORMED_QUERY;
+ switch (cerror)
+ {
+ case CCL_ERR_UNKNOWN_QUAL:
+ z3950_diag = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
+ break;
+ case CCL_ERR_TRUNC_NOT_LEFT:
+ case CCL_ERR_TRUNC_NOT_RIGHT:
+ case CCL_ERR_TRUNC_NOT_BOTH:
+ z3950_diag = YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE;
+ break;
+ }
apdu_res =
- odr.create_searchResponse(apdu_req,
- YAZ_BIB1_MALFORMED_QUERY,
- addinfo);
+ odr.create_searchResponse(apdu_req, z3950_diag, addinfo);
package.response() = apdu_res;
return;
}