From 7c7fbb98185e1b7c3db79609395bea6b646ecbcc Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 11 Apr 2014 12:27:21 +0200 Subject: [PATCH] find depth-matches also for edge targets --- .../net/yacy/search/schema/HyperlinkEdges.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source/net/yacy/search/schema/HyperlinkEdges.java b/source/net/yacy/search/schema/HyperlinkEdges.java index 30559ae3b..9a9120d5b 100644 --- a/source/net/yacy/search/schema/HyperlinkEdges.java +++ b/source/net/yacy/search/schema/HyperlinkEdges.java @@ -37,6 +37,10 @@ public class HyperlinkEdges implements Iterable { Targets targets = this.edges.get(source); Integer d = this.singletonDepth.get(source); if (d == null) d = -1; else this.singletonDepth.remove(source); + if (target.type == HyperlinkType.Inbound) { + Integer e = this.singletonDepth.remove(target); + if (e != null && d.intValue() == -1) d = e.intValue() - 1; + } if (targets == null) { targets = new Targets(d.intValue()); this.edges.put(source, targets); @@ -71,11 +75,21 @@ public class HyperlinkEdges implements Iterable { } } - public Integer getDepth(final MultiProtocolURL url) { + public int getDepth(final MultiProtocolURL url) { Targets targets = this.edges.get(url); if (targets != null) return targets.depth; Integer d = this.singletonDepth.get(url); - return d == null ? -1 : d.intValue(); + if (d != null) return d.intValue(); + // now search in targets + String targetHost = url.getHost(); + for (Map.Entry e: this.edges.entrySet()) { + if (e.getValue().targets.contains(url)) { + String sourceHost = e.getKey().getHost(); + // check if this is an inbound match + if ((sourceHost == null && targetHost == null) || (sourceHost != null && targetHost != null && sourceHost.equals(targetHost))) return e.getValue().depth + 1; + } + } + return -1; } @Override