Merge branch 'master' of ssh://git@gitorious.org/yacy/rc1.git

Conflicts:
	source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java
pull/1/head
Michael Peter Christen 12 years ago
commit 80fe3d7860

@ -43,8 +43,6 @@
<classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/> <classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
<classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/> <classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="lib/servlet-api-2.5-20081211.jar"/> <classpathentry kind="lib" path="lib/servlet-api-2.5-20081211.jar"/>
<classpathentry kind="lib" path="lib/jetty-6.1.26-patched-JETTY-1340.jar"/>
<classpathentry kind="lib" path="lib/jetty-util-6.1.26-patched-JETTY-1340.jar"/>
<classpathentry kind="lib" path="lib/jaudiotagger-2.0.4-20111207.115108-15.jar"/> <classpathentry kind="lib" path="lib/jaudiotagger-2.0.4-20111207.115108-15.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.7.jar"/> <classpathentry kind="lib" path="lib/commons-codec-1.7.jar"/>
<classpathentry kind="lib" path="lib/spatial4j-0.3.jar"/> <classpathentry kind="lib" path="lib/spatial4j-0.3.jar"/>

@ -66,8 +66,6 @@
<string>$JAVAROOT/lib/jcl-over-slf4j-1.7.2.jar</string> <string>$JAVAROOT/lib/jcl-over-slf4j-1.7.2.jar</string>
<string>$JAVAROOT/lib/jempbox-1.7.1.jar</string> <string>$JAVAROOT/lib/jempbox-1.7.1.jar</string>
<string>$JAVAROOT/lib/jena-2.6.4.jar</string> <string>$JAVAROOT/lib/jena-2.6.4.jar</string>
<string>$JAVAROOT/lib/jetty-6.1.26-patched-JETTY-1340.jar</string>
<string>$JAVAROOT/lib/jetty-util-6.1.26-patched-JETTY-1340.jar</string>
<string>$JAVAROOT/lib/jsch-0.1.42.jar</string> <string>$JAVAROOT/lib/jsch-0.1.42.jar</string>
<string>$JAVAROOT/lib/json-simple-1.1.jar</string> <string>$JAVAROOT/lib/json-simple-1.1.jar</string>
<string>$JAVAROOT/lib/log4j-1.2.17.jar</string> <string>$JAVAROOT/lib/log4j-1.2.17.jar</string>

@ -185,8 +185,6 @@
<pathelement location="${lib}/jcl-over-slf4j-1.7.2.jar" /> <pathelement location="${lib}/jcl-over-slf4j-1.7.2.jar" />
<pathelement location="${lib}/jempbox-1.7.1" /> <pathelement location="${lib}/jempbox-1.7.1" />
<pathelement location="${lib}/jena-2.6.4.jar" /> <pathelement location="${lib}/jena-2.6.4.jar" />
<pathelement location="${lib}/jetty-6.1.26-patched-JETTY-1340.jar" />
<pathelement location="${lib}/jetty-util-6.1.26-patched-JETTY-1340.jar" />
<pathelement location="${lib}/jsch-0.1.42.jar" /> <pathelement location="${lib}/jsch-0.1.42.jar" />
<pathelement location="${lib}/json-simple-1.1.jar" /> <pathelement location="${lib}/json-simple-1.1.jar" />
<pathelement location="${lib}/jsoup-1.6.3.jar" /> <pathelement location="${lib}/jsoup-1.6.3.jar" />
@ -433,7 +431,7 @@
<classpath> <classpath>
<pathelement location="${build}"/> <pathelement location="${build}"/>
<pathelement location="${htroot}"/> <pathelement location="${htroot}"/>
<pathelement location="${libt}/junit-4.7.jar" /> <fileset dir="${libt}" includes="**/*.jar" />
<fileset dir="${lib}" includes="**/*.jar" /> <fileset dir="${lib}" includes="**/*.jar" />
</classpath> </classpath>
<compilerarg value="-Xlint"/> <compilerarg value="-Xlint"/>
@ -441,7 +439,7 @@
</target> </target>
<target name="test" depends="compileTest" description="run some unittests"> <target name="test" depends="compileTest" description="run some unittests">
<junit printsummary="yes" haltonfailure="no"> <junit printsummary="yes" haltonfailure="no" fork="true" dir="${yacyroot}">
<formatter type="plain"/> <formatter type="plain"/>
<batchtest> <batchtest>
<fileset dir="${test}"> <fileset dir="${test}">
@ -452,7 +450,7 @@
<pathelement location="${test}"/> <pathelement location="${test}"/>
<pathelement location="${build}"/> <pathelement location="${build}"/>
<pathelement location="${htroot}"/> <pathelement location="${htroot}"/>
<pathelement location="${libt}/junit-4.7.jar" /> <fileset dir="${libt}" includes="**/*.jar" />
<fileset dir="${lib}" includes="**/*.jar" /> <fileset dir="${lib}" includes="**/*.jar" />
</classpath> </classpath>
</junit> </junit>
@ -518,6 +516,7 @@
<fileset dir="${libbuild}/GitRevTask" includes="**/*.class" /> <fileset dir="${libbuild}/GitRevTask" includes="**/*.class" />
<fileset dir="." includes="TEST-*" /> <fileset dir="." includes="TEST-*" />
</delete> </delete>
<delete dir="test/DATA" failonerror="false"/>
</target> </target>
<target name="installonlinux"> <target name="installonlinux">

