2007-08-28 14:15:46 +02:00
// yacysearchitem.java
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 28.08.2007 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
2009-09-27 00:07:40 +02:00
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2007-08-28 14:15:46 +02:00
//
// LICENSE
2011-06-13 23:44:03 +02:00
//
2007-08-28 14:15:46 +02:00
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.net.MalformedURLException ;
2013-11-26 02:24:47 +01:00
import java.util.Iterator ;
2013-12-04 22:44:51 +01:00
2011-01-03 21:52:54 +01:00
import net.yacy.cora.date.GenericFormatter ;
2012-11-21 18:46:49 +01:00
import net.yacy.cora.document.analysis.Classification ;
import net.yacy.cora.document.analysis.Classification.ContentDomain ;
2013-09-15 00:30:23 +02:00
import net.yacy.cora.document.encoding.ASCII ;
import net.yacy.cora.document.feed.RSSMessage ;
import net.yacy.cora.document.id.DigestURL ;
import net.yacy.cora.document.id.MultiProtocolURL ;
2013-05-20 22:05:28 +02:00
import net.yacy.cora.protocol.ClientIdentification ;
2012-06-26 00:08:25 +02:00
import net.yacy.cora.protocol.Domains ;
2010-08-23 14:32:02 +02:00
import net.yacy.cora.protocol.HeaderFramework ;
import net.yacy.cora.protocol.RequestHeader ;
2011-10-13 00:26:48 +02:00
import net.yacy.cora.protocol.RequestHeader.FileType ;
2013-07-09 14:28:25 +02:00
import net.yacy.cora.util.ConcurrentLog ;
2013-12-04 22:44:51 +01:00
import net.yacy.cora.util.Memory ;
2013-06-09 08:15:23 +02:00
import net.yacy.crawler.data.Cache ;
2013-02-13 00:33:53 +01:00
import net.yacy.data.URLLicense ;
2009-10-10 03:14:19 +02:00
import net.yacy.kelondro.util.Formatter ;
2011-10-04 11:06:24 +02:00
import net.yacy.peers.NewsPool ;
import net.yacy.peers.Seed ;
2011-09-25 18:59:06 +02:00
import net.yacy.peers.graphics.ProfilingGraph ;
2012-05-04 17:28:27 +02:00
import net.yacy.search.EventTracker ;
2011-09-25 18:59:06 +02:00
import net.yacy.search.Switchboard ;
import net.yacy.search.SwitchboardConstants ;
2012-11-01 17:16:43 +01:00
import net.yacy.search.query.HeuristicResult ;
2011-09-25 18:59:06 +02:00
import net.yacy.search.query.QueryParams ;
import net.yacy.search.query.SearchEvent ;
import net.yacy.search.query.SearchEventCache ;
2012-11-01 17:16:43 +01:00
import net.yacy.search.query.SearchEventType ;
2011-09-25 18:59:06 +02:00
import net.yacy.search.snippet.ResultEntry ;
import net.yacy.search.snippet.TextSnippet ;
2012-09-21 15:48:16 +02:00
import net.yacy.server.serverObjects ;
import net.yacy.server.serverSwitch ;
import net.yacy.utils.crypt ;
import net.yacy.utils.nxTools ;
2007-08-28 14:15:46 +02:00
public class yacysearchitem {
2011-06-13 23:44:03 +02:00
2011-03-08 23:37:17 +01:00
private static final String SHORTEN_SUFFIX = " ... " ;
private static final int SHORTEN_SUFFIX_LENGTH = SHORTEN_SUFFIX . length ( ) ;
private static final int MAX_NAME_LENGTH = 60 ;
private static final int MAX_URL_LENGTH = 120 ;
2007-08-28 14:15:46 +02:00
2012-05-16 13:42:32 +02:00
//private static boolean col = true;
2011-06-13 23:44:03 +02:00
2009-07-19 22:37:44 +02:00
public static serverObjects respond ( final RequestHeader header , final serverObjects post , final serverSwitch env ) {
final Switchboard sb = ( Switchboard ) env ;
2007-08-28 14:15:46 +02:00
final serverObjects prop = new serverObjects ( ) ;
2011-06-13 23:44:03 +02:00
2008-08-02 14:12:04 +02:00
final String eventID = post . get ( " eventID " , " " ) ;
final boolean authenticated = sb . adminAuthenticated ( header ) > = 2 ;
final int item = post . getInt ( " item " , - 1 ) ;
2012-06-26 00:08:25 +02:00
final boolean auth = Domains . isLocalhost ( header . get ( HeaderFramework . CONNECTION_PROP_CLIENTIP , " " ) ) | | sb . verifyAuthentication ( header ) ;
2011-10-13 00:26:48 +02:00
final RequestHeader . FileType fileType = header . fileType ( ) ;
2011-03-08 23:37:17 +01:00
2007-09-09 14:30:18 +02:00
// default settings for blank item
2007-10-24 23:38:19 +02:00
prop . put ( " content " , " 0 " ) ;
prop . put ( " rss " , " 0 " ) ;
prop . put ( " references " , " 0 " ) ;
prop . put ( " rssreferences " , " 0 " ) ;
prop . put ( " dynamic " , " 0 " ) ;
2011-06-13 23:44:03 +02:00
2007-08-28 14:15:46 +02:00
// find search event
2009-08-24 17:24:02 +02:00
final SearchEvent theSearch = SearchEventCache . getEvent ( eventID ) ;
2007-09-09 14:30:18 +02:00
if ( theSearch = = null ) {
// the event does not exist, show empty page
return prop ;
}
2011-06-13 23:44:03 +02:00
2007-09-04 01:43:55 +02:00
// dynamically update count values
2012-11-05 03:19:28 +01:00
prop . put ( " offset " , theSearch . query . neededResults ( ) - theSearch . query . itemsPerPage ( ) + 1 ) ;
2013-02-26 17:16:31 +01:00
prop . put ( " itemscount " , Formatter . number ( Math . min ( ( item < 0 ) ? theSearch . query . neededResults ( ) : item + 1 , theSearch . getResultCount ( ) ) ) ) ;
2012-11-05 03:19:28 +01:00
prop . put ( " itemsperpage " , Formatter . number ( theSearch . query . itemsPerPage ) ) ;
2013-02-26 17:16:31 +01:00
prop . put ( " totalcount " , Formatter . number ( theSearch . getResultCount ( ) , true ) ) ;
2013-03-03 22:38:50 +01:00
prop . put ( " localResourceSize " , Formatter . number ( theSearch . local_rwi_stored . get ( ) + theSearch . local_solr_stored . get ( ) , true ) ) ;
2013-02-27 22:40:23 +01:00
prop . put ( " remoteResourceSize " , Formatter . number ( theSearch . remote_rwi_stored . get ( ) + theSearch . remote_solr_stored . get ( ) , true ) ) ;
prop . put ( " remoteIndexCount " , Formatter . number ( theSearch . remote_rwi_available . get ( ) + theSearch . remote_solr_available . get ( ) , true ) ) ;
prop . put ( " remotePeerCount " , Formatter . number ( theSearch . remote_rwi_peerCount . get ( ) + theSearch . remote_solr_peerCount . get ( ) , true ) ) ;
2013-02-12 11:52:33 +01:00
prop . put ( " navurlBase " , QueryParams . navurlBase ( " html " , theSearch . query , null ) . toString ( ) ) ;
2012-01-26 15:32:30 +01:00
final String target_special_pattern = sb . getConfig ( SwitchboardConstants . SEARCH_TARGET_SPECIAL_PATTERN , " " ) ;
2011-06-13 23:44:03 +02:00
2013-03-19 11:23:18 +01:00
long timeout = item = = 0 ? 10000 : ( theSearch . query . isLocal ( ) ? 1000 : 3000 ) ;
2012-11-05 03:19:28 +01:00
if ( theSearch . query . contentdom = = Classification . ContentDomain . TEXT | | theSearch . query . contentdom = = Classification . ContentDomain . ALL ) {
2007-09-06 15:26:38 +02:00
// text search
2008-02-21 15:53:51 +01:00
// generate result object
2013-03-19 11:23:18 +01:00
final ResultEntry result = theSearch . oneResult ( item , timeout ) ;
2008-02-21 15:53:51 +01:00
if ( result = = null ) return prop ; // no content
2012-01-26 15:32:30 +01:00
final String resultUrlstring = result . urlstring ( ) ;
2013-09-15 00:30:23 +02:00
final DigestURL resultURL = result . url ( ) ;
2012-01-26 15:32:30 +01:00
final String target = sb . getConfig ( resultUrlstring . matches ( target_special_pattern ) ? SwitchboardConstants . SEARCH_TARGET_SPECIAL : SwitchboardConstants . SEARCH_TARGET_DEFAULT , " _self " ) ;
2010-12-01 19:48:21 +01:00
final int port = resultURL . getPort ( ) ;
2013-09-15 00:30:23 +02:00
DigestURL faviconURL = null ;
2012-05-19 01:06:33 +02:00
if ( ( fileType = = FileType . HTML | | fileType = = FileType . JSON ) & & ! sb . isIntranetMode ( ) ) try {
2013-09-15 00:30:23 +02:00
faviconURL = new DigestURL ( resultURL . getProtocol ( ) + " :// " + resultURL . getHost ( ) + ( ( port ! = - 1 ) ? ( " : " + port ) : " " ) + " /favicon.ico " ) ;
2008-08-02 14:12:04 +02:00
} catch ( final MalformedURLException e1 ) {
2013-07-09 14:28:25 +02:00
ConcurrentLog . logException ( e1 ) ;
2007-09-06 15:26:38 +02:00
faviconURL = null ;
}
2012-11-05 03:19:28 +01:00
final String resource = theSearch . query . domType . toString ( ) ;
2014-01-20 00:58:17 +01:00
final String origQ = theSearch . query . getQueryGoal ( ) . getQueryString ( true ) ;
2008-12-02 16:24:25 +01:00
prop . put ( " content " , 1 ) ; // switch on specific content
2011-02-02 16:54:13 +01:00
prop . put ( " content_showDate " , sb . getConfigBool ( " search.result.show.date " , true ) ? 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 ) ;
2013-06-12 15:02:49 +02:00
prop . put ( " content_showCitation " , sb . getConfigBool ( " search.result.show.citation " , true ) ? 1 : 0 ) ;
2011-02-02 16:54:13 +01:00
prop . put ( " content_showPictures " , sb . getConfigBool ( " search.result.show.pictures " , true ) ? 1 : 0 ) ;
2013-06-09 08:15:23 +02:00
prop . put ( " content_showCache " , sb . getConfigBool ( " search.result.show.cache " , true ) & & Cache . has ( resultURL . hash ( ) ) ? 1 : 0 ) ;
2012-06-14 19:55:34 +02:00
prop . put ( " content_showProxy " , sb . getConfigBool ( " search.result.show.proxy " , true ) ? 1 : 0 ) ;
2012-12-27 10:01:10 +01:00
prop . put ( " content_showHostBrowser " , sb . getConfigBool ( " search.result.show.hostbrowser " , true ) ? 1 : 0 ) ;
2008-12-02 16:24:25 +01:00
prop . put ( " content_authorized " , authenticated ? " 1 " : " 0 " ) ;
2011-11-24 15:57:09 +01:00
final String urlhash = ASCII . String ( result . hash ( ) ) ;
prop . put ( " content_authorized_bookmark " , sb . tables . bookmarks . hasBookmark ( " admin " , urlhash ) ? " 0 " : " 1 " ) ;
2014-02-10 21:40:42 +01:00
prop . putHTML ( " content_authorized_bookmark_bookmarklink " , " yacysearch.html?query= " + origQ . replace ( ' ' , '+' ) + " &Enter=Search&count= " + theSearch . query . itemsPerPage ( ) + " &offset= " + ( theSearch . query . neededResults ( ) - theSearch . query . itemsPerPage ( ) ) + " &order= " + crypt . simpleEncode ( theSearch . query . ranking . toExternalString ( ) ) + " &resource= " + resource + " &time=3&bookmarkref= " + urlhash + " &urlmaskfilter=.* " ) ;
2012-01-26 15:32:30 +01:00
prop . put ( " content_authorized_recommend " , ( sb . peers . newsPool . getSpecific ( NewsPool . OUTGOING_DB , NewsPool . CATEGORY_SURFTIPP_ADD , " url " , resultUrlstring ) = = null ) ? " 1 " : " 0 " ) ;
2014-02-10 21:40:42 +01:00
prop . putHTML ( " content_authorized_recommend_deletelink " , " yacysearch.html?query= " + origQ . replace ( ' ' , '+' ) + " &Enter=Search&count= " + theSearch . query . itemsPerPage ( ) + " &offset= " + ( theSearch . query . neededResults ( ) - theSearch . query . itemsPerPage ( ) ) + " &order= " + crypt . simpleEncode ( theSearch . query . ranking . toExternalString ( ) ) + " &resource= " + resource + " &time=3&deleteref= " + urlhash + " &urlmaskfilter=.* " ) ;
prop . putHTML ( " content_authorized_recommend_recommendlink " , " yacysearch.html?query= " + origQ . replace ( ' ' , '+' ) + " &Enter=Search&count= " + theSearch . query . itemsPerPage ( ) + " &offset= " + ( theSearch . query . neededResults ( ) - theSearch . query . itemsPerPage ( ) ) + " &order= " + crypt . simpleEncode ( theSearch . query . ranking . toExternalString ( ) ) + " &resource= " + resource + " &time=3&recommendref= " + urlhash + " &urlmaskfilter=.* " ) ;
2011-11-24 15:57:09 +01:00
prop . put ( " content_authorized_urlhash " , urlhash ) ;
final String resulthashString = urlhash ;
2008-12-02 16:24:25 +01:00
prop . putHTML ( " content_title " , result . title ( ) ) ;
2009-01-17 00:22:42 +01:00
prop . putXML ( " content_title-xml " , result . title ( ) ) ;
2009-04-26 21:17:36 +02:00
prop . putJSON ( " content_title-json " , result . title ( ) ) ;
2012-01-26 15:32:30 +01:00
prop . putHTML ( " content_showPictures_link " , resultUrlstring ) ;
2012-06-10 10:51:53 +02:00
//prop.putHTML("content_link", resultUrlstring);
// START interaction
String modifyURL = resultUrlstring ;
2014-01-04 16:10:54 +01:00
if ( sb . getConfigBool ( " proxyURL.useforresults " , false ) & & sb . getConfigBool ( " proxyURL " , false ) ) {
2012-06-10 10:51:53 +02:00
// check if url is allowed to view
if ( sb . getConfig ( " proxyURL.rewriteURLs " , " all " ) . equals ( " all " ) ) {
modifyURL = " ./proxy.html?url= " + modifyURL ;
}
// check if url is allowed to view
if ( sb . getConfig ( " proxyURL.rewriteURLs " , " all " ) . equals ( " domainlist " ) ) {
try {
2013-09-15 00:30:23 +02:00
if ( sb . crawlStacker . urlInAcceptedDomain ( new DigestURL ( modifyURL ) ) = = null ) {
2012-06-10 10:51:53 +02:00
modifyURL = " ./proxy.html?url= " + modifyURL ;
}
2013-07-17 18:31:30 +02:00
} catch ( final MalformedURLException e ) {
2012-06-10 10:51:53 +02:00
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
}
if ( sb . getConfig ( " proxyURL.rewriteURLs " , " all " ) . equals ( " yacy " ) ) {
try {
2013-09-15 00:30:23 +02:00
if ( ( new DigestURL ( modifyURL ) . getHost ( ) . endsWith ( " .yacy " ) ) ) {
2012-06-10 10:51:53 +02:00
modifyURL = " ./proxy.html?url= " + modifyURL ;
}
2013-07-17 18:31:30 +02:00
} catch ( final MalformedURLException e ) {
2012-06-10 10:51:53 +02:00
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
}
}
prop . putHTML ( " content_link " , modifyURL ) ;
2012-06-14 17:56:38 +02:00
// prop.putHTML("content_value", Interaction.TripleGet(result.urlstring(), "http://virtual.x/hasvalue", "anonymous"));
2012-06-10 10:51:53 +02:00
// END interaction
2013-06-25 16:27:20 +02:00
String resultFileName = resultURL . getFileName ( ) ;
2011-02-02 01:50:06 +01:00
prop . putHTML ( " content_target " , target ) ;
2013-08-22 14:23:47 +02:00
if ( faviconURL ! = null & & fileType = = FileType . HTML ) sb . loader . loadIfNotExistBackground ( faviconURL , 1024 * 1024 * 10 , null , ClientIdentification . yacyIntranetCrawlerAgent ) ;
2013-02-13 00:33:53 +01:00
prop . putHTML ( " content_faviconCode " , URLLicense . aquireLicense ( faviconURL ) ) ; // acquire license for favicon url loading
2010-04-25 23:37:36 +02:00
prop . put ( " content_urlhash " , resulthashString ) ;
2013-03-13 14:47:00 +01:00
prop . put ( " content_ranking " , result . ranking ( ) ) ;
2011-02-02 16:54:13 +01:00
prop . put ( " content_showMetadata_urlhash " , resulthashString ) ;
2012-06-14 19:55:34 +02:00
prop . put ( " content_showCache_link " , resultUrlstring ) ;
prop . put ( " content_showProxy_link " , resultUrlstring ) ;
2012-12-27 10:01:10 +01:00
prop . put ( " content_showHostBrowser_link " , resultUrlstring ) ;
2011-02-02 16:54:13 +01:00
prop . put ( " content_showParser_urlhash " , resulthashString ) ;
2013-06-12 15:02:49 +02:00
prop . put ( " content_showCitation_urlhash " , resulthashString ) ;
2011-10-04 11:06:24 +02:00
prop . put ( " content_urlhexhash " , Seed . b64Hash2hexHash ( resulthashString ) ) ;
2011-03-08 23:37:17 +01:00
prop . putHTML ( " content_urlname " , nxTools . shortenURLString ( result . urlname ( ) , MAX_URL_LENGTH ) ) ;
2011-02-02 16:54:13 +01:00
prop . put ( " content_showDate_date " , GenericFormatter . RFC1123_SHORT_FORMATTER . format ( result . modified ( ) ) ) ;
2010-08-23 14:32:02 +02:00
prop . put ( " content_date822 " , HeaderFramework . formatRFC1123 ( result . modified ( ) ) ) ;
2010-05-04 22:57:09 +02:00
//prop.put("content_ybr", RankingProcess.ybr(result.hash()));
2009-02-23 12:39:20 +01:00
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'
2013-02-11 22:10:14 +01:00
prop . putHTML ( " content_sizename " , RSSMessage . sizename ( result . filesize ( ) ) ) ;
prop . putHTML ( " content_showSize_sizename " , RSSMessage . sizename ( result . filesize ( ) ) ) ;
2010-12-01 19:48:21 +01:00
prop . putHTML ( " content_host " , resultURL . getHost ( ) = = null ? " " : resultURL . getHost ( ) ) ;
2013-06-25 16:27:20 +02:00
prop . putHTML ( " content_file " , resultFileName ) ;
2010-12-01 19:48:21 +01:00
prop . putHTML ( " content_path " , resultURL . getPath ( ) ) ;
2012-11-05 03:19:28 +01:00
prop . put ( " content_nl " , ( item = = theSearch . query . offset ) ? 0 : 1 ) ;
2010-05-11 13:14:05 +02:00
prop . putHTML ( " content_publisher " , result . publisher ( ) ) ;
prop . putHTML ( " content_creator " , result . creator ( ) ) ; // author
prop . putHTML ( " content_subject " , result . subject ( ) ) ;
2013-11-26 02:24:47 +01:00
final Iterator < String > query = theSearch . query . getQueryGoal ( ) . getIncludeStrings ( ) ;
final StringBuilder s = new StringBuilder ( theSearch . query . getQueryGoal ( ) . getIncludeSize ( ) * 20 ) ;
while ( query . hasNext ( ) ) s . append ( '+' ) . append ( query . next ( ) ) ;
2011-03-08 23:37:17 +01:00
final String words = ( s . length ( ) > 0 ) ? s . substring ( 1 ) : " " ;
prop . putHTML ( " content_words " , words ) ;
prop . putHTML ( " content_showParser_words " , words ) ;
2012-12-15 00:05:46 +01:00
prop . putHTML ( " content_former " , origQ ) ;
prop . putHTML ( " content_showPictures_former " , origQ ) ;
2009-08-27 16:34:41 +02:00
final TextSnippet snippet = result . textSnippet ( ) ;
2012-11-18 01:22:41 +01:00
final String desc = ( snippet = = null ) ? " " : snippet . isMarked ( ) ? snippet . getLineRaw ( ) : snippet . getLineMarked ( theSearch . query . getQueryGoal ( ) ) ;
2009-04-27 14:52:12 +02:00
prop . put ( " content_description " , desc ) ;
prop . putXML ( " content_description-xml " , desc ) ;
prop . putJSON ( " content_description-json " , desc ) ;
2012-11-01 17:16:43 +01:00
final HeuristicResult heuristic = theSearch . getHeuristic ( result . hash ( ) ) ;
2010-06-27 23:38:16 +02:00
if ( heuristic = = null ) {
prop . put ( " content_heuristic " , 0 ) ;
} else {
if ( heuristic . redundant ) {
prop . put ( " content_heuristic " , 1 ) ;
} else {
prop . put ( " content_heuristic " , 2 ) ;
}
prop . put ( " content_heuristic_name " , heuristic . heuristicName ) ;
}
2012-11-05 03:19:28 +01:00
EventTracker . update ( EventTracker . EClass . SEARCH , new ProfilingGraph . EventSearch ( theSearch . query . id ( true ) , SearchEventType . FINALIZATION , " " + item , 0 , 0 ) , false ) ;
2014-02-05 03:45:02 +01:00
final String ext = MultiProtocolURL . getFileExtension ( resultFileName ) ;
2013-12-04 18:44:23 +01:00
if ( MultiProtocolURL . isImage ( ext ) ) {
2013-02-13 00:33:53 +01:00
final String license = URLLicense . aquireLicense ( resultURL ) ;
2010-12-01 19:48:21 +01:00
prop . put ( " content_code " , license ) ;
} else {
prop . put ( " content_code " , " " ) ;
}
2012-06-04 23:44:26 +02:00
if ( result . lat ( ) = = 0 . 0d | | result . lon ( ) = = 0 . 0d ) {
2011-03-31 01:26:36 +02:00
prop . put ( " content_loc " , 0 ) ;
} else {
prop . put ( " content_loc " , 1 ) ;
prop . put ( " content_loc_lat " , result . lat ( ) ) ;
prop . put ( " content_loc_lon " , result . lon ( ) ) ;
}
2013-06-11 14:42:30 +02:00
final boolean clustersearch = sb . isRobinsonMode ( ) & & sb . getConfig ( SwitchboardConstants . CLUSTER_MODE , " " ) . equals ( SwitchboardConstants . CLUSTER_MODE_PUBLIC_CLUSTER ) ;
2013-11-13 13:38:01 +01:00
final boolean indexReceiveGranted = sb . getConfigBool ( SwitchboardConstants . INDEX_RECEIVE_ALLOW_SEARCH , true ) | | clustersearch ;
2013-06-11 14:42:30 +02:00
boolean p2pmode = sb . peers ! = null & & sb . peers . sizeConnected ( ) > 0 & & indexReceiveGranted ;
2013-06-28 15:33:19 +02:00
boolean stealthmode = p2pmode & & theSearch . query . isLocal ( ) ;
2013-06-11 14:42:30 +02:00
if ( ( sb . getConfigBool ( SwitchboardConstants . HEURISTIC_SEARCHRESULTS , false ) | |
2013-12-04 22:44:51 +01:00
( sb . getConfigBool ( SwitchboardConstants . GREEDYLEARNING_ACTIVE , false ) & & sb . getConfigBool ( SwitchboardConstants . GREEDYLEARNING_ENABLED , false ) & & Memory . load ( ) < 1 . 0 ) ) & &
! stealthmode ) sb . heuristicSearchResults ( resultUrlstring ) ;
2012-11-05 03:19:28 +01:00
theSearch . query . transmitcount = item + 1 ;
2007-09-09 14:30:18 +02:00
return prop ;
2007-09-06 15:26:38 +02:00
}
2011-03-08 23:37:17 +01:00
2012-11-05 03:19:28 +01:00
if ( theSearch . query . contentdom = = Classification . ContentDomain . IMAGE ) {
2007-09-06 15:26:38 +02:00
// image search; shows thumbnails
2008-02-21 15:53:51 +01:00
2012-11-05 03:19:28 +01:00
prop . put ( " content " , theSearch . query . contentdom . getCode ( ) + 1 ) ; // switch on specific content
2013-09-02 18:55:38 +02:00
SearchEvent . ImageResult image = null ;
try {
image = theSearch . oneImageResult ( item , timeout ) ;
final String imageUrlstring = image . imageUrl . toNormalform ( true ) ;
final String target = sb . getConfig ( imageUrlstring . matches ( target_special_pattern ) ? SwitchboardConstants . SEARCH_TARGET_SPECIAL : SwitchboardConstants . SEARCH_TARGET_DEFAULT , " _self " ) ;
2012-01-26 15:32:30 +01:00
2013-09-02 18:55:38 +02:00
final String license = URLLicense . aquireLicense ( image . imageUrl ) ;
sb . loader . loadIfNotExistBackground ( image . imageUrl , 1024 * 1024 * 10 , null , ClientIdentification . yacyIntranetCrawlerAgent ) ;
prop . putHTML ( " content_item_hrefCache " , ( auth ) ? " /ViewImage.png?url= " + imageUrlstring : imageUrlstring ) ;
prop . putHTML ( " content_item_href " , imageUrlstring ) ;
2011-09-18 18:59:01 +02:00
prop . putHTML ( " content_item_target " , target ) ;
2010-12-01 19:48:21 +01:00
prop . put ( " content_item_code " , license ) ;
2013-09-02 18:55:38 +02:00
prop . putHTML ( " content_item_name " , shorten ( image . imagetext , MAX_NAME_LENGTH ) ) ;
prop . put ( " content_item_mimetype " , image . mimetype ) ;
2012-04-24 12:55:58 +02:00
prop . put ( " content_item_fileSize " , 0 ) ;
2013-09-02 18:55:38 +02:00
prop . put ( " content_item_width " , image . width ) ;
prop . put ( " content_item_height " , image . height ) ;
2012-04-24 12:55:58 +02:00
prop . put ( " content_item_attr " , " " /*(ms.attr.equals("-1 x -1")) ? "" : "(" + ms.attr + ")"*/ ) ; // attributes, here: original size of image
2013-09-02 18:55:38 +02:00
prop . put ( " content_item_urlhash " , ASCII . String ( image . imageUrl . hash ( ) ) ) ;
prop . put ( " content_item_source " , image . sourceUrl . toNormalform ( true ) ) ;
prop . putXML ( " content_item_source-xml " , image . sourceUrl . toNormalform ( true ) ) ;
prop . put ( " content_item_sourcedom " , image . sourceUrl . getHost ( ) ) ;
2012-11-05 03:19:28 +01:00
prop . put ( " content_item_nl " , ( item = = theSearch . query . offset ) ? 0 : 1 ) ;
2009-11-23 17:10:50 +01:00
prop . put ( " content_item " , 1 ) ;
2013-09-02 18:55:38 +02:00
} catch ( MalformedURLException e ) {
prop . put ( " content_item " , " 0 " ) ;
2007-09-07 13:45:38 +02:00
}
2012-11-05 03:19:28 +01:00
theSearch . query . transmitcount = item + 1 ;
2007-09-09 14:30:18 +02:00
return prop ;
2007-09-07 13:45:38 +02:00
}
2011-06-13 23:44:03 +02:00
2012-11-05 03:19:28 +01:00
if ( ( theSearch . query . contentdom = = ContentDomain . AUDIO ) | |
( theSearch . query . contentdom = = ContentDomain . VIDEO ) | |
( theSearch . query . contentdom = = ContentDomain . APP ) ) {
2007-09-07 13:45:38 +02:00
// any other media content
2008-02-21 15:53:51 +01:00
// generate result object
2013-03-19 11:23:18 +01:00
final ResultEntry ms = theSearch . oneResult ( item , timeout ) ;
2012-11-05 03:19:28 +01:00
prop . put ( " content " , theSearch . query . contentdom . getCode ( ) + 1 ) ; // switch on specific content
2012-04-27 14:18:02 +02:00
if ( ms = = null ) {
prop . put ( " content_item " , " 0 " ) ;
2007-09-07 13:45:38 +02:00
} else {
2012-10-10 11:46:22 +02:00
final String resultUrlstring = ms . url ( ) . toNormalform ( true ) ;
2012-04-27 14:18:02 +02:00
final String target = sb . getConfig ( resultUrlstring . matches ( target_special_pattern ) ? SwitchboardConstants . SEARCH_TARGET_SPECIAL : SwitchboardConstants . SEARCH_TARGET_DEFAULT , " _self " ) ;
prop . putHTML ( " content_item_href " , resultUrlstring ) ;
prop . putHTML ( " content_item_hrefshort " , nxTools . shortenURLString ( resultUrlstring , MAX_URL_LENGTH ) ) ;
prop . putHTML ( " content_item_target " , target ) ;
prop . putHTML ( " content_item_name " , shorten ( ms . title ( ) , MAX_NAME_LENGTH ) ) ;
prop . put ( " content_item_col " , ( item % 2 = = 0 ) ? " 0 " : " 1 " ) ;
2012-11-05 03:19:28 +01:00
prop . put ( " content_item_nl " , ( item = = theSearch . query . offset ) ? 0 : 1 ) ;
2012-04-27 14:18:02 +02:00
prop . put ( " content_item " , 1 ) ;
2007-09-06 15:26:38 +02:00
}
2012-11-05 03:19:28 +01:00
theSearch . query . transmitcount = item + 1 ;
2007-09-09 14:30:18 +02:00
return prop ;
2007-09-06 15:26:38 +02:00
}
2011-06-13 23:44:03 +02:00
2007-08-28 14:15:46 +02:00
return prop ;
}
2011-06-13 23:44:03 +02:00
2008-08-02 14:12:04 +02:00
private static String shorten ( final String s , final int length ) {
2011-03-08 23:37:17 +01:00
final String ret ;
if ( s . length ( ) < = length ) {
ret = s ;
} else {
final int p = s . lastIndexOf ( '.' ) ;
if ( p < 0 ) {
ret = s . substring ( 0 , length - SHORTEN_SUFFIX_LENGTH ) + SHORTEN_SUFFIX ;
} else {
assert p > = 0 ;
final String ext = s . substring ( p + 1 ) ;
if ( ext . length ( ) > 4 ) {
ret = s . substring ( 0 , length / 2 - 2 ) + SHORTEN_SUFFIX + s . substring ( s . length ( ) - ( length / 2 - 2 ) ) ;
} else {
ret = s . substring ( 0 , length - ext . length ( ) - SHORTEN_SUFFIX_LENGTH ) + SHORTEN_SUFFIX + ext ;
}
}
}
return ret ;
2007-09-07 13:45:38 +02:00
}
2007-08-28 14:15:46 +02:00
}