From 907db8b7a6c6ab4daa37ffcf47ec14ff8bdba832 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 25 Feb 2014 15:19:04 +0100 Subject: [PATCH] fix for bad query shortcut hack --- .../solr/connector/AbstractSolrConnector.java | 3 ++- .../federate/solr/connector/CachedSolrConnector.java | 6 +++++- .../solr/connector/ConcurrentUpdateSolrConnector.java | 11 +++++++++++ .../federate/solr/connector/MirrorSolrConnector.java | 6 +++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/source/net/yacy/cora/federate/solr/connector/AbstractSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/AbstractSolrConnector.java index 0aaad4f2e..521433886 100644 --- a/source/net/yacy/cora/federate/solr/connector/AbstractSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/AbstractSolrConnector.java @@ -37,6 +37,7 @@ import net.yacy.cora.document.encoding.UTF8; import net.yacy.cora.sorting.ClusteredScoreMap; import net.yacy.cora.sorting.ReversibleScoreMap; import net.yacy.cora.util.LookAheadIterator; +import net.yacy.kelondro.data.word.Word; import net.yacy.search.schema.CollectionSchema; import org.apache.solr.client.solrj.SolrQuery; @@ -336,8 +337,8 @@ public abstract class AbstractSolrConnector implements SolrConnector { @Override public SolrDocument getDocumentById(final String id, final String ... fields) throws IOException { + assert id.length() == Word.commonHashLength : "wrong id: " + id; final SolrQuery query = new SolrQuery(); - assert id.length() == 12; // construct query StringBuilder sb = new StringBuilder(23); sb.append("{!raw f=").append(CollectionSchema.id.getSolrFieldName()).append('}').append(id); diff --git a/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java index cf28b3021..deb6a5096 100644 --- a/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java @@ -27,6 +27,7 @@ import java.util.Map; import net.yacy.cora.sorting.ReversibleScoreMap; import net.yacy.cora.storage.ARC; import net.yacy.cora.storage.ConcurrentARC; +import net.yacy.kelondro.data.word.Word; import net.yacy.kelondro.util.MemoryControl; import net.yacy.search.schema.CollectionSchema; @@ -140,6 +141,7 @@ public class CachedSolrConnector extends AbstractSolrConnector implements SolrCo @Override public SolrDocument getDocumentById(final String id, final String ... fields) throws IOException { + assert id.length() == Word.commonHashLength : "wrong id: " + id; String q = idQuery(id); SolrDocument doc = fields.length == 0 ? this.documentCache.get(q) : null; if (doc != null) { @@ -209,7 +211,9 @@ public class CachedSolrConnector extends AbstractSolrConnector implements SolrCo */ @Override public SolrDocumentList getDocumentListByQuery(final String querystring, final int offset, final int count, final String ... fields) throws IOException { - if (offset == 0 && count == 1 && querystring.startsWith("id:")) { + if (offset == 0 && count == 1 && querystring.startsWith("id:") && + ((querystring.length() == 17 && querystring.charAt(3) == '"' && querystring.charAt(16) == '"') || + querystring.length() == 15)) { final SolrDocumentList list = new SolrDocumentList(); SolrDocument doc = getDocumentById(querystring.charAt(3) == '"' ? querystring.substring(4, querystring.length() - 1) : querystring.substring(3), fields); list.add(doc); diff --git a/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java index 5ebb3c7c2..feee3484e 100644 --- a/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java @@ -35,6 +35,7 @@ import net.yacy.cora.storage.ARH; import net.yacy.cora.storage.ConcurrentARC; import net.yacy.cora.storage.ConcurrentARH; import net.yacy.cora.util.ConcurrentLog; +import net.yacy.kelondro.data.word.Word; import net.yacy.kelondro.util.MemoryControl; import net.yacy.search.schema.CollectionSchema; @@ -411,6 +412,7 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector { @Override public SolrDocument getDocumentById(final String id, String... fields) throws IOException { + assert id.length() == Word.commonHashLength : "wrong id: " + id; if (this.missCache.contains(id)) return null; if (existIdFromDeleteQueue(id)) return null; SolrInputDocument idoc = getFromUpdateQueue(id); @@ -443,6 +445,15 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector { @Override public SolrDocumentList getDocumentListByQuery(String querystring, int offset, int count, String... fields) throws IOException, SolrException { + if (offset == 0 && count == 1 && querystring.startsWith("id:") && + ((querystring.length() == 17 && querystring.charAt(3) == '"' && querystring.charAt(16) == '"') || + querystring.length() == 15)) { + final SolrDocumentList list = new SolrDocumentList(); + SolrDocument doc = getDocumentById(querystring.charAt(3) == '"' ? querystring.substring(4, querystring.length() - 1) : querystring.substring(3), fields); + list.add(doc); + return list; + } + SolrDocumentList sdl = this.connector.getDocumentListByQuery(querystring, offset, count, AbstractSolrConnector.ensureEssentialFieldsIncluded(fields)); /* Iterator i = sdl.iterator(); diff --git a/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java index a745a0841..2d42d9039 100644 --- a/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java @@ -28,6 +28,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.atomic.AtomicLong; import net.yacy.cora.sorting.ReversibleScoreMap; +import net.yacy.kelondro.data.word.Word; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; @@ -172,6 +173,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo @Override public SolrDocument getDocumentById(final String key, final String ... fields) throws IOException { + assert key.length() == Word.commonHashLength : "wrong id: " + key; SolrDocument doc; if ((solr0 != null && ((doc = solr0.getDocumentById(key, fields)) != null)) || (solr1 != null && ((doc = solr1.getDocumentById(key, fields)) != null))) { return doc; @@ -205,7 +207,9 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo @Override public SolrDocumentList getDocumentListByQuery(final String querystring, final int offset, final int count, final String ... fields) throws IOException { if (this.solr0 == null && this.solr1 == null) return new SolrDocumentList(); - if (offset == 0 && count == 1 && querystring.startsWith("id:")) { + if (offset == 0 && count == 1 && querystring.startsWith("id:") && + ((querystring.length() == 17 && querystring.charAt(3) == '"' && querystring.charAt(16) == '"') || + querystring.length() == 15)) { final SolrDocumentList list = new SolrDocumentList(); SolrDocument doc = getDocumentById(querystring.charAt(3) == '"' ? querystring.substring(4, querystring.length() - 1) : querystring.substring(3), fields); list.add(doc);