[phylr] r45 commited - Relational database service with BioSQL

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 29, 2009, 10:18:07 AM7/29/09
to phylr-...@googlegroups.com
Revision: 45
Author: dazhi.jiao
Date: Wed Jul 29 07:01:00 2009
Log: Relational database service with BioSQL
http://code.google.com/p/phylr/source/detail?r=45

Added:

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BioSQLDCRecordResolver.java

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BioSQLQueryTranslator.java
/trunk/phylr-gsoc/src/main/resources/BioSQL.props
Deleted:

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BasicRelationalRecordResolver.java

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BasicSQLTranslator.java
Modified:
/trunk/phylr-gsoc/README.txt
/trunk/phylr-gsoc/pom.xml

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RecordResolver.java

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RelationalQueryResult.java

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RelationalRecordIterator.java

/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/SRWRelationalDatabase.java
/trunk/phylr-gsoc/src/main/resources/SRWServer.props
/trunk/phylr-gsoc/src/main/resources/log4j.properties
/trunk/phylr-gsoc/src/main/sql/TreeBaseBioSQLMig.sql
/trunk/phylr-gsoc/src/main/webapp/stdiface.xsl

=======================================
--- /dev/null
+++
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BioSQLDCRecordResolver.java
Wed Jul 29 07:01:00 2009
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2006 OCLC Online Computer Library Center, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * BasicLuceneRecordResolver.java
+ *
+ * Created on November 1, 2006, 1:40 PM
+ */
+
+package org.nescent.phylr.relational;
+
+import gov.loc.www.zing.srw.ExtraDataType;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.oclc.os.SRW.Record;
+
+
+/**
+ *
+ * @author djiao
+ */
+public class BioSQLDCRecordResolver implements RecordResolver {
+ static Log log=LogFactory.getLog(BioSQLDCRecordResolver.class);
+ static final String
LUCENE_SCHEMA_ID="info:srw/schema/1/LuceneDocument";
+
+ /** Creates a new instance of BasicLuceneRecordResolver */
+ public BioSQLDCRecordResolver() {
+ }
+
+ public void init(Properties properties) {
+ }
+
+ public Record resolve(ResultSet result, String IdFieldName,
ExtraDataType extraDataType) {
+ String str = null;
+ try {
+ int id = result.getInt(1);
+ String xml = result.getString(2); // it expects a list dc elements
+ StringBuffer sb = new StringBuffer("<dc
xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");
+ sb.append(xml);
+ sb.append("</dc>");
+ str = sb.toString();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return new Record(str, "info:srw/schema/1/dc-v1.1");
+ }
+}
=======================================
--- /dev/null
+++
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BioSQLQueryTranslator.java
Wed Jul 29 07:01:00 2009
@@ -0,0 +1,106 @@
+package org.nescent.phylr.relational;
+
+import java.util.Properties;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.oclc.os.SRW.SRWDiagnostic;
+import org.oclc.os.SRW.SortTool;
+import org.z3950.zing.cql.CQLAndNode;
+import org.z3950.zing.cql.CQLBooleanNode;
+import org.z3950.zing.cql.CQLNode;
+import org.z3950.zing.cql.CQLNotNode;
+import org.z3950.zing.cql.CQLOrNode;
+import org.z3950.zing.cql.CQLTermNode;
+
+public class BioSQLQueryTranslator implements CqlQueryTranslator {
+ private static Log log= LogFactory.getLog(BioSQLQueryTranslator.class);
+ SRWRelationalDatabase database = null;
+
+ private String outSql = "select tree_id, xmlagg(xvalue) from ( " +
+ "SELECT tree_id, xmlforest(tq.value as \"dc:identifier\") as
xvalue " +
+ "FROM tree_qualifier_value tq, term te " +
+ "WHERE tq.term_id = te.term_id and te.name='dc.identifier' " +
+ "UNION ALL " +
+ "SELECT tq.tree_id, xmlforest(tq.value as \"dc:title\") as xvalue " +
+ "FROM tree_qualifier_value tq, term te " +
+ "WHERE tq.term_id = te.term_id and te.name='dc.title' " +
+ "UNION ALL " +
+ "SELECT tq.tree_id, xmlforest(tq.value as \"dc:abstract\") as
xvalue " +
+ "FROM tree_qualifier_value tq, term te " +
+ "WHERE tq.term_id = te.term_id and te.name='dc.abstract' " +
+ "UNION ALL " +
+ "SELECT tq.tree_id, xmlforest(tq.value as \"dc:contributor\") as
xvalue " +
+ "FROM tree_qualifier_value tq, term te " +
+ "WHERE tq.term_id = te.term_id and te.name='dc.contributor' " +
+ ") as tab " +
+ "WHERE tree_id in (?) " +
+ "GROUP BY tree_id";
+
+ private String ftSql = "select tq.tree_id from tree_qualifier_value as
tq, term as te " +
+ "where to_tsvector('english', value) @@ to_tsquery('english', ?) " +
+ "and tq.term_id = te.term_id and te.name=?";
+
+ private String eqSql = "select tq.tree_id from tree_qualifier_value as
tq, term as te " +
+ "where value=? " +
+ "and tq.term_id = te.term_id and te.name=?";
+
+// Not legal until JDK 6 @Override
+ public void init(Properties properties, SRWRelationalDatabase ldb)
throws InstantiationException {
+ this.database = ldb;
+ }
+
+// Not legal until JDK 6 @Override
+ public String makeQuery(CQLNode node, SortTool sortTool) throws
SRWDiagnostic {
+ String sql = outSql;
+ StringBuffer sb =new StringBuffer();
+ makeSQLQuery(node, sb);
+ sql = sql.replaceFirst("\\?", sb.toString());
+ return sql;
+ }
+
+ public void makeSQLQuery(CQLNode node, StringBuffer sb) {
+ if(node instanceof CQLBooleanNode) {
+ CQLBooleanNode cbn=(CQLBooleanNode)node;
+ makeSQLQuery(cbn.left, sb);
+ if(node instanceof CQLAndNode)
+ sb.append(" INTERSECT ");
+ else if(node instanceof CQLNotNode)
+ sb.append(" EXCEPT ");
+ else if(node instanceof CQLOrNode)
+ sb.append(" UNION ");
+ else sb.append(" UnknownBoolean("+cbn+") ");
+ makeSQLQuery(cbn.right, sb);
+ }
+ else if(node instanceof CQLTermNode) {
+ String sql = null;
+ CQLTermNode ctn=(CQLTermNode)node;
+ String index=ctn.getIndex();
+ if(index.equals(""))
+ index = "dc.title"; // set default field to dc:title
+
+ String term = ctn.getTerm();
+
+ if(ctn.getRelation().getBase().equals("=") ||
+ ctn.getRelation().getBase().equals("scr")) {
+ sql = eqSql.replaceFirst("\\?", "'" + term + "'");
+ } else {
+ sql = ftSql;
+ if(ctn.getRelation().getBase().equals("any")) {
+ sql = sql.replaceFirst("\\?", "'" +
StringUtils.join(StringUtils.split(term), " | ") + "'");
+ }
+ else if(ctn.getRelation().getBase().equals("all")) {
+ sql = sql.replaceFirst("\\?", "'" +
StringUtils.join(StringUtils.split(term), " & ") + "'");
+ } else if (ctn.getRelation().getBase().equals("exact")) {
+ sql = sql.replaceFirst("\\?", "'" + term + "'");
+ } else
+ sql = "Unsupported
Relation: "+ctn.getRelation().getBase();
+ }
+ sql = sql.replaceFirst("\\?", "'" + index + "'");
+ sb.append(sql);
+ }
+ else sb.append("UnknownCQLNode("+node+")");
+
+ }
+}
=======================================
--- /dev/null
+++ /trunk/phylr-gsoc/src/main/resources/BioSQL.props Wed Jul 29 07:01:00
2009
@@ -0,0 +1,43 @@
+databaseInfo.title=Phylr
+databaseInfo.description=Phylr contains a copy of the BioSQL data.
+databaseInfo.author=Phylr subgroup from the Nescent Database
Interoperability Hackathon
+databaseInfo.contact=rsch...@nescent.org
+
+configInfo.maximumRecords=50
+
+# Mapping between the CQL indexes (query fields) and searchable fields
+# within the Lucene index.
+qualifier.dc.identifier=dc.identifier
+qualifier.dc.contributor=dc.contributor
+qualifier.dc.title=dc.title
+qualifier.dc.abstract=dc.abstract
+
+# Database Connection Settings
+SRWRelationalDatabase.driver=org.postgresql.Driver
+SRWRelationalDatabase.user=djiao
+SRWRelationalDatabase.password=phylr
+SRWRelationalDatabase.url=jdbc:postgresql://pyran.ath.cx/biosql
+
+# Possible result formats
+#xmlSchemas=nexml,dc, LuceneDocument
+xmlSchemas=dc
+
+#nexml.identifier=info:http://www.nexml.org/1.0
+#nexml.location=http://www.nexml.org/1.0/nexml.xsd
+#nexml.namespace=http://www.nexml.org/1.0
+#nexml.title=Nexml
+#nexml.resolver=org.nescent.phylr.lucene.NexmlRecordResolver
+
+dc.identifier=info:srw/schema/1/dc-v1.1
+dc.location=http://www.loc.gov/standards/sru/resources/dc-schema.xsd
+dc.namespace=http://purl.org/dc/elements/1.1/
+dc.title=Dublin Core
+dc.resolver=org.nescent.phylr.relational.BioSQLDCRecordResolver
+
+#LuceneDocument.identifier=info:srw/schema/1/LuceneDocument
+#LuceneDocument.location=http://www.oclc.org/standards/Lucene/schema/LuceneDocument.xsd
+#LuceneDocument.namespace=http://www.oclc.org/LuceneDocument
+#LuceneDocument.title=Lucene records in their internal format
+
+
+
=======================================
---
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BasicRelationalRecordResolver.java
Sun Jul 12 07:58:40 2009
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Copyright 2006 OCLC Online Computer Library Center, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * BasicLuceneRecordResolver.java
- *
- * Created on November 1, 2006, 1:40 PM
- */
-
-package org.nescent.phylr.relational;
-
-import gov.loc.www.zing.srw.ExtraDataType;
-
-import java.sql.ResultSet;
-import java.util.Iterator;
-import java.util.Properties;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.oclc.os.SRW.Record;
-import org.oclc.os.SRW.Utilities;
-
-
-/**
- *
- * @author levan
- */
-public class BasicRelationalRecordResolver implements RecordResolver {
- static Log log=LogFactory.getLog(BasicRelationalRecordResolver.class);
- static final String
LUCENE_SCHEMA_ID="info:srw/schema/1/LuceneDocument";
-
- /** Creates a new instance of BasicLuceneRecordResolver */
- public BasicRelationalRecordResolver() {
- }
-
-// Not legal until JDK 6 @Override
- public void init(Properties properties) {
- }
-
-// Not legal until JDK 6 @Override
- public Record resolve(ResultSet result, String IdFieldName,
ExtraDataType extraDataType) {
- /*
- // Enumeration fields=doc.fields(); // lucene 1.4
- Iterator fields=doc.getFields().iterator();
- Field field;
- StringBuffer sb=new StringBuffer("<LuceneDocument
xmlns=\"http://www.oclc.org/LuceneDocument\">");
- // while(fields.hasMoreElements()) {
- while(fields.hasNext()) {
- // field=(Field)fields.nextElement();
- field=(Field)fields.next();
- sb.append("<field name=\"").append(field.name()).append("\">");
-
- String fieldVal = field.stringValue();
- int firstNewline = fieldVal.indexOf("\n");
- log.error("Trimmed: " + fieldVal.substring(0,firstNewline));
-
- // sb.append(fieldVal.substring(firstNewline));
- sb.append("</field>");
- }
- sb.append("</LuceneDocument>");
- return new Record(sb.toString(), LUCENE_SCHEMA_ID);
- */
- return null;
- }
-}
=======================================
---
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/BasicSQLTranslator.java
Sun Jul 12 07:58:40 2009
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.nescent.phylr.relational;
-
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.oclc.os.SRW.SRWDiagnostic;
-import org.oclc.os.SRW.SortTool;
-import org.z3950.zing.cql.CQLNode;
-
-public class BasicSQLTranslator implements CqlQueryTranslator {
- private static Log log= LogFactory.getLog(BasicSQLTranslator.class);
-
-// Not legal until JDK 6 @Override
- public void init(Properties properties, SRWRelationalDatabase ldb)
throws InstantiationException {
- }
-
-// Not legal until JDK 6 @Override
- public String makeQuery(CQLNode node, SortTool sortTool) throws
SRWDiagnostic {
- return "";
- }
-
-
-}
=======================================
--- /trunk/phylr-gsoc/README.txt Thu Jun 25 08:05:43 2009
+++ /trunk/phylr-gsoc/README.txt Wed Jul 29 07:01:00 2009
@@ -18,3 +18,27 @@
-Dexec.mainClass=org.nescent.phylr.lucene.NexmlIndexer \
-Dexec.args="-d data/phylr-nexml/ -i data/phylr-index/ -m
src/test/resources/predicates.txt"

+To Migrate Data from TreeBase (PostgreSQL)
+First create database
+# createdb biosql
+
+import treebase dump into the database
+# psql biosql < treebase.sql
+
+create biosql tables using the schema
+# psql biosql < biosqldb-pg.sql
+
+Because both treebase and biosql phylodb extension have a table
name "node_path",
+so rename "node_path" to "bs_node_path" in biosql-phylodb-pg.sql
+THen Create tables in the biosql-phylodb extension
+# psql biosql < biosql-phylodb-pg.sql
+
+Now import the ncbi taxonomy using the biosql import script
+# load_ncbi_taxonomy.pl --diver Pg --download yes --dbname biosql
+
+Then execute the migration script
+# psql biosql < TreeBaseBioSQLMig.sql
+
+All done.
+
+
=======================================
--- /trunk/phylr-gsoc/pom.xml Wed Jun 24 19:26:41 2009
+++ /trunk/phylr-gsoc/pom.xml Wed Jul 29 07:01:00 2009
@@ -123,6 +123,20 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>biojava</groupId>
+ <artifactId>biojava</artifactId>
+ <version>1.7</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>8.3-603.jdbc4</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
<finalName>phylr-gsoc</finalName>
@@ -130,8 +144,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.5</source>
- <target>1.5</target>
+ <source>1.6</source>
+ <target>1.6</target>
</configuration>
</plugin>
<plugin>
=======================================
---
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RecordResolver.java
Sun Jul 12 07:58:40 2009
+++
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RecordResolver.java
Wed Jul 29 07:01:00 2009
@@ -20,7 +20,7 @@

import java.sql.ResultSet;
import java.util.Properties;
-import org.apache.lucene.document.Document;
+
import org.oclc.os.SRW.Record;

/**
=======================================
---
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RelationalQueryResult.java
Sun Jul 12 07:58:40 2009
+++
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RelationalQueryResult.java
Wed Jul 29 07:01:00 2009
@@ -15,6 +15,7 @@
ResultSet hits=null;
SRWRelationalDatabase ldb=null;
long count = -1;
+ RelationalRecordIterator localIterator = null;

/** Creates a new instance of LuceneQueryResult */
public RelationalQueryResult() {
@@ -25,6 +26,20 @@
this.ldb=ldb;
this.hits=hits;
}
+
+ @Override
+ public void close() {
+ super.close();
+ log.info("RelationalResultSet close");
+ try {
+ if (!this.hits.isClosed()) {
+ this.hits.close();
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }

@Override
public long getNumberOfRecords() {
@@ -36,6 +51,7 @@
try {
hits.last();
count = hits.getRow();
+ hits.beforeFirst();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -48,11 +64,16 @@
public QueryResult getSortedResult(String sortKeys) {
return this;
}
-
+
@Override
public RecordIterator newRecordIterator(long whichRec, int numRecs,
String schemaId, ExtraDataType edt) throws InstantiationException {
log.debug("whichRec="+whichRec+", numRecs="+numRecs+",
schemaId="+schemaId+", edt="+edt);
- return new RelationalRecordIterator(whichRec, schemaId, this,
(RecordResolver)ldb.resolvers.get(schemaId), edt);
+ if (this.localIterator == null) {
+ this.localIterator = new RelationalRecordIterator(whichRec,
schemaId, this, (RecordResolver)ldb.resolvers.get(schemaId), edt);
+ } else {
+ localIterator.go(whichRec);
+ }
+ return localIterator;
}
}
=======================================
---
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RelationalRecordIterator.java
Sun Jul 12 07:58:40 2009
+++
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/RelationalRecordIterator.java
Wed Jul 29 07:01:00 2009
@@ -24,6 +24,7 @@
import gov.loc.www.zing.srw.ExtraDataType;

import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.NoSuchElementException;

import org.apache.commons.logging.Log;
@@ -55,18 +56,38 @@
this.resolver=resolver;
this.edt=edt;
}
+
+ public void go(long whichRec) {
+ ResultSet hits = result.hits;
+ try {
+ hits.absolute(new Long(whichRec-1).intValue());
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }

public void close() {
try {
- result.hits.close();
- } catch (Exception ex) {}
+ if (!this.result.hits.isClosed())
+ this.result.hits.close();
+ } catch (Exception ex) {
+ log.error("Failed to close ResultSet object: " + ex.getMessage());
+ }
}

public boolean hasNext() {
log.debug("whichRec="+whichRec+",
result.getNumberOfRecords()="+result.getNumberOfRecords());
- if(whichRec<=result.getNumberOfRecords())
- return true;
- return false;
+ try {
+ if (result.hits.isAfterLast()) {
+ return false;
+ } else {
+ return true;
+ }
+ } catch (SQLException e) {
+ log.error(e.getMessage());
+ }
+ return true;
}

public Object next() throws NoSuchElementException {
@@ -78,8 +99,7 @@
try {
hits.next();
return resolver.resolve(hits, result.ldb.idFieldName, edt);
- }
- catch(Exception e) {
+ } catch(Exception e) {
log.error(e, e);
log.error("whichRec="+whichRec);
throw new NoSuchElementException(e.getMessage());
=======================================
---
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/SRWRelationalDatabase.java
Sun Jul 12 07:58:40 2009
+++
/trunk/phylr-gsoc/src/main/java/org/nescent/phylr/relational/SRWRelationalDatabase.java
Wed Jul 29 07:01:00 2009
@@ -8,8 +8,10 @@
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
+import java.util.StringTokenizer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -26,12 +28,19 @@
static Log log = LogFactory.getLog(SRWRelationalDatabase.class);

CqlQueryTranslator translator = null;
- // Hashtable indexSynonyms=new Hashtable();
Hashtable<String, RecordResolver> resolvers = new Hashtable<String,
RecordResolver>();
String idFieldName = null, indexInfo = null;

Connection connection = null;

+ public Connection getConnection() {
+ return connection;
+ }
+
+ public void setConnection(Connection connection) {
+ this.connection = connection;
+ }
+
@Override
public void addRenderer(String schemaName, String schemaID, Properties
props)
throws InstantiationException {
@@ -40,7 +49,7 @@
.getProperty(schemaName + ".resolver");
if (resolverName == null) {
log.debug("creating BasicRelationalResolver");
- resolver = new BasicRelationalRecordResolver();
+ resolver = new BioSQLDCRecordResolver();
resolver.init(props);
} else {
try {
@@ -69,10 +78,92 @@
@Override
public String getIndexInfo() {
if (indexInfo == null) {
- // TODO: to implement
+ indexInfo = makeIndexInfo(dbProperties, null);
}
return indexInfo;
}
+
+ public static String makeIndexInfo(Properties props, Hashtable<String,
String> indexMappings) {
+ Hashtable<String, String> sets=new Hashtable<String, String>();
+ int indexNum=0;
+ String index, indexSet, luceneIndex, prop;
+ StringBuffer sb=new StringBuffer(" <indexInfo>\n");
+ StringTokenizer st;
+
+ makeUnqualifiedIndexes(props);
+
+ Enumeration enumer=props.propertyNames();
+ while(enumer.hasMoreElements()) {
+ prop=(String)enumer.nextElement();
+ if(prop.startsWith("qualifier.")) {
+ st=new StringTokenizer(prop.substring(10));
+ index=st.nextToken();
+ st=new StringTokenizer(index, ".");
+ if(st.countTokens()==1) {
+ indexSet="local";
+ index=prop.substring(10);
+ }
+ else {
+ indexSet=st.nextToken();
+ index=prop.substring(10+indexSet.length()+1);
+ }
+
+ if(log.isDebugEnabled())log.debug("indexSet="+indexSet+",
index="+index);
+ if(sets.get(indexSet)==null) { // new set
+ sb.append(" <set identifier=\"")
+ .append(props.getProperty("indexSet."+indexSet))
+ .append("\"
name=\"").append(indexSet).append("\"/>\n");
+ sets.put(indexSet, indexSet);
+ }
+ sb.append(" <index>\n")
+ .append("
<title>").append(indexSet).append('.').append(index).append("</title>\n")
+ .append(" <map>\n")
+ .append(" <name
set=\"").append(indexSet).append("\">").append(index).append("</name>\n")
+ .append(" </map>\n")
+ .append(" </index>\n");
+
+ if(indexMappings!=null) {
+ // now for a bit of trickery for the CQL parser
+ // the line we just read isn't in the format the parser
+ // expect. we just read:
+ // qualifier.<indexSet>.indexName=luceneIndexName
+ // the parser is expecting:
+ //
qualifier.<indexSet>.indexName=1=<z39.50UseAttribute>
+ // it doesn't really care what Use attribute we
provide,
+ // so we'll make up Use attribute numbers to correspond
+ // with the lucene indexes.
+ luceneIndex=props.getProperty(prop);
+ indexMappings.put(indexSet+"."+index, luceneIndex);
+ if(log.isDebugEnabled())
+ log.debug("mapping "+indexSet+"."+index+"
to "+luceneIndex);
+ props.put(prop, "1="+(++indexNum));
+ }
+ }
+ else if(prop.startsWith("hiddenQualifier.")) {
+ st=new StringTokenizer(prop.substring(16));
+ index=st.nextToken();
+ if(indexMappings!=null) {
+ // now for a bit of trickery for the CQL parser
+ // the line we just read isn't in the format the parser
+ // expect. we just read:
+ // qualifier.<indexSet>.indexName=luceneIndexName
+ // the parser is expecting:
+ //
qualifier.<indexSet>.indexName=1=<z39.50UseAttribute>
+ // it doesn't really care what Use attribute we
provide,
+ // so we'll make up Use attribute numbers to correspond
+ // with the lucene indexes.
+ luceneIndex=props.getProperty(prop);
+ indexMappings.put(index, luceneIndex);
+ if(log.isDebugEnabled())
+ log.debug("mapping "+index+" to "+luceneIndex);
+ props.put(prop, "1="+(++indexNum));
+ }
+ }
+ }
+ sb.append(" </indexInfo>\n");
+ return sb.toString();
+ }
+

@Override
public QueryResult getQueryResult(String queryStr,
@@ -112,14 +203,6 @@
lqr.addDiagnostic(SRWDiagnostic.GeneralSystemError, e.getMessage());
return lqr;
} finally {
- /*
- if (results != null) {
- try { results.close(); } catch (Exception ex) {}
- }
- if (stmt != null) {
- try { stmt.close(); } catch (Exception ex) {}
- }
- */
}
}

@@ -173,8 +256,18 @@

maxTerms = 10;
position = 1;
+
+ String driver = dbProperties.getProperty("SRWRelationalDatabase.driver");
+ try {
+ Class.forName(driver);
+ } catch (ClassNotFoundException e1) {
+ log.error("Database driver not found: " + driver);
+ throw new InstantiationException("Database driver not found: " +
driver);
+ }

String url = dbProperties.getProperty("SRWRelationalDatabase.url");
+ String username = dbProperties.getProperty("SRWRelationalDatabase.user");
+ String password =
dbProperties.getProperty("SRWRelationalDatabase.password");
log.debug("db url=" + url);

if (url == null) {
@@ -183,7 +276,7 @@
}

try {
- connection = DriverManager.getConnection(url);
+ connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
log.error("Unable to create connection with url=" + url
+ " for database " + dbname);
=======================================
--- /trunk/phylr-gsoc/src/main/resources/SRWServer.props Wed Jun 24
19:53:15 2009
+++ /trunk/phylr-gsoc/src/main/resources/SRWServer.props Wed Jul 29
07:01:00 2009
@@ -55,6 +55,10 @@
db.treebase.home=/home/djiao/workspace/phylr-gsoc/data/phylr-index
db.treebase.configuration=TreeIndex.props

+db.biosql.class=org.nescent.phylr.relational.SRWRelationalDatabase
+db.biosql.home=/home/djiao/workspace/phylr-gsoc/data/phylr-index
+db.biosql.configuration=BioSQL.props
+
db.lucene.class=org.oclc.os.SRW.Lucene.SRWLuceneDatabase
db.lucene.home=/Users/ryan/phylr-data/dryadSearch
db.lucene.configuration=Test.props
=======================================
--- /trunk/phylr-gsoc/src/main/resources/log4j.properties Wed Jun 24
19:53:15 2009
+++ /trunk/phylr-gsoc/src/main/resources/log4j.properties Wed Jul 29
07:01:00 2009
@@ -8,7 +8,7 @@
#log4j.logger.org.oclc.os.SRW.DSpaceLucene.SRWLuceneDatabase=DEBUG
#log4j.logger.org.oclc.os.SRW.SRWDatabaseImpl=INFO
#log4j.logger.org.oclc.os.SRW.SRWDatabase=INFO
-log4j.logger.org.oclc.os.SRW=DEBUG
+log4j.logger.org.oclc.os.SRW=INFO

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
=======================================
--- /trunk/phylr-gsoc/src/main/sql/TreeBaseBioSQLMig.sql Mon Jul 27
11:01:26 2009
+++ /trunk/phylr-gsoc/src/main/sql/TreeBaseBioSQLMig.sql Wed Jul 29
07:01:00 2009
@@ -85,10 +85,10 @@

-- STUDY
INSERT INTO ontology (name, definition) VALUES ('Dublin Core', 'Dublin
Core Metadata Initiative (DCMI)');
-INSERT INTO term (name, ontology_id) SELECT 'identifier',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
-INSERT INTO term (name, ontology_id) SELECT 'contributor',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
-INSERT INTO term (name, ontology_id) SELECT 'title', ontology.ontology_id
FROM ontology WHERE ontology.name = 'Dublin Core';
-INSERT INTO term (name, ontology_id) SELECT 'abstract',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
+INSERT INTO term (name, ontology_id) SELECT 'dc.identifier',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
+INSERT INTO term (name, ontology_id) SELECT 'dc.contributor',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
+INSERT INTO term (name, ontology_id) SELECT 'dc.title',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
+INSERT INTO term (name, ontology_id) SELECT 'dc.abstract',
ontology.ontology_id FROM ontology WHERE ontology.name = 'Dublin Core';
INSERT INTO term (name, ontology_id) SELECT 'study.doi',
ontology.ontology_id FROM ontology WHERE ontology.name = 'TreeBase DB';

INSERT INTO tree_qualifier_value (tree_id, term_id, value)
@@ -117,4 +117,11 @@
-- Rename table node_path back
ALTER TABLE bs_node_path RENAME TO node_path;

-
+-- Create full text index
+CREATE INDEX ft_tree_qualifier_value_idx ON tree_qualifier_value USING
gin(to_tsvector('english', value))
+
+CREATE INDEX term_name_idx ON term USING btree (name);
+
+
+
+
=======================================
--- /trunk/phylr-gsoc/src/main/webapp/stdiface.xsl Fri Jul 10 11:45:16 2009
+++ /trunk/phylr-gsoc/src/main/webapp/stdiface.xsl Wed Jul 29 07:01:00 2009
@@ -22,12 +22,6 @@
input.button { margin: 0; }
--&gt;
</style>
-<script type="text/javascript" src="ext-core.js"/>
-<script type="text/javascript">
-<![CDATA[
-
-]]>
-</script>
</head>
<body>
<div id="masthead">

Reply all
Reply to author
Forward
0 new messages