diff --git a/htroot/ConfigSearchPage_p.html b/htroot/ConfigSearchPage_p.html index 613fcddad..d86c07b5b 100644 --- a/htroot/ConfigSearchPage_p.html +++ b/htroot/ConfigSearchPage_p.html @@ -177,7 +177,7 @@ $(function() { #[content_showDate_date]#  | 42 kbyte -  | Metadata +  | Metadata  | Parser  | Pictures  | Cache diff --git a/htroot/IndexControlURLs_p.html b/htroot/IndexControlURLs_p.html index c22c46516..c1fd4d14f 100644 --- a/htroot/IndexControlURLs_p.html +++ b/htroot/IndexControlURLs_p.html @@ -216,9 +216,9 @@ function updatepage(str) { #(genUrlProfile)# ::No entry found for URL-hash #[urlhash]# - ::
+ ::
- + API These document details can be retrieved as XHTML+RDFa document containg RDF annotations in Dublin Core vocabulary. diff --git a/htroot/ViewFile.html b/htroot/ViewFile.html index abda39d6d..2bf65cbbf 100644 --- a/htroot/ViewFile.html +++ b/htroot/ViewFile.html @@ -88,39 +88,20 @@ function updatepage(str) { + +
#(error)#
URL Metadata
URL:
#[url]#
-
Hash:
#[hash]#
+
Hash:
#[hash]# (click this for full metadata)
In Metadata:
#(inurldb)#no::yes#(/inurldb)#
In Cache:
#(incache)#no::yes#(/incache)#
Word Count:
#[wordCount]#
Description:
#[desc]#
Size:
#[size]# Bytes
#(mimeTypeAvailable)#::
MimeType:
#[mimeType]#
#(/mimeTypeAvailable)# -
Referrer Hash:
#[referrerHash]#
-
Modified Date:
#[moddate]#
-
Load Date:
#[loaddate]#
-
Fresh Date:
#[freshdate]#
-
Host Hash:
#[hosthash]#
-
dc_creator:
#[dc_creator]#
-
dc_publisher:
#[dc_publisher]#
-
dc_subject:
#[dc_subject]#
-
md5:
#[md5]#
-
lat:
#[lat]#
-
lon:
#[lon]#
-
doctype:
#[doctype]#
-
Language:
#[language]#
-
Flags:
#[flags]#
-
Word Count:
#[wordCount]#
-
Local Links:
#[llocal]#
-
Global Links:
#[lother]#
-
Image Links:
#[limage]#
-
Audio Links:
#[laudio]#
-
Video Links:
#[lvideo]#
-
App Links:
#[lapp]#
Collections:
#[collections]#
Triplestore:
#[triples]#
:
@@ -156,7 +137,7 @@ function updatepage(str) { :: Unsupported protocol. #(/error)# - +
#(viewMode)# ::
Original Content from Web @@ -225,7 +206,7 @@ function updatepage(str) {
#(/viewMode)# - +
#%env/templates/footer.template%# diff --git a/htroot/solr/select.java b/htroot/solr/select.java index 00f872490..c127d2bae 100644 --- a/htroot/solr/select.java +++ b/htroot/solr/select.java @@ -33,6 +33,7 @@ import net.yacy.cora.federate.solr.SolrServlet; import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector; import net.yacy.cora.federate.solr.responsewriter.EnhancedXMLResponseWriter; import net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter; +import net.yacy.cora.federate.solr.responsewriter.HTMLResponseWriter; import net.yacy.cora.federate.solr.responsewriter.JsonResponseWriter; import net.yacy.cora.federate.solr.responsewriter.OpensearchResponseWriter; import net.yacy.cora.protocol.HeaderFramework; @@ -83,6 +84,7 @@ public class select { xsltWriter.init(initArgs); RESPONSE_WRITER.put("xslt", xsltWriter); // try i.e. http://localhost:8090/solr/select?q=*:*&start=0&rows=10&wt=xslt&tr=json.xsl RESPONSE_WRITER.put("exml", new EnhancedXMLResponseWriter()); + RESPONSE_WRITER.put("html", new HTMLResponseWriter()); RESPONSE_WRITER.put("rss", opensearchResponseWriter); //try http://localhost:8090/solr/select?wt=rss&q=olympia&hl=true&hl.fl=text_t,h1,h2 RESPONSE_WRITER.put("opensearch", opensearchResponseWriter); //try http://localhost:8090/solr/select?wt=rss&q=olympia&hl=true&hl.fl=text_t,h1,h2 RESPONSE_WRITER.put("yjson", new JsonResponseWriter()); //try http://localhost:8090/solr/select?wt=json&q=olympia&hl=true&hl.fl=text_t,h1,h2 @@ -107,7 +109,7 @@ public class select { if ("exml".equals(wt)) return "application/rss+xml"; if ("json".equals(wt)) return "application/json"; if ("yjson".equals(wt)) return "application/json"; - if ("python".equals(wt)) return "text/html"; + if ("html".equals(wt) || "python".equals(wt)) return "text/html"; if ("php".equals(wt) || "phps".equals(wt)) return "application/x-httpd-php"; if ("ruby".equals(wt)) return "text/html"; if ("raw".equals(wt)) return "application/octet-stream"; diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index 906e3c95a..9b30e35b5 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -26,7 +26,7 @@

#(showDate)#::#[date]##(/showDate)# #(showSize)#:: | #[sizename]##(/showSize)# - #(showMetadata)#:: | Metadata#(/showMetadata)# + #(showMetadata)#:: | Metadata#(/showMetadata)# #(showParser)#:: | Parser#(/showParser)# #(showPictures)#:: | Pictures#(/showPictures)# #(showCache)#:: | Cache#(/showCache)# diff --git a/source/net/yacy/cora/federate/solr/responsewriter/HTMLResponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/HTMLResponseWriter.java new file mode 100644 index 000000000..d2ca13f12 --- /dev/null +++ b/source/net/yacy/cora/federate/solr/responsewriter/HTMLResponseWriter.java @@ -0,0 +1,190 @@ +/** + * HTMLResponseWriter + * Copyright 2013 by Michael Peter Christen + * First released 09.06.2013 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.cora.federate.solr.responsewriter; + +import java.io.IOException; +import java.io.Writer; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +import net.yacy.cora.federate.solr.SolrType; +import net.yacy.search.schema.CollectionSchema; + +import org.apache.lucene.document.Document; +import org.apache.lucene.index.IndexableField; +import org.apache.solr.common.params.SolrParams; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.common.util.XML; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.QueryResponseWriter; +import org.apache.solr.response.ResultContext; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.schema.FieldType; +import org.apache.solr.schema.IndexSchema; +import org.apache.solr.schema.SchemaField; +import org.apache.solr.schema.TextField; +import org.apache.solr.search.DocIterator; +import org.apache.solr.search.DocList; +import org.apache.solr.search.SolrIndexSearcher; + +public class HTMLResponseWriter implements QueryResponseWriter { + + private static final Set DEFAULT_FIELD_LIST = null; + private static final Pattern dqp = Pattern.compile("\""); + + public HTMLResponseWriter() { + super(); + } + + @Override + public String getContentType(final SolrQueryRequest request, final SolrQueryResponse response) { + return CONTENT_TYPE_XML_UTF8; + } + + @Override + public void init(@SuppressWarnings("rawtypes") NamedList n) { + } + + @Override + public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp) throws IOException { + NamedList values = rsp.getValues(); + assert values.get("responseHeader") != null; + assert values.get("response") != null; + + writer.write("\n"); + //writer.write("\n"); + writer.write("\n"); + writer.write("\n"); + //writer.write("\n"); + writer.write("\n"); + writer.write("\n"); + NamedList paramsList = request.getOriginalParams().toNamedList(); + paramsList.remove("wt"); + String xmlquery = dqp.matcher("/solr/select?" + SolrParams.toSolrParams(paramsList).toString()).replaceAll("%22"); + writer.write("
\"API\"\n"); + writer.write("This search result can also be retrieved as XML. Click the API icon to see an example call to the search rss API.
\n"); + + DocList response = ((ResultContext) values.get("response")).docs; + final int sz = response.size(); + if (sz > 0) { + SolrIndexSearcher searcher = request.getSearcher(); + DocIterator iterator = response.iterator(); + IndexSchema schema = request.getSchema(); + + if (sz == 1) { + int id = iterator.nextDoc(); + Document doc = searcher.doc(id, DEFAULT_FIELD_LIST); + LinkedHashMap tdoc = translateDoc(schema, doc); + String title = tdoc.get(CollectionSchema.title.getSolrFieldName()); + writer.write("" + title + "\n\n"); + writeDoc(writer, tdoc, title); + } else { + writer.write("Document List\n\n"); + for (int i = 0; i < sz; i++) { + int id = iterator.nextDoc(); + Document doc = searcher.doc(id, DEFAULT_FIELD_LIST); + LinkedHashMap tdoc = translateDoc(schema, doc); + String title = tdoc.get(CollectionSchema.title.getSolrFieldName()); + writeDoc(writer, tdoc, title); + } + } + } else { + writer.write("No Document Found\n\n"); + } + + writer.write("\n"); + } + + private static final void writeDoc(Writer writer, LinkedHashMap tdoc, String title) throws IOException { + writer.write("\n"); + writer.write("
\n"); + writer.write("

" + title + "

\n"); + writer.write("
\n"); + for (Map.Entry entry: tdoc.entrySet()) { + writer.write("
"); + writer.write(entry.getKey()); + writer.write("
"); + XML.escapeAttributeValue(entry.getValue(), writer); + writer.write("
\n"); + } + writer.write("
\n"); + writer.write("
\n"); + writer.write("\n"); + } + + private static final LinkedHashMap translateDoc(final IndexSchema schema, final Document doc) { + List fields = doc.getFields(); + int sz = fields.size(); + int fidx1 = 0, fidx2 = 0; + LinkedHashMap kv = new LinkedHashMap(); + while (fidx1 < sz) { + IndexableField value = fields.get(fidx1); + String fieldName = value.name(); + fidx2 = fidx1 + 1; + while (fidx2 < sz && fieldName.equals(fields.get(fidx2).name())) { + fidx2++; + } + SchemaField sf = schema.getFieldOrNull(fieldName); + if (sf == null) sf = new SchemaField(fieldName, new TextField()); + FieldType type = sf.getType(); + + if (fidx1 + 1 == fidx2) { + if (sf.multiValued()) { + String sv = value.stringValue(); + kv.put(fieldName, field2string(type, sv)); + } else { + kv.put(fieldName, field2string(type, value.stringValue())); + } + } else { + for (int i = fidx1; i < fidx2; i++) { + String sv = fields.get(i).stringValue(); + kv.put(fieldName + "_" + i, field2string(type, sv)); + } + } + + fidx1 = fidx2; + } + return kv; + } + + @SuppressWarnings("deprecation") + private static String field2string(final FieldType type, final String value) { + String typeName = type.getTypeName(); + if (typeName.equals(SolrType.bool.printName())) { + return "F".equals(value) ? "false" : "true"; + } else if (typeName.equals(SolrType.date.printName())) { + return org.apache.solr.schema.DateField.formatExternal(new Date(Long.parseLong(value))); // this is declared deprecated in solr 4.2.1 but is still used as done here + } + return value; + } + + // XML.escapeCharData(val, writer); +}