@ -57,6 +57,7 @@ import net.yacy.document.Tokenizer;
import net.yacy.document.parser.pdfParser ;
import net.yacy.document.parser.html.ContentScraper ;
import net.yacy.document.parser.html.IconEntry ;
import net.yacy.document.parser.html.IconLinkRelations ;
import net.yacy.kelondro.data.word.Word ;
import net.yacy.kelondro.data.word.WordReferenceRow ;
import net.yacy.kelondro.data.word.WordReferenceVars ;
@ -96,6 +97,12 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
private String alternative_urlname ;
private TextSnippet textSnippet = null ;
/ * *
* Creates an instance from encoded properties .
* @param prop encoded properties
* @param collection collection origin ( e . g . "dht" )
* @throws MalformedURLException
* /
public URIMetadataNode ( final Properties prop , String collection ) throws MalformedURLException {
// generates an plasmaLURLEntry using the properties from the argument
// the property names must correspond to the one from toString
@ -165,7 +172,13 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
if ( prop . containsKey ( "wi" ) ) {
this . word = new WordReferenceVars ( new WordReferenceRow ( Base64Order . enhancedCoder . decodeString ( prop . getProperty ( "wi" , "" ) ) ) , false ) ;
}
if ( prop . containsKey ( "favicon" ) ) {
final String rawFaviconURL = crypt . simpleDecode ( prop . getProperty ( "favicon" , "" ) ) ;
DigestURL faviconURL = new DigestURL ( rawFaviconURL ) ;
this . setIconsFields ( faviconURL ) ;
}
}
public URIMetadataNode ( final SolrDocument doc ) throws MalformedURLException {
super ( ) ;
@ -570,6 +583,72 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
return icons ;
}
/ * *
* Try to extract icon entry with preferred size from this solr document .
* We look preferably for a standard icon but accept as a fallback other icons .
* @param preferredSize preferred size
* @return icon entry or null
* /
public IconEntry getFavicon ( Dimension preferredSize ) {
IconEntry faviconEntry = null ;
boolean foundStandard = false ;
double closestDistance = Double . MAX_VALUE ;
for ( IconEntry icon : this . getIcons ( ) ) {
boolean isStandard = icon . isStandardIcon ( ) ;
double distance = IconEntry . getDistance ( icon . getClosestSize ( preferredSize ) , preferredSize ) ;
boolean match = false ;
if ( foundStandard ) {
/ *
* Already found a standard icon : now must find a standard icon
* with closer size
* /
match = isStandard & & distance < closestDistance ;
} else {
/ *
* No standard icon yet found : prefer a standard icon , or check
* size
* /
match = isStandard | | distance < closestDistance ;
}
if ( match ) {
faviconEntry = icon ;
closestDistance = distance ;
foundStandard = isStandard ;
if ( isStandard & & distance = = 0.0 ) {
break ;
}
}
}
return faviconEntry ;
}
/ * *
* Use iconURL to set icons related field on this solr document .
*
* @param iconURL icon URL
* /
private void setIconsFields ( DigestURL iconURL ) {
final List < String > protocols = new ArrayList < String > ( 1 ) ;
final List < String > sizes = new ArrayList < String > ( 1 ) ;
final List < String > stubs = new ArrayList < String > ( 1 ) ;
final List < String > rels = new ArrayList < String > ( 1 ) ;
if ( iconURL ! = null ) {
String protocol = iconURL . getProtocol ( ) ;
protocols . add ( protocol ) ;
sizes . add ( "" ) ;
stubs . add ( iconURL . toString ( ) . substring ( protocol . length ( ) + 3 ) ) ;
rels . add ( IconLinkRelations . ICON . getRelValue ( ) ) ;
}
this . setField ( CollectionSchema . icons_protocol_sxt . name ( ) , protocols ) ;
this . setField ( CollectionSchema . icons_urlstub_sxt . name ( ) , stubs ) ;
this . setField ( CollectionSchema . icons_rel_sxt . name ( ) , rels ) ;
this . setField ( CollectionSchema . icons_sizes_sxt . name ( ) , sizes ) ;
}
/ * *
* @param name field name
* @return field values from field name eventually immutable empty list when field has no values or is not a List
@ -673,6 +752,13 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
final String wprop = this . word ( ) . toPropertyForm ( ) ;
s . append ( ",wi=" ) . append ( Base64Order . enhancedCoder . encodeString ( wprop ) ) ;
}
/* Add favicon URL with preferred size being 16x16 pixels if known */
if ( ! this . getIcons ( ) . isEmpty ( ) ) {
IconEntry faviconEntry = this . getFavicon ( new Dimension ( 16 , 16 ) ) ;
if ( faviconEntry ! = null ) {
s . append ( ",favicon=" ) . append ( crypt . simpleEncode ( faviconEntry . getUrl ( ) . toNormalform ( false ) ) ) ;
}
}
return s ;
} catch ( final Throwable e ) {
ConcurrentLog . logException ( e ) ;