Skip to content

Commit

Permalink
- added solr core and libraries that solr needs (lucene is missing, will
Browse files Browse the repository at this point in the history
follow later)
- added embedded solr connector which can connect to solr
programmatically (without using a server in between)
  • Loading branch information
Orbiter committed Jun 21, 2012
1 parent 15f4551 commit 3f55dc7
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 161 deletions.
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
<classpathentry kind="lib" path="lib/httpclient-4.2.jar"/>
<classpathentry kind="lib" path="lib/httpmime-4.2.jar"/>
<classpathentry kind="lib" path="lib/commons-io-2.1.jar"/>
<classpathentry kind="lib" path="lib/apache-solr-solrj-3.6.0.jar" sourcepath="/solrj/src"/>
<classpathentry kind="lib" path="lib/apache-solr-solrj-3.6.0.jar" sourcepath="/Users/admin/git/lucene-solr/solr/solrj/src/java"/>
<classpathentry kind="lib" path="lib/commons-compress-1.4.1.jar"/>
<classpathentry kind="lib" path="lib/apache-solr-core-3.6.0.jar" sourcepath="/Users/admin/git/lucene-solr/solr/core/src/java/"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/icu4j-core.jar"/>
<classpathentry kind="lib" path="lib/htmllexer.jar"/>
Expand Down
4 changes: 4 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<pathelement location="${htroot}" />
<pathelement location="${lib}/activation.jar" />
<pathelement location="${lib}/apache-mime4j-0.6.jar" />
<pathelement location="${lib}/apache-solr-core-3.6.0.jar" />
<pathelement location="${lib}/apache-solr-solrj-3.6.0.jar" />
<pathelement location="${lib}/arq-2.8.7.jar" />
<pathelement location="${lib}/bcmail-jdk15-145.jar" />
Expand All @@ -166,9 +167,11 @@
<pathelement location="${lib}/commons-fileupload-1.2.2.jar" />
<pathelement location="${lib}/commons-io-2.1.jar" />
<pathelement location="${lib}/commons-jxpath-1.3.jar" />
<pathelement location="${lib}/commons-lang-2.6.jar" />
<pathelement location="${lib}/commons-logging-1.1.1.jar" />
<pathelement location="${lib}/fontbox-1.6.0.jar" />
<pathelement location="${lib}/geronimo-stax-api_1.0_spec-1.0.1.jar" />
<pathelement location="${lib}/guava-r05.jar" />
<pathelement location="${lib}/htmllexer.jar" />
<pathelement location="${lib}/htmlparser.jar" />
<pathelement location="${lib}/httpclient-4.2.jar" />
Expand All @@ -185,6 +188,7 @@
<pathelement location="${lib}/jsch-0.1.42.jar" />
<pathelement location="${lib}/json-simple-1.1.jar" />
<pathelement location="${lib}/log4j-1.2.16.jar" />
<pathelement location="${lib}/log4j-over-slf4j-1.6.1.jar" />
<pathelement location="${lib}/metadata-extractor-2.4.0-beta-1.jar" />
<pathelement location="${lib}/mysql-connector-java-5.1.12-bin.jar" />
<pathelement location="${lib}/pdfbox-1.6.0.jar" />
Expand Down
Binary file added lib/apache-solr-core-3.6.0.jar
Binary file not shown.
Binary file added lib/commons-lang-2.6.jar
Binary file not shown.
18 changes: 17 additions & 1 deletion lib/dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
list of library-dependencies:

* apache-solr-solrj-3.4.0.jar depens on:
* apache-solr-solrj-3.4.0.jar depends on:
commons-codec-1.4.jar
commons-httpclient-3.1.jar
commons-io-1.4.jar
Expand All @@ -9,6 +9,22 @@ jcl-over-slf4j-1.6.1.jar
slf4j-api-1.6.1.jar
wstx-asl-3.2.7.jar

* apache-solr-core-3.6.0.jar depends on
commons-codec-1.6.jar
commons-fileupload-1.2.1.jar
commons-httpclient-3.1.jar
commons-io-2.1.jar
commons-lang-2.6.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
guava-r05.jar
httpclient-4.2.jar
httpcore-4.2.jar
jcl-over-slf4j-1.6.1.jar
log4j-over-slf4j-1.6.1.jar
slf4j-api-1.6.1.jar
slf4j-jdk14-1.6.1.jar
wstx-asl-3.2.7.jar

