From 2b6c79d3470ef1ab0d06c31f5497789f1e7e95b4 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Mon, 4 Mar 2013 01:13:17 +0100 Subject: [PATCH] in method exists() also use the new caching-stacks for documents/metadata --- .../kelondro/data/meta/URIMetadataNode.java | 2 -- source/net/yacy/search/index/Fulltext.java | 32 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/source/net/yacy/kelondro/data/meta/URIMetadataNode.java b/source/net/yacy/kelondro/data/meta/URIMetadataNode.java index c9f809225..27b0ca243 100644 --- a/source/net/yacy/kelondro/data/meta/URIMetadataNode.java +++ b/source/net/yacy/kelondro/data/meta/URIMetadataNode.java @@ -46,9 +46,7 @@ import net.yacy.kelondro.util.Bitfield; import net.yacy.search.schema.CollectionSchema; import net.yacy.utils.crypt; -import org.apache.solr.client.solrj.util.ClientUtils; import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrInputDocument; /** diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.java index b1079fae6..b63645817 100644 --- a/source/net/yacy/search/index/Fulltext.java +++ b/source/net/yacy/search/index/Fulltext.java @@ -306,6 +306,24 @@ public final class Fulltext { public DigestURI getURL(final byte[] urlHash) { if (urlHash == null) return null; + + // try to get the data from the delayed cache; this happens if we retrieve this from a fresh search result + String u = ASCII.String(urlHash); + for (URIMetadataRow entry: this.pendingCollectionInputRows) { + if (u.equals(ASCII.String(entry.hash()))) { + if (this.urlIndexFile != null) try {this.urlIndexFile.remove(urlHash);} catch (IOException e) {} // migration + return entry.url(); + } + } + + for (SolrInputDocument doc: this.pendingCollectionInputDocuments) { + if (u.equals(doc.getFieldValue(CollectionSchema.id.getSolrFieldName()))) { + if (this.urlIndexFile != null) try {this.urlIndexFile.remove(urlHash);} catch (IOException e) {} // migration + String url = (String) doc.getFieldValue(CollectionSchema.sku.getSolrFieldName()); + if (url != null) try {return new DigestURI(url);} catch (MalformedURLException e) {} + } + } + String x; try { x = (String) this.getDefaultConnector().getFieldById(ASCII.String(urlHash), CollectionSchema.sku.getSolrFieldName()); @@ -340,8 +358,7 @@ public final class Fulltext { // try to get the data from the delayed cache; this happens if we retrieve this from a fresh search result for (URIMetadataRow entry: this.pendingCollectionInputRows) { - String id = ASCII.String(entry.hash()); - if (id != null && id.equals(u)) { + if (u.equals(ASCII.String(entry.hash()))) { if (this.urlIndexFile != null) try {this.urlIndexFile.remove(urlHash);} catch (IOException e) {} // migration SolrDocument sd = this.collectionConfiguration.toSolrDocument(getDefaultConfiguration().metadata2solr(entry)); return new URIMetadataNode(sd, wre, weight); @@ -349,8 +366,7 @@ public final class Fulltext { } for (SolrInputDocument doc: this.pendingCollectionInputDocuments) { - String id = (String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName()); - if (id != null && id.equals(u)) { + if (u.equals(doc.getFieldValue(CollectionSchema.id.getSolrFieldName()))) { if (this.urlIndexFile != null) try {this.urlIndexFile.remove(urlHash);} catch (IOException e) {} // migration SolrDocument sd = this.collectionConfiguration.toSolrDocument(doc); return new URIMetadataNode(sd, wre, weight); @@ -709,12 +725,18 @@ public final class Fulltext { public boolean exists(final String urlHash) { if (urlHash == null) return false; - if (this.urlIndexFile != null && this.urlIndexFile.has(ASCII.getBytes(urlHash))) return true; + for (URIMetadataRow entry: this.pendingCollectionInputRows) { + if (urlHash.equals(ASCII.String(entry.hash()))) return true; + } + for (SolrInputDocument doc: this.pendingCollectionInputDocuments) { + if (urlHash.equals(doc.getFieldValue(CollectionSchema.id.getSolrFieldName()))) return true; + } try { if (this.getDefaultConnector().exists(CollectionSchema.id.getSolrFieldName(), urlHash)) return true; } catch (final Throwable e) { Log.logException(e); } + if (this.urlIndexFile != null && this.urlIndexFile.has(ASCII.getBytes(urlHash))) return true; return false; }