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.
pull/1/head
Michael Peter Christen 10 years ago
parent 893889bc7b
commit fd4e2c809a

@ -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/"
>
<!-- YaCy Search Engine; http://yacy.net -->
<channel>

@ -25,6 +25,7 @@
<p class="url"><a href="#[link]#" id="url#[urlhash]#" target="#[target]#">#[urlname]#</a></p>
<p class="urlinfo">
#(showDate)#::#[date]##(/showDate)#
#(showEvent)#::on #[date]##(/showEvent)#
#(showSize)#::&nbsp;|&nbsp;#[sizename]##(/showSize)#
#(showMetadata)#::&nbsp;|&nbsp;<a href="solr/select?q=id:%22#[urlhash]#%22&defType=edismax&start=0&rows=1&core=collection1&wt=html" target="_blank" onclick="return hs.htmlExpand(this, { objectType: 'ajax'} )">Metadata</a>#(/showMetadata)#
#(showParser)#::&nbsp;|&nbsp;<a href="ViewFile.html?urlHash=#[urlhash]#&amp;words=#[words]#" target="_blank">Parser</a>#(/showParser)#

@ -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()));

@ -5,6 +5,7 @@
"code": "#[code]#",
"description": "#[description-json]#",
"pubDate": "#[date822]#",
#(showEvent)#::"eventDate": "#[date822]#",#(/showEvent)#
"size": "#[size]#",
"sizename": "#[sizename]#",
"guid": "#[urlhash]#",

@ -3,6 +3,7 @@
<link>#[link]#</link>
<description>#[description-xml]#</description>
<pubDate>#[date822]#</pubDate>
#(showEvent)#::<ev:startdate>#[date822]#</ev:startdate><ev:enddate>#[date822]#</ev:enddate>#(/showEvent)#
<dc:publisher><![CDATA[#[publisher]#]]></dc:publisher>
<dc:creator><![CDATA[#[creator]#]]></dc:creator>
<dc:subject><![CDATA[#[subject]#]]></dc:subject>

@ -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<Date> x = (List<Date>) 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;

@ -170,6 +170,9 @@ public class ResultEntry implements Comparable<ResultEntry>, Comparator<ResultEn
public Date modified() {
return this.urlentry.moddate();
}
public Date[] events() {
return this.urlentry.datesInContent();
}
public int filesize() {
return this.urlentry.filesize();
}

Loading…
Cancel
Save