@ -59,10 +59,6 @@ import org.apache.solr.servlet.SolrRequestParsers;
import org.apache.solr.servlet.cache.HttpCacheHeaderUtil; import org.apache.solr.servlet.cache.HttpCacheHeaderUtil;
import org.apache.solr.servlet.cache.Method; import org.apache.solr.servlet.cache.Method;
import org.apache.solr.util.FastWriter; import org.apache.solr.util.FastWriter;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.FilterHolder;
public class SolrServlet implements Filter { public class SolrServlet implements Filter {
@ -196,38 +192,6 @@ public class SolrServlet implements Filter {
hresponse.sendError((code < 100) ? 500 : code, ex.getMessage() + "\n\n" + sw.toString()); hresponse.sendError((code < 100) ? 500 : code, ex.getMessage() + "\n\n" + sw.toString());
} }
/**
* from org.apache.solr.client.solrj.embedded.JettySolrRunner
*/
public static Server startServer(String context, int port, EmbeddedSolrConnector c) {
//this.context = context;
Server server = new Server(port);
/*
SocketConnector connector = new SocketConnector();
connector.setPort(port);
connector.setReuseAddress(true);
this.server.setConnectors(new Connector[] { connector });
this.server.setSessionIdManager(new HashSessionIdManager(new Random()));
*/
server.setStopAtShutdown(true);
Context root = new Context(server, context, Context.SESSIONS);
root.addServlet(Servlet404.class, "/*");
// attach org.apache.solr.response.XMLWriter to search requests
SolrServlet.initCore(c);
FilterHolder dispatchFilter = root.addFilter(SolrServlet.class, "*", Handler.REQUEST);
if (!server.isRunning()) {
try {
server.start();
waitForSolr(context, port);
} catch (Exception e) {
e.printStackTrace();
}
}
return server;
}
public static void waitForSolr(String context, int port) throws Exception { public static void waitForSolr(String context, int port) throws Exception {
// A raw term query type doesn't check the schema // A raw term query type doesn't check the schema
URL url = new URL("http://127.0.0.1:" + port + context + "/select?q={!raw+f=test_query}ping"); URL url = new URL("http://127.0.0.1:" + port + context + "/select?q={!raw+f=test_query}ping");

@ -24,18 +24,13 @@ package net.yacy.cora.federate.solr.connector;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import net.yacy.cora.federate.solr.SolrServlet;
import net.yacy.cora.federate.solr.YaCySchema;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.MemoryControl; import net.yacy.kelondro.util.MemoryControl;
import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
@ -198,37 +193,4 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
} }
} }
public static void main(String[] args) {
File solr_config = new File("defaults/solr");
File storage = new File("DATA/INDEX/webportal/SEGMENTS/text/solr/");
storage.mkdirs();
try {
EmbeddedSolrConnector solr = new EmbeddedSolrConnector(storage, solr_config);
SolrInputDocument doc = new SolrInputDocument();
doc.addField(YaCySchema.id.name(), "ABCD0000abcd");
doc.addField(YaCySchema.title.name(), "Lorem ipsum");
doc.addField(YaCySchema.host_s.name(), "yacy.net");
doc.addField(YaCySchema.text_t.name(), "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
solr.add(doc);
// start a server
SolrServlet.startServer("/solr", 8091, solr); // try http://localhost:8091/solr/select?q=*:*
// do a normal query
SolrDocumentList select = solr.query(YaCySchema.text_t.name() + ":tempor", 0, 10);
for (SolrDocument d : select) System.out.println("***TEST SELECT*** " + d.toString());
// do a facet query
select = solr.query(YaCySchema.text_t.name() + ":tempor", 0, 10);
for (SolrDocument d : select) System.out.println("***TEST SELECT*** " + d.toString());
// try http://127.0.0.1:8091/solr/select?q=ping
try {Thread.sleep(1000 * 1000);} catch (InterruptedException e) {}
solr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }

@ -40,8 +40,6 @@ import java.nio.channels.FileLock;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import sun.security.action.GetBooleanAction;
import net.yacy.cora.date.GenericFormatter; import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.lod.JenaTripleStore; import net.yacy.cora.lod.JenaTripleStore;
import net.yacy.cora.protocol.ClientIdentification; import net.yacy.cora.protocol.ClientIdentification;

@ -41,9 +41,9 @@ public class ParserTest {
final String mimetype = testFile[1]; final String mimetype = testFile[1];
final DigestURI url = new DigestURI("http://localhost/"+filename); final DigestURI url = new DigestURI("http://localhost/"+filename);
final Document[] docs = TextParser.parseSource(url, mimetype, null, file.length(), new FileInputStream(file), true); final Document[] docs = TextParser.parseSource(url, mimetype, null, file.length(), new FileInputStream(file));
for (final Document doc: docs) { for (final Document doc: docs) {
final Reader content = new InputStreamReader(doc.getText(), doc.getCharset()); final Reader content = new InputStreamReader(doc.getTextStream(), doc.getCharset());
final StringBuilder str = new StringBuilder(); final StringBuilder str = new StringBuilder();
int c; int c;
while( (c = content.read()) != -1 ) while( (c = content.read()) != -1 )

@ -23,15 +23,19 @@ public class yacyURLTest extends TestCase {
new String[]{"/test/test2/../hallo/","/test/hallo/"}, new String[]{"/test/test2/../hallo/","/test/hallo/"},
new String[]{"/home/..test/../hallo/../","/home/"} new String[]{"/home/..test/../hallo/../","/home/"}
}; };
String testhost = "http://localhost";
for (int i=0; i < testStrings.length; i++) { for (int i=0; i < testStrings.length; i++) {
// desired conversion result // desired conversion result
System.out.print("testResolveBackpath: " + testStrings[i][0]); System.out.print("testResolveBackpath: " + testStrings[i][0]);
String shouldBe = testStrings[i][1]; String shouldBe = testhost + testStrings[i][1];
// conversion result // conversion result
String resolvedURL = MultiProtocolURI.resolveBackpath(testStrings[i][0]); String resolvedURL="";
try {
resolvedURL = (new MultiProtocolURI(testhost + testStrings[i][0])).toString();
} catch (MalformedURLException ex) {
fail ("malformed URL");
}
// test if equal // test if equal
assertEquals(shouldBe,resolvedURL); assertEquals(shouldBe,resolvedURL);
System.out.println(" -> " + resolvedURL); System.out.println(" -> " + resolvedURL);

@ -28,7 +28,7 @@ public class MultiProtocolURITest {
for (int i=0; i<testURIs.length; i++) { for (int i=0; i<testURIs.length; i++) {
MultiProtocolURI uri = new MultiProtocolURI(testURIs[i][0]); MultiProtocolURI uri = new MultiProtocolURI(testURIs[i][0]);
assertEquals(uri.toNormalform(true, true, false, true), testURIs[i][1]); assertEquals(uri.toNormalform(true, true), testURIs[i][1]);
} }
} }
} }

@ -0,0 +1,184 @@
package net.yacy.cora.federate.solr.connector;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.yacy.cora.federate.solr.SolrServlet;
import net.yacy.cora.federate.solr.YaCySchema;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.FilterHolder;
public class EmbeddedSolrConnectorTest {
Server jetty; // Jetty server
EmbeddedSolrConnector solr;
public EmbeddedSolrConnectorTest() {
}
@Before
public void setUp() {
File solr_config = new File("defaults/solr");
File storage = new File("test/DATA/INDEX/webportal/SEGMENTS/text/solr/");
storage.mkdirs();
System.out.println("setup EmeddedSolrConnector using config dir: " + solr_config.getAbsolutePath());
try {
solr = new EmbeddedSolrConnector(storage, solr_config);
// start a server
jetty = startServer("/solr", 8091, solr); // try http://localhost:8091/solr/select?q=*:*
} catch (IOException ex) {
fail("IOException starting Jetty");
}
}
@After
public void tearDown() {
if (jetty != null) {
try {
jetty.stop();
} catch (Exception ex) {
fail("Exception stopping Jetty");
}
}
solr.close();
}
/**
* Test of query solr via jetty
*/
@Test
public void testQuery() {
System.out.println("adding test document to solr");
SolrInputDocument doc = new SolrInputDocument();
doc.addField(YaCySchema.id.name(), "ABCD0000abcd");
doc.addField(YaCySchema.title.name(), "Lorem ipsum");
doc.addField(YaCySchema.host_s.name(), "yacy.net");
doc.addField(YaCySchema.text_t.name(), "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
try {
solr.add(doc);
} catch (IOException ex) {
fail("IOException adding test document to Solr");
} catch (SolrException ex) {
fail("SolrExceptin adding test document to Solr");
}
solr.commit(true);
System.out.println("query solr");
long expResult = 1;
SolrDocumentList result;
try {
result = solr.query(YaCySchema.text_t.name() + ":tempor", 0, 10);
assertEquals(expResult, result.getNumFound());
} catch (IOException ex) {
fail("Solr query no result");
}
}
public static void waitForSolr(String context, int port) throws Exception {
// A raw term query type doesn't check the schema
URL url = new URL("http://127.0.0.1:" + port + context + "/select?q={!raw+f=test_query}ping");
Exception ex = null;
// Wait for a total of 20 seconds: 100 tries, 200 milliseconds each
for (int i = 0; i < 600; i++) {
try {
InputStream stream = url.openStream();
stream.close();
} catch (IOException e) {
ex = e;
Thread.sleep(200);
continue;
}
return;
}
throw new RuntimeException("Jetty/Solr unresponsive", ex);
}
/**
* from org.apache.solr.client.solrj.embedded.JettySolrRunner
*/
public static Server startServer(String context, int port, EmbeddedSolrConnector c) {
//this.context = context;
Server server = new Server(port);
/*
SocketConnector connector = new SocketConnector();
connector.setPort(port);
connector.setReuseAddress(true);
this.server.setConnectors(new Connector[] { connector });
this.server.setSessionIdManager(new HashSessionIdManager(new Random()));
*/
server.setStopAtShutdown(true);
Context root = new Context(server, context, Context.SESSIONS);
root.addServlet(SolrServlet.Servlet404.class, "/*");
// attach org.apache.solr.response.XMLWriter to search requests
SolrServlet.initCore(c);
FilterHolder dispatchFilter = root.addFilter(SolrServlet.class, "*", Handler.REQUEST);
if (!server.isRunning()) {
try {
server.start();
waitForSolr(context, port);
} catch (Exception e) {
e.printStackTrace();
}
}
return server;
}
public static void main(String[] args) {
File solr_config = new File("defaults/solr");
File storage = new File("DATA/INDEX/webportal/SEGMENTS/text/solr/");
storage.mkdirs();
try {
EmbeddedSolrConnector solr = new EmbeddedSolrConnector(storage, solr_config);
SolrInputDocument doc = new SolrInputDocument();
doc.addField(YaCySchema.id.name(), "ABCD0000abcd");
doc.addField(YaCySchema.title.name(), "Lorem ipsum");
doc.addField(YaCySchema.host_s.name(), "yacy.net");
doc.addField(YaCySchema.text_t.name(), "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
solr.add(doc);
// start a server
startServer("/solr", 8091, solr); // try http://localhost:8091/solr/select?q=*:*
// do a normal query
SolrDocumentList select = solr.query(YaCySchema.text_t.name() + ":tempor", 0, 10);
for (SolrDocument d : select) {
System.out.println("***TEST SELECT*** " + d.toString());
}
// do a facet query
select = solr.query(YaCySchema.text_t.name() + ":tempor", 0, 10);
for (SolrDocument d : select) {
System.out.println("***TEST SELECT*** " + d.toString());
}
// try http://127.0.0.1:8091/solr/select?q=ping
try {
Thread.sleep(1000 * 1000);
} catch (InterruptedException e) {
}
solr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save