From 18f9c40302308c40d0765d1dadf6a8d7e473679c Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 4 Apr 2014 10:54:11 +0200 Subject: [PATCH] moved Edge class out of linkstructure servlet as this does not work on non-eclipse driven environments (all non-dev cases) --- htroot/api/linkstructure.java | 29 ++++---------- .../net/yacy/search/schema/HyperlinkEdge.java | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 source/net/yacy/search/schema/HyperlinkEdge.java diff --git a/htroot/api/linkstructure.java b/htroot/api/linkstructure.java index 878a9efd1b..692388b197 100644 --- a/htroot/api/linkstructure.java +++ b/htroot/api/linkstructure.java @@ -38,25 +38,12 @@ import net.yacy.search.Switchboard; import net.yacy.search.index.Fulltext; import net.yacy.search.schema.CollectionSchema; +import net.yacy.search.schema.HyperlinkEdge; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; import net.yacy.server.servletProperties; public class linkstructure { - - public static enum Edgetype { - InboundOk, InboundNofollow, Outbound, Dead; - } - - public static class Edge { - public DigestURL source, target; - public Edgetype type; - public Edge(DigestURL source, DigestURL target, Edgetype type) { - this.source = source; - this.target = target; - this.type = type; - } - } public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { final servletProperties prop = new servletProperties(); @@ -105,7 +92,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje ); SolrDocument doc; Map errorDocs = new HashMap(); - Map edges = new HashMap(); + Map edges = new HashMap(); try { while ((doc = docs.take()) != AbstractSolrConnector.POISON_DOCUMENT) { String u = (String) doc.getFieldValue(CollectionSchema.sku.getSolrFieldName()); @@ -123,7 +110,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje try { DigestURL linkurl = new DigestURL(link, null); String edgehash = ids + ASCII.String(linkurl.hash()); - edges.put(edgehash, new Edge(from, linkurl, Edgetype.InboundOk)); + edges.put(edgehash, new HyperlinkEdge(from, linkurl, HyperlinkEdge.Type.InboundOk)); } catch (MalformedURLException e) {} } links = URIMetadataNode.getLinks(doc, false); // outbound @@ -132,7 +119,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje try { DigestURL linkurl = new DigestURL(link, null); String edgehash = ids + ASCII.String(linkurl.hash()); - edges.put(edgehash, new Edge(from, linkurl, Edgetype.Outbound)); + edges.put(edgehash, new HyperlinkEdge(from, linkurl, HyperlinkEdge.Type.Outbound)); } catch (MalformedURLException e) {} } } @@ -142,15 +129,15 @@ public static serverObjects respond(final RequestHeader header, final serverObje } catch (MalformedURLException e) { } // we use the errorDocs to mark all edges with endpoint to error documents - for (Map.Entry edge: edges.entrySet()) { - if (errorDocs.containsKey(edge.getValue().target)) edge.getValue().type = Edgetype.Dead; + for (Map.Entry edge: edges.entrySet()) { + if (errorDocs.containsKey(edge.getValue().target)) edge.getValue().type = HyperlinkEdge.Type.Dead; } // finally just write out the edge array int c = 0; - for (Map.Entry edge: edges.entrySet()) { + for (Map.Entry edge: edges.entrySet()) { prop.putJSON("list_" + c + "_source", edge.getValue().source.getPath()); - prop.putJSON("list_" + c + "_target", edge.getValue().type.equals(Edgetype.Outbound) ? edge.getValue().target.toNormalform(true) : edge.getValue().target.getPath()); + prop.putJSON("list_" + c + "_target", edge.getValue().type.equals(HyperlinkEdge.Type.Outbound) ? edge.getValue().target.toNormalform(true) : edge.getValue().target.getPath()); prop.putJSON("list_" + c + "_type", edge.getValue().type.name()); prop.put("list_" + c + "_eol", 1); c++; diff --git a/source/net/yacy/search/schema/HyperlinkEdge.java b/source/net/yacy/search/schema/HyperlinkEdge.java new file mode 100644 index 0000000000..712cb9b4c5 --- /dev/null +++ b/source/net/yacy/search/schema/HyperlinkEdge.java @@ -0,0 +1,40 @@ +/** + * HyperlinkEdge + * Copyright 2014 by Michael Peter Christen + * First released 04.04.2014 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 . + */ + +package net.yacy.search.schema; + +import net.yacy.cora.document.id.DigestURL; + +public class HyperlinkEdge { + + public static enum Type { + InboundOk, InboundNofollow, Outbound, Dead; + } + + public DigestURL source, target; + public Type type; + + public HyperlinkEdge(DigestURL source, DigestURL target, Type type) { + this.source = source; + this.target = target; + this.type = type; + } + +}