You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
5.3 KiB
133 lines
5.3 KiB
16 years ago
|
// yacydoc.java
|
||
|
// -----------------------
|
||
|
// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||
|
// first published 12.01.2009 on http://yacy.net
|
||
|
//
|
||
|
// This is a part of YaCy, a peer-to-peer based web search engine
|
||
|
//
|
||
|
// $LastChangedDate: 2007-11-14 01:15:28 +0000 (Mi, 14 Nov 2007) $
|
||
|
// $LastChangedRevision: 4216 $
|
||
|
// $LastChangedBy: orbiter $
|
||
|
//
|
||
|
// LICENSE
|
||
13 years ago
|
//
|
||
16 years ago
|
// This program is free software; you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation; either version 2 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// This program 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 General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
|
||
2 years ago
|
package net.yacy.htroot.api;
|
||
|
|
||
16 years ago
|
import java.net.MalformedURLException;
|
||
12 years ago
|
import java.util.Arrays;
|
||
16 years ago
|
|
||
14 years ago
|
import net.yacy.cora.date.ISO8601Formatter;
|
||
11 years ago
|
import net.yacy.cora.document.encoding.ASCII;
|
||
|
import net.yacy.cora.document.id.DigestURL;
|
||
14 years ago
|
import net.yacy.cora.protocol.RequestHeader;
|
||
12 years ago
|
import net.yacy.cora.util.ConcurrentLog;
|
||
12 years ago
|
import net.yacy.kelondro.data.meta.URIMetadataNode;
|
||
15 years ago
|
import net.yacy.kelondro.data.word.Word;
|
||
13 years ago
|
import net.yacy.search.Switchboard;
|
||
|
import net.yacy.search.index.Segment;
|
||
12 years ago
|
import net.yacy.server.serverObjects;
|
||
|
import net.yacy.server.serverSwitch;
|
||
13 years ago
|
|
||
16 years ago
|
public class yacydoc {
|
||
13 years ago
|
|
||
11 years ago
|
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||
16 years ago
|
// return variable that accumulates replacements
|
||
16 years ago
|
final Switchboard sb = (Switchboard) env;
|
||
13 years ago
|
|
||
16 years ago
|
final serverObjects prop = new serverObjects();
|
||
13 years ago
|
final Segment segment = sb.index;
|
||
13 years ago
|
final boolean html = post != null && post.containsKey("html");
|
||
15 years ago
|
prop.setLocalized(html);
|
||
13 years ago
|
|
||
16 years ago
|
prop.put("dc_title", "");
|
||
|
prop.put("dc_creator", "");
|
||
|
prop.put("dc_description", "");
|
||
|
prop.put("dc_subject", "");
|
||
|
prop.put("dc_publisher", "");
|
||
|
prop.put("dc_contributor", "");
|
||
|
prop.put("dc_date", "");
|
||
|
prop.put("dc_type", "");
|
||
|
prop.put("dc_identifier", "");
|
||
|
prop.put("dc_language", "");
|
||
12 years ago
|
prop.put("collection", "");
|
||
13 years ago
|
prop.put("geo_lat", "");
|
||
|
prop.put("geo_long", "");
|
||
|
|
||
|
prop.put("yacy_urlhash", "");
|
||
13 years ago
|
prop.put("yacy_loaddate", "");
|
||
|
prop.put("yacy_referrer_hash", "");
|
||
|
prop.put("yacy_referrer_url", "");
|
||
13 years ago
|
prop.put("yacy_size", "");
|
||
|
prop.put("yacy_words", "");
|
||
|
prop.put("yacy_citations", "");
|
||
|
prop.put("yacy_inbound", "");
|
||
|
prop.put("yacy_outbound", "");
|
||
16 years ago
|
|
||
|
if (post == null) return prop;
|
||
13 years ago
|
|
||
|
final String urlstring = post.get("url", "").trim();
|
||
16 years ago
|
String urlhash = post.get("urlhash", "").trim();
|
||
13 years ago
|
if (urlstring.isEmpty() && urlhash.isEmpty()) return prop;
|
||
16 years ago
|
|
||
13 years ago
|
if (urlstring.length() > 0 && urlhash.isEmpty()) {
|
||
16 years ago
|
try {
|
||
11 years ago
|
final DigestURL url = new DigestURL(urlstring);
|
||
14 years ago
|
urlhash = ASCII.String(url.hash());
|
||
13 years ago
|
} catch (final MalformedURLException e) {
|
||
12 years ago
|
ConcurrentLog.logException(e);
|
||
16 years ago
|
}
|
||
|
}
|
||
13 years ago
|
if (urlhash == null || urlhash.isEmpty()) return prop;
|
||
13 years ago
|
|
||
12 years ago
|
final URIMetadataNode entry = segment.fulltext().getMetadata(urlhash.getBytes());
|
||
16 years ago
|
if (entry == null) return prop;
|
||
|
|
||
13 years ago
|
if (entry.url() == null) {
|
||
16 years ago
|
return prop;
|
||
|
}
|
||
12 years ago
|
final URIMetadataNode le = (entry.referrerHash() == null || entry.referrerHash().length != Word.commonHashLength) ? null : segment.fulltext().getMetadata(entry.referrerHash());
|
||
13 years ago
|
|
||
13 years ago
|
prop.putXML("dc_title", entry.dc_title());
|
||
|
prop.putXML("dc_creator", entry.dc_creator());
|
||
15 years ago
|
prop.putXML("dc_description", ""); // this is the fulltext part in the surrogate
|
||
13 years ago
|
prop.putXML("dc_subject", entry.dc_subject());
|
||
|
prop.putXML("dc_publisher", entry.dc_publisher());
|
||
16 years ago
|
prop.putXML("dc_contributor", "");
|
||
14 years ago
|
prop.putXML("dc_date", ISO8601Formatter.FORMATTER.format(entry.moddate()));
|
||
15 years ago
|
prop.putXML("dc_type", String.valueOf(entry.doctype()));
|
||
12 years ago
|
prop.putXML("dc_identifier", entry.url().toNormalform(true));
|
||
11 years ago
|
prop.putXML("dc_language", entry.language());
|
||
12 years ago
|
prop.putXML("collection", Arrays.toString(entry.collections()));
|
||
13 years ago
|
prop.put("geo_lat", entry.lat());
|
||
|
prop.put("geo_long", entry.lon());
|
||
16 years ago
|
|
||
13 years ago
|
prop.put("yacy_urlhash", entry.url().hash());
|
||
16 years ago
|
prop.putXML("yacy_loaddate", entry.loaddate().toString());
|
||
14 years ago
|
prop.putXML("yacy_referrer_hash", (le == null) ? "" : ASCII.String(le.hash()));
|
||
12 years ago
|
prop.putXML("yacy_referrer_url", (le == null) ? "" : le.url().toNormalform(true));
|
||
10 years ago
|
prop.put("yacy_size", entry.filesize());
|
||
13 years ago
|
prop.put("yacy_words", entry.wordCount());
|
||
11 years ago
|
prop.put("yacy_citations", sb.index.connectedCitation() ? sb.index.urlCitation().count(entry.hash()) : 0);
|
||
13 years ago
|
prop.put("yacy_inbound", entry.llocal());
|
||
|
prop.put("yacy_outbound", entry.lother());
|
||
13 years ago
|
|
||
16 years ago
|
// return rewrite properties
|
||
|
return prop;
|
||
|
}
|
||
|
|
||
|
}
|