* pdfbox-1.6.0.jar depends on:
fontbox-1.6.0.jar
jempbox-1.6.0.jar
Binary file added lib/guava-r05.jar
Binary file not shown.
Binary file added lib/log4j-over-slf4j-1.6.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/**
* AbstractSolrConnector
* Copyright 2012 by Michael Peter Christen
* First released 21.06.2012 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/

package net.yacy.cora.services.federated.solr;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.yacy.kelondro.logging.Log;
import net.yacy.search.index.SolrField;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;

public class AbstractSolrConnector implements SolrConnector {

protected SolrServer server;

protected AbstractSolrConnector() {
this.server = null;
}

protected void init(SolrServer server) {
this.server = server;
}

@Override
public synchronized void close() {
try {
this.server.commit();
} catch (SolrServerException e) {
Log.logException(e);
} catch (IOException e) {
Log.logException(e);
}
}

@Override
public long getSize() {
try {
final SolrDocumentList list = get("*:*", 0, 1);
return list.getNumFound();
} catch (final Throwable e) {
Log.logException(e);
return 0;
}
}

/**
* delete everything in the solr index
* @throws IOException
*/
@Override
public void clear() throws IOException {
try {
this.server.deleteByQuery("*:*");
this.server.commit();
} catch (final Throwable e) {
throw new IOException(e);
}
}

@Override
public void delete(final String id) throws IOException {
try {
this.server.deleteById(id);
} catch (final Throwable e) {
throw new IOException(e);
}
}

@Override
public void delete(final List<String> ids) throws IOException {
try {
this.server.deleteById(ids);
} catch (final Throwable e) {
throw new IOException(e);
}
}

@Override
public boolean exists(final String id) throws IOException {
try {
final SolrDocumentList list = get(SolrField.id.getSolrFieldName() + ":" + id, 0, 1);
return list.getNumFound() > 0;
} catch (final Throwable e) {
Log.logException(e);
return false;
}
}

public void add(final File file, final String solrId) throws IOException {
final ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
up.addFile(file);
up.setParam("literal.id", solrId);
up.setParam("uprefix", "attr_");
up.setParam("fmap.content", "attr_content");
//up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
try {
this.server.request(up);
this.server.commit();
} catch (final Throwable e) {
throw new IOException(e);
}
}

@Override
public void add(final SolrDoc solrdoc) throws IOException, SolrException {
try {
this.server.add(solrdoc,180000); // commitWithIn 180s
//this.server.commit();
} catch (SolrServerException e) {
Log.logWarning("SolrConnector", e.getMessage() + " DOC=" + solrdoc.toString());
throw new IOException(e);
}
}

@Override
public void add(final Collection<SolrDoc> solrdocs) throws IOException, SolrException {
ArrayList<SolrInputDocument> l = new ArrayList<SolrInputDocument>();
for (SolrDoc d: solrdocs) l.add(d);
try {
this.server.add(l,180000); // commitWithIn 120s
//this.server.commit();
} catch (SolrServerException e) {
Log.logWarning("SolrConnector", e.getMessage() + " DOC=" + solrdocs.toString());
throw new IOException(e);
}
}

/**
* get a query result from solr
* to get all results set the query String to "*:*"
* @param querystring
* @throws IOException
*/
@Override
public SolrDocumentList get(final String querystring, final int offset, final int count) throws IOException {
// construct query
final SolrQuery query = new SolrQuery();
query.setQuery(querystring);
query.setRows(count);
query.setStart(offset);
//query.addSortField( "price", SolrQuery.ORDER.asc );

// query the server
//SearchResult result = new SearchResult(count);
try {
final QueryResponse rsp = this.server.query( query );
final SolrDocumentList docs = rsp.getResults();
return docs;
// add the docs into the YaCy search result container
/*
for (SolrDocument doc: docs) {
result.put(element)
}
*/
} catch (final Throwable e) {
throw new IOException(e);
}

//return result;
}

}
Loading

0 comments on commit 3f55dc7

Please sign in to comment.