From fd4e2c809ad415d4bc9e4ca65cf1dea56d2a7940 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Mon, 2 Mar 2015 18:00:20 +0100 Subject: [PATCH] Show dates in the content of a document in the search result: - if an eventDate is given in the search result, replace the document date with the event date and prefix it with the string "on ". - the document date is omitted if a date from the cent is shown Added also the date as fields in the json and rss result sets. --- htroot/yacysearch.rss | 1 + htroot/yacysearchitem.html | 1 + htroot/yacysearchitem.java | 8 +++++++- htroot/yacysearchitem.json | 1 + htroot/yacysearchitem.xml | 1 + .../yacy/kelondro/data/meta/URIMetadataNode.java | 13 +++++++++++++ source/net/yacy/search/snippet/ResultEntry.java | 3 +++ 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/htroot/yacysearch.rss b/htroot/yacysearch.rss index 2a8a3a8f1..ded55e396 100644 --- a/htroot/yacysearch.rss +++ b/htroot/yacysearch.rss @@ -7,6 +7,7 @@ xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" + xmlns:ev="http://purl.org/rss/1.0/modules/event/" > diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index 4e6a9a027..2bc81b6fc 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -25,6 +25,7 @@

#[urlname]#

#(showDate)#::#[date]##(/showDate)# + #(showEvent)#::on #[date]##(/showEvent)# #(showSize)#:: | #[sizename]##(/showSize)# #(showMetadata)#:: | Metadata#(/showMetadata)# #(showParser)#:: | Parser#(/showParser)# diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index 9fd353c61..41980c540 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.net.MalformedURLException; import java.util.Collection; +import java.util.Date; import java.util.Iterator; import java.util.Map; @@ -195,8 +196,11 @@ public class yacysearchitem { prop.putHTML("content_faviconCode", URLLicense.aquireLicense(faviconURL)); // acquire license for favicon url loading prop.put("content_urlhash", urlhash); prop.put("content_ranking", Float.toString(result.score())); + Date[] events = result.events(); + boolean showEvent = events != null && events.length > 0 && sb.getConfig("search.navigation", "").indexOf("date",0) >= 0; + prop.put("content_showEvent", showEvent ? 1 : 0); if (fileType == FileType.HTML) { // html template specific settings - prop.put("content_showDate", sb.getConfigBool("search.result.show.date", true) ? 1 : 0); + prop.put("content_showDate", sb.getConfigBool("search.result.show.date", true) && !showEvent ? 1 : 0); prop.put("content_showSize", sb.getConfigBool("search.result.show.size", true) ? 1 : 0); prop.put("content_showMetadata", sb.getConfigBool("search.result.show.metadata", true) ? 1 : 0); prop.put("content_showParser", sb.getConfigBool("search.result.show.parser", true) ? 1 : 0); @@ -207,6 +211,7 @@ public class yacysearchitem { prop.put("content_showHostBrowser", sb.getConfigBool("search.result.show.hostbrowser", true) ? 1 : 0); prop.put("content_showVocabulary", sb.getConfigBool("search.result.show.vocabulary", true) ? 1 : 0); + if (showEvent) prop.put("content_showEvent_date", GenericFormatter.RFC1123_SHORT_FORMATTER.format(events[0])); prop.put("content_showDate_date", GenericFormatter.RFC1123_SHORT_FORMATTER.format(result.modified())); prop.putHTML("content_showSize_sizename", RSSMessage.sizename(result.filesize())); prop.put("content_showMetadata_urlhash", urlhash); @@ -239,6 +244,7 @@ public class yacysearchitem { prop.put("content_urlhexhash", Seed.b64Hash2hexHash(urlhash)); prop.putHTML("content_urlname", nxTools.shortenURLString(result.urlname(), MAX_URL_LENGTH)); prop.put("content_date822", isAtomFeed ? ISO8601Formatter.FORMATTER.format(result.modified()) : HeaderFramework.formatRFC1123(result.modified())); + if (showEvent) prop.put("content_showEvent_date822", isAtomFeed ? ISO8601Formatter.FORMATTER.format(events[0]) : HeaderFramework.formatRFC1123(events[0])); //prop.put("content_ybr", RankingProcess.ybr(result.hash())); prop.putHTML("content_size", Integer.toString(result.filesize())); // we don't use putNUM here because that number shall be usable as sorting key. To print the size, use 'sizename' prop.putHTML("content_sizename", RSSMessage.sizename(result.filesize())); diff --git a/htroot/yacysearchitem.json b/htroot/yacysearchitem.json index bde450962..a8bb2f413 100644 --- a/htroot/yacysearchitem.json +++ b/htroot/yacysearchitem.json @@ -5,6 +5,7 @@ "code": "#[code]#", "description": "#[description-json]#", "pubDate": "#[date822]#", + #(showEvent)#::"eventDate": "#[date822]#",#(/showEvent)# "size": "#[size]#", "sizename": "#[sizename]#", "guid": "#[urlhash]#", diff --git a/htroot/yacysearchitem.xml b/htroot/yacysearchitem.xml index 5fc71a6a2..c8dfb7e87 100644 --- a/htroot/yacysearchitem.xml +++ b/htroot/yacysearchitem.xml @@ -3,6 +3,7 @@ #[link]# #[description-xml]# #[date822]# +#(showEvent)#::#[date822]##[date822]##(/showEvent)# diff --git a/source/net/yacy/kelondro/data/meta/URIMetadataNode.java b/source/net/yacy/kelondro/data/meta/URIMetadataNode.java index 4fa085932..c7dacc618 100644 --- a/source/net/yacy/kelondro/data/meta/URIMetadataNode.java +++ b/source/net/yacy/kelondro/data/meta/URIMetadataNode.java @@ -213,6 +213,10 @@ public class URIMetadataNode extends SolrDocument { return getDate(CollectionSchema.last_modified); } + public Date[] datesInContent() { + return getDates(CollectionSchema.dates_in_content_dts); + } + public DigestURL url() { return this.url; } @@ -596,6 +600,15 @@ public class URIMetadataNode extends SolrDocument { return x.after(now) ? now : x; } + private Date[] getDates(CollectionSchema field) { + assert field.isMultiValued(); + assert field.getType() == SolrType.date; + @SuppressWarnings("unchecked") + List x = (List) this.getFieldValue(field.getSolrFieldName()); + if (x == null) return new Date[0]; + return x.toArray(new Date[x.size()]); + } + private String getString(CollectionSchema field) { assert !field.isMultiValued(); assert field.getType() == SolrType.string || field.getType() == SolrType.text_general || field.getType() == SolrType.text_en_splitting_tight; diff --git a/source/net/yacy/search/snippet/ResultEntry.java b/source/net/yacy/search/snippet/ResultEntry.java index 4201416c1..e9f91d544 100644 --- a/source/net/yacy/search/snippet/ResultEntry.java +++ b/source/net/yacy/search/snippet/ResultEntry.java @@ -170,6 +170,9 @@ public class ResultEntry implements Comparable, Comparator