From 4da15db9983f53be542147345c4ae355e8692656 Mon Sep 17 00:00:00 2001 From: luccioman Date: Tue, 17 Oct 2017 09:41:58 +0200 Subject: [PATCH] Fixed search result Snapshots link. Previously rendered as a broken URL containing the absolute file path of a snapshot on the search server. Now rendered as a valid URL linking to the /api/snapshot API to provide available snapshot content. Snapshot format is selected among the available ones in the following order of preference : JPG/PNG, PDF, and XML. --- htroot/ConfigSearchPage_p.html | 2 +- htroot/yacysearchitem.html | 2 +- htroot/yacysearchitem.java | 23 ++++++++++++++++++++++- locales/fr.lng | 2 +- locales/master.lng.xlf | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/htroot/ConfigSearchPage_p.html b/htroot/ConfigSearchPage_p.html index 2d8d54693..3e05283fa 100644 --- a/htroot/ConfigSearchPage_p.html +++ b/htroot/ConfigSearchPage_p.html @@ -258,7 +258,7 @@ var solr= $.getJSON("solr/collection1/select?q=*:*&defType=edismax&start=0&rows=  | Cache  | View via Proxy  | Browse index -  | Snapshots +  | JPG Snapshot #(search.result.show.ranking)#:: | Ranking: 1.12195955E9#(/search.result.show.ranking)# diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index 78bd3a080..5043c0df9 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -49,7 +49,7 @@ #(showProxy)#:: | View via proxy#(/showProxy)# #(showHostBrowser)#:: | Browse index#(/showHostBrowser)# #(showVocabulary)#::
#{vocabulary}##[name]#:#[terms]# #{/vocabulary}##(/showVocabulary)# - #(showSnapshots)#::Snapshots#(/showSnapshots)# + #(showSnapshots)#:: | #[extension]# Snapshot#(/showSnapshots)# #(showRanking)#:: | Ranking: #[ranking]##(/showRanking)#

diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index e2a3ce8d9..9a6ce2dee 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -33,6 +33,7 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Date; import java.util.Iterator; +import java.util.Locale; import java.util.StringTokenizer; import net.yacy.cora.date.GenericFormatter; @@ -338,7 +339,27 @@ public class yacysearchitem { prop.put("content_showVocabulary", 0); } if (snapshotPaths != null && snapshotPaths.size() > 0) { - prop.put("content_showSnapshots_link", snapshotPaths.iterator().next().getAbsolutePath()); + /* Only add a link to the eventual snapshot file in the format it is stored (no resource fetching and conversion here) */ + String selectedExt = null, ext; + for(final File snapshot : snapshotPaths) { + ext = MultiProtocolURL.getFileExtension(snapshot.getName()); + if("jpg".equals(ext) || "png".equals(ext)) { + /* Prefer snapshots in jpeg or png format */ + selectedExt = ext; + break; + } else if("pdf".equals(ext)) { + selectedExt = ext; + } else if("xml".equals(ext) && selectedExt == null) { + /* Use the XML metadata snapshot in last resort */ + selectedExt = ext; + } + } + if(selectedExt != null) { + prop.putHTML("content_showSnapshots_extension", selectedExt.toUpperCase(Locale.ROOT)); + prop.putHTML("content_showSnapshots_link", "api/snapshot." + selectedExt + "?url=" + resultURL); + } else { + prop.put("content_showSnapshots", 0); + } } prop.put("content_showRanking_ranking", Float.toString(result.score())); prop.put("content_ranking", Float.toString(result.score())); diff --git a/locales/fr.lng b/locales/fr.lng index f6c5b5b47..560c7b837 100644 --- a/locales/fr.lng +++ b/locales/fr.lng @@ -590,7 +590,7 @@ Maximum range (in days)==Période maximale (en jours) Maximum days number in the histogram. Beware that a large value may trigger high CPU loads both on the server and on the browser with large result sets.==Nombre maximum de jours de l'histogramme. Veuillez noter qu'une valeur élevée peut déclencher des charges CPU importantes tant sur le serveur que sur le navigateur lorsqu'il y a un grand nombre de résultats. keyword subject keyword2 keyword3==mot-clé sujet mot-clé2 mot-clé3 View via Proxy==Ouvrir via le proxy ->Snapshots<==>Captures< +>JPG Snapshot<==>Capture JPG< "Raw ranking score value"=="Score de classement brut" Ranking: 1.12195955E9==Score: 1.12195955E9 "Delete navigator"=="Supprimer le groupe" diff --git a/locales/master.lng.xlf b/locales/master.lng.xlf index d56331813..bc775a744 100644 --- a/locales/master.lng.xlf +++ b/locales/master.lng.xlf @@ -2172,7 +2172,7 @@ View via Proxy - >Snapshots< + >JPG Snapshot< "Raw ranking score value"