Skip to content

Commit

Permalink
moved Edge class out of linkstructure servlet as this does not work on
Browse files Browse the repository at this point in the history
non-eclipse driven environments (all non-dev cases)
  • Loading branch information
Orbiter committed Apr 4, 2014
1 parent de95e5e commit 18f9c40
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
29 changes: 8 additions & 21 deletions htroot/api/linkstructure.java
Expand Up @@ -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();
Expand Down Expand Up @@ -105,7 +92,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
);
SolrDocument doc;
Map<String, FailType> errorDocs = new HashMap<String, FailType>();
Map<String, Edge> edges = new HashMap<String, Edge>();
Map<String, HyperlinkEdge> edges = new HashMap<String, HyperlinkEdge>();
try {
while ((doc = docs.take()) != AbstractSolrConnector.POISON_DOCUMENT) {
String u = (String) doc.getFieldValue(CollectionSchema.sku.getSolrFieldName());
Expand All @@ -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
Expand All @@ -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) {}
}
}
Expand All @@ -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<String, Edge> edge: edges.entrySet()) {
if (errorDocs.containsKey(edge.getValue().target)) edge.getValue().type = Edgetype.Dead;
for (Map.Entry<String, HyperlinkEdge> 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<String, Edge> edge: edges.entrySet()) {
for (Map.Entry<String, HyperlinkEdge> 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++;
Expand Down
40 changes: 40 additions & 0 deletions 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 <http://www.gnu.org/licenses/>.
*/

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;
}

}

0 comments on commit 18f9c40

Please sign in to comment.