Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
new workflow processor in Segment to enqueue indexing documents to solr
Michael Peter Christena1644ca0fdfc
diff --git a/source/net/yacy/kelondro/data/word/Word.java b/source/net/yacy/kelondro/data/word/Word.javaindex 7cdf972da..701037c7e 100644--- a/source/net/yacy/kelondro/data/word/Word.java+++ b/source/net/yacy/kelondro/data/word/Word.java@@ -29,7 +29,6 @@ package net.yacy.kelondro.data.word;import java.util.Collection;import java.util.Locale;-import net.yacy.cora.document.WordCache;import net.yacy.cora.order.Base64Order;import net.yacy.cora.order.Digest;import net.yacy.cora.storage.ARC;diff --git a/source/net/yacy/peers/Protocol.java b/source/net/yacy/peers/Protocol.javaindex 094db68f6..a62790478 100644--- a/source/net/yacy/peers/Protocol.java+++ b/source/net/yacy/peers/Protocol.java@@ -1192,7 +1192,7 @@ public final class Protocol {// after this conversion we can remove the largest and not used field text_t and synonyms_sxt from the document// because that goes into a search cache and would take a lot of memory in the search cache- doc.removeFields(CollectionSchema.text_t.getSolrFieldName());+ //doc.removeFields(CollectionSchema.text_t.getSolrFieldName());doc.removeFields(CollectionSchema.synonyms_sxt.getSolrFieldName());// the input document stays untouched because it contains top-level cloned objects@@ -1214,16 +1214,14 @@ public final class Protocol {event.addExpectedRemoteReferences(-count);Network.log.logInfo("local search (solr): localpeer sent " + container.get(0).size() + "/" + docList.size() + " references");} else {- // learn the documents, this can be done later- try {- event.query.getSegment().fulltext().putDocuments(docs); docs.clear(); docs = null;- event.addNodes(container, facets, snippets, false, target.getName() + "/" + target.hash, (int) docList.getNumFound());- event.addFinalize();- event.addExpectedRemoteReferences(-count);- Network.log.logInfo("remote search (solr): peer " + target.getName() + " sent " + (container.size() == 0 ? 0 : container.get(0).size()) + "/" + docList.size() + " references");- } catch (IOException e) {- Log.logException(e);+ for (SolrInputDocument doc: docs) {+ event.query.getSegment().putDocumentInQueue(doc);}+ docs.clear(); docs = null;+ event.addNodes(container, facets, snippets, false, target.getName() + "/" + target.hash, (int) docList.getNumFound());+ event.addFinalize();+ event.addExpectedRemoteReferences(-count);+ Network.log.logInfo("remote search (solr): peer " + target.getName() + " sent " + (container.size() == 0 ? 0 : container.get(0).size()) + "/" + docList.size() + " references");}final int dls = docList.size();docList.clear();diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.javaindex 27fc03555..8fe9a3960 100644--- a/source/net/yacy/search/index/Fulltext.java+++ b/source/net/yacy/search/index/Fulltext.java@@ -37,7 +37,6 @@ import java.util.List;import java.util.Map;import java.util.Set;import java.util.concurrent.BlockingQueue;-import java.util.concurrent.LinkedBlockingQueue;import java.util.concurrent.atomic.AtomicInteger;import java.util.regex.Pattern;@@ -387,6 +386,8 @@ public final class Fulltext {SolrConnector connector = this.getDefaultConnector();if (connector == null) return;String id = (String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName());+ String url = (String) doc.getFieldValue(CollectionSchema.sku.getSolrFieldName());+ Log.logInfo("Fulltext", "indexing: " + id + " " + url);byte[] idb = ASCII.getBytes(id);try {if (this.urlIndexFile != null) this.urlIndexFile.remove(idb);@@ -402,13 +403,6 @@ public final class Fulltext {if (MemoryControl.shortStatus()) clearCache();}- public void putDocuments(final Collection<SolrInputDocument> docs) throws IOException {- if (docs == null || docs.size() == 0) return;- this.getDefaultConnector().add(docs);- this.statsDump = null;- if (MemoryControl.shortStatus()) clearCache();- }-public void putEdges(final Collection<SolrInputDocument> edges) throws IOException {if (edges == null || edges.size() == 0) return;try {diff --git a/source/net/yacy/search/index/ReindexSolrBusyThread.java b/source/net/yacy/search/index/ReindexSolrBusyThread.javaindex aac2b6a46..eb1677536 100644--- a/source/net/yacy/search/index/ReindexSolrBusyThread.java+++ b/source/net/yacy/search/index/ReindexSolrBusyThread.java@@ -24,15 +24,9 @@ import net.yacy.kelondro.logging.Log;import net.yacy.search.Switchboard;import java.util.ArrayList;import java.util.concurrent.Semaphore;-import java.util.logging.Level;-import java.util.logging.Logger;import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector;import net.yacy.kelondro.workflow.AbstractBusyThread;import net.yacy.search.schema.CollectionConfiguration;-import org.apache.lucene.index.FieldInfo;-import org.apache.solr.client.solrj.SolrServerException;-import org.apache.solr.client.solrj.request.LukeRequest;-import org.apache.solr.client.solrj.response.LukeResponse;import org.apache.solr.common.SolrDocument;import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.SolrInputDocument;@@ -135,7 +129,7 @@ import org.apache.solr.common.SolrInputDocument;for (SolrDocument doc : xdocs) {SolrInputDocument idoc = colcfg.toSolrInputDocument(doc);- Switchboard.getSwitchboard().index.fulltext().putDocument(idoc);+ Switchboard.getSwitchboard().index.putDocumentInQueue(idoc);processed++;}}diff --git a/source/net/yacy/search/index/Segment.java b/source/net/yacy/search/index/Segment.javaindex 60ad64567..645b70786 100644--- a/source/net/yacy/search/index/Segment.java+++ b/source/net/yacy/search/index/Segment.java@@ -75,7 +75,9 @@ import net.yacy.kelondro.util.Bitfield;import net.yacy.kelondro.util.ByteBuffer;import net.yacy.kelondro.util.ISO639;import net.yacy.kelondro.util.MemoryControl;+import net.yacy.kelondro.workflow.WorkflowProcessor;import net.yacy.repository.LoaderDispatcher;+import net.yacy.search.StorageQueueEntry;import net.yacy.search.query.SearchEvent;import net.yacy.search.schema.CollectionConfiguration;import net.yacy.search.schema.CollectionSchema;@@ -114,6 +116,7 @@ public class Segment {protected IndexCell<WordReference> termIndex;protected IndexCell<CitationReference> urlCitationIndex;protected boolean writeWebgraph;+ private WorkflowProcessor<StorageQueueEntry> indexingPutDocumentProcessor;/*** create a new Segment@@ -132,8 +135,18 @@ public class Segment {this.termIndex = null;this.urlCitationIndex = null;this.writeWebgraph = false;- }+ this.indexingPutDocumentProcessor = new WorkflowProcessor<StorageQueueEntry>(+ "putDocument",+ "solr document put queueing",+ new String[] {},+ this,+ "putDocument",+ 10,+ null,+ 1);+ }+public void writeWebgraph(boolean check) {this.writeWebgraph = check;}@@ -402,6 +415,7 @@ public class Segment {}public synchronized void close() {+ this.indexingPutDocumentProcessor.shutdown();if (this.termIndex != null) this.termIndex.close();if (this.fulltext != null) this.fulltext.close();if (this.urlCitationIndex != null) this.urlCitationIndex.close();@@ -457,6 +471,31 @@ public class Segment {if (this.termIndex != null) this.termIndex.add(termHash, entry);}+ /**+ * putDocument should not be called directly; instead, put queueEntries to+ * indexingPutDocumentProcessor+ * (this must be public, otherwise the WorkflowProcessor - calling by reflection - does not work)+ * ATTENTION: do not remove! profiling tools will show that this is not called, which is not true (using reflection)+ * @param queueEntry+ * @throws IOException+ */+ public void putDocument(final StorageQueueEntry queueEntry) {+ try {+ this.fulltext().putDocument(queueEntry.queueEntry);+ } catch (IOException e) {+ Log.logException(e);+ }+ }++ /**+ * put a solr document into the index. This is the right point to call when enqueueing of solr document is wanted.+ * This method exist to prevent that solr is filled concurrently with data which makes it fail or throw strange exceptions.+ * @param queueEntry+ */+ public void putDocumentInQueue(final SolrInputDocument queueEntry) {+ this.indexingPutDocumentProcessor.enQueue(new StorageQueueEntry(queueEntry));+ }+public SolrInputDocument storeDocument(final DigestURI url,final DigestURI referrerURL,@@ -546,7 +585,8 @@ public class Segment {for (SolrDocument doc: docs) {SolrInputDocument sid = this.fulltext.getDefaultConfiguration().toSolrInputDocument(doc);sid.setField(uniquefield.getSolrFieldName(), false);- this.fulltext.getDefaultConnector().add(sid);+ this.putDocumentInQueue(sid);+ //this.fulltext.getDefaultConnector().add(sid);}} else {vector.setField(uniquefield.getSolrFieldName(), true);@@ -562,19 +602,7 @@ public class Segment {}// STORE TO SOLRString error = null;- tryloop: for (int i = 0; i < 20; i++) {- try {- error = null;- this.fulltext.putDocument(vector);- break tryloop;- } catch ( final IOException e ) {- error = "failed to send " + urlNormalform + " to solr: " + e.getMessage();- Log.logWarning("SOLR", error);- if (i == 10) this.fulltext.commit(false);- try {Thread.sleep(1000);} catch (InterruptedException e1) {}- continue tryloop;- }- }+ this.putDocumentInQueue(vector);if (this.writeWebgraph) {tryloop: for (int i = 0; i < 20; i++) {try {diff --git a/source/net/yacy/search/schema/CollectionConfiguration.java b/source/net/yacy/search/schema/CollectionConfiguration.javaindex b92f7eb08..ca113a892 100644--- a/source/net/yacy/search/schema/CollectionConfiguration.java+++ b/source/net/yacy/search/schema/CollectionConfiguration.java@@ -147,7 +147,14 @@ public class CollectionConfiguration extends SchemaConfiguration implements Seri}} catch (final IOException e) {}}-++ private final static Set<String> omitFields = new HashSet<String>(3);+ static {+ omitFields.add(CollectionSchema.author_sxt.getSolrFieldName());+ omitFields.add(CollectionSchema.coordinate_p_0_coordinate.getSolrFieldName());+ omitFields.add(CollectionSchema.coordinate_p_1_coordinate.getSolrFieldName());+ }+/*** Convert a SolrDocument to a SolrInputDocument.* This is useful if a document from the search index shall be modified and indexed again.@@ -158,10 +165,6 @@ public class CollectionConfiguration extends SchemaConfiguration implements Seri*/public SolrInputDocument toSolrInputDocument(SolrDocument doc) {SolrInputDocument sid = new SolrInputDocument();- Set<String> omitFields = new HashSet<String>(3);- omitFields.add(CollectionSchema.author_sxt.getSolrFieldName());- omitFields.add(CollectionSchema.coordinate_p_0_coordinate.getSolrFieldName());- omitFields.add(CollectionSchema.coordinate_p_1_coordinate.getSolrFieldName());for (String name: doc.getFieldNames()) {if (this.contains(name) && !omitFields.contains(name)) { // check each field if enabled in local Solr schemasid.addField(name, doc.getFieldValue(name), 1.0f);@@ -171,17 +174,13 @@ public class CollectionConfiguration extends SchemaConfiguration implements Seri}public SolrDocument toSolrDocument(SolrInputDocument doc) {- SolrDocument sid = new SolrDocument();- Set<String> omitFields = new HashSet<String>(3);- omitFields.add(CollectionSchema.author_sxt.getSolrFieldName());- omitFields.add(CollectionSchema.coordinate_p_0_coordinate.getSolrFieldName());- omitFields.add(CollectionSchema.coordinate_p_1_coordinate.getSolrFieldName());+ SolrDocument sd = new SolrDocument();for (SolrInputField field: doc) {if (this.contains(field.getName()) && !omitFields.contains(field.getName())) { // check each field if enabled in local Solr schema- sid.setField(field.getName(), field.getValue());+ sd.setField(field.getName(), field.getValue());}}- return sid;+ return sd;}public SolrInputDocument metadata2solr(final URIMetadataRow md) {