2005-10-05 15:14:18 +02:00
// search.java
2007-08-15 13:36:59 +02:00
// (C) 2004 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
2005-10-05 15:14:18 +02:00
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2005-04-07 21:19:42 +02:00
//
2007-08-15 13:36:59 +02:00
// LICENSE
//
2005-04-07 21:19:42 +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
2005-05-12 19:50:45 +02:00
// You must compile this file with
2005-04-07 21:19:42 +02:00
// javac -classpath .:../../Classes search.java
// if the shell's current path is htroot/yacy
2007-08-28 14:15:46 +02:00
import java.util.ArrayList ;
2006-09-06 19:51:28 +02:00
import java.util.Iterator ;
2006-09-11 00:36:47 +02:00
import java.util.Map ;
2007-09-08 13:50:19 +02:00
import java.util.Set ;
2007-01-15 02:50:57 +01:00
import java.util.TreeSet ;
2006-09-06 19:51:28 +02:00
2008-08-25 20:11:47 +02:00
import de.anomic.http.httpRequestHeader ;
2009-01-30 23:08:08 +01:00
import de.anomic.kelondro.order.Base64Order ;
import de.anomic.kelondro.order.Bitfield ;
2009-03-02 11:00:32 +01:00
import de.anomic.kelondro.text.ReferenceContainer ;
2009-01-30 23:44:20 +01:00
import de.anomic.kelondro.util.SortStack ;
2007-08-16 13:44:18 +02:00
import de.anomic.net.natLib ;
2007-12-04 21:19:13 +01:00
import de.anomic.plasma.plasmaProfiling ;
2007-08-28 14:15:46 +02:00
import de.anomic.plasma.plasmaSearchEvent ;
2006-09-30 00:27:20 +02:00
import de.anomic.plasma.plasmaSearchQuery ;
2006-02-05 00:51:00 +01:00
import de.anomic.plasma.plasmaSearchRankingProfile ;
2005-05-05 07:36:42 +02:00
import de.anomic.plasma.plasmaSwitchboard ;
2008-01-11 01:12:01 +01:00
import de.anomic.plasma.plasmaSearchEvent.ResultEntry ;
2006-01-20 16:14:21 +01:00
import de.anomic.server.serverCore ;
2005-05-05 07:36:42 +02:00
import de.anomic.server.serverObjects ;
2007-11-17 02:53:02 +01:00
import de.anomic.server.serverProfiling ;
2005-05-05 07:36:42 +02:00
import de.anomic.server.serverSwitch ;
2008-01-08 21:12:31 +01:00
import de.anomic.tools.crypt ;
2008-09-21 02:04:42 +02:00
import de.anomic.tools.iso639 ;
2008-04-26 03:00:10 +02:00
import de.anomic.xml.RSSFeed ;
import de.anomic.xml.RSSMessage ;
2005-05-05 07:36:42 +02:00
import de.anomic.yacy.yacyCore ;
2007-07-05 01:48:52 +02:00
import de.anomic.yacy.yacyNetwork ;
2005-05-05 07:36:42 +02:00
import de.anomic.yacy.yacySeed ;
2008-03-11 12:09:38 +01:00
import de.anomic.yacy.yacyURL ;
2005-04-07 21:19:42 +02:00
2005-10-05 12:45:33 +02:00
public final class search {
2005-04-07 21:19:42 +02:00
2008-08-25 20:11:47 +02:00
public static serverObjects respond ( final httpRequestHeader header , final serverObjects post , final serverSwitch < ? > env ) {
2005-10-05 15:14:18 +02:00
// return variable that accumulates replacements
2008-03-12 01:05:18 +01:00
final plasmaSwitchboard sb = ( plasmaSwitchboard ) env ;
sb . remoteSearchLastAccess = System . currentTimeMillis ( ) ;
2008-08-02 14:12:04 +02:00
final serverObjects prop = new serverObjects ( ) ;
2008-03-12 01:05:18 +01:00
if ( ( post = = null ) | | ( env = = null ) ) return prop ;
if ( ! yacyNetwork . authentifyRequest ( post , env ) ) return prop ;
2008-08-25 20:11:47 +02:00
final String client = header . get ( httpRequestHeader . CONNECTION_PROP_CLIENTIP ) ;
2005-04-07 21:19:42 +02:00
2008-03-12 01:05:18 +01:00
//System.out.println("yacy: search received request = " + post.toString());
final String oseed = post . get ( " myseed " , " " ) ; // complete seed of the requesting peer
// final String youare = post.get("youare", ""); // seed hash of the target peer, used for testing network stability
final String key = post . get ( " key " , " " ) ; // transmission key for response
final String query = post . get ( " query " , " " ) ; // a string of word hashes that shall be searched and combined
final String exclude = post . get ( " exclude " , " " ) ; // a string of word hashes that shall not be within the search result
2008-08-02 14:12:04 +02:00
final String urls = post . get ( " urls " , " " ) ; // a string of url hashes that are preselected for the search: no other may be returned
final String abstracts = post . get ( " abstracts " , " " ) ; // a string of word hashes for abstracts that shall be generated, or 'auto' (for maxcount-word), or '' (for none)
2008-03-12 01:05:18 +01:00
// final String fwdep = post.get("fwdep", ""); // forward depth. if "0" then peer may NOT ask another peer for more results
// final String fwden = post.get("fwden", ""); // forward deny, a list of seed hashes. They may NOT be target of forward hopping
final int count = Math . min ( 100 , post . getInt ( " count " , 10 ) ) ; // maximum number of wanted results
final int maxdist = post . getInt ( " maxdist " , Integer . MAX_VALUE ) ;
final String prefer = post . get ( " prefer " , " " ) ;
final String contentdom = post . get ( " contentdom " , " text " ) ;
final String filter = post . get ( " filter " , " .* " ) ;
2008-09-21 02:04:42 +02:00
String language = post . get ( " language " , " " ) ;
if ( ! iso639 . exists ( language ) ) {
// take language from the user agent
String agent = header . get ( " User-Agent " ) ;
if ( agent = = null ) agent = System . getProperty ( " user.language " ) ;
language = ( agent = = null ) ? " en " : iso639 . userAgentLanguageDetection ( agent ) ;
2008-10-01 22:20:39 +02:00
if ( language = = null ) language = " en " ;
2008-09-21 02:04:42 +02:00
}
2008-03-12 01:05:18 +01:00
final int partitions = post . getInt ( " partitions " , 30 ) ;
String profile = post . get ( " profile " , " " ) ; // remote profile hand-over
if ( profile . length ( ) > 0 ) profile = crypt . simpleDecode ( profile , null ) ;
//final boolean includesnippet = post.get("includesnippet", "false").equals("true");
2009-01-30 16:33:00 +01:00
Bitfield constraint = ( ( post . containsKey ( " constraint " ) ) & & ( post . get ( " constraint " , " " ) . length ( ) > 0 ) ) ? new Bitfield ( 4 , post . get ( " constraint " , " ______ " ) ) : null ;
2008-03-12 01:05:18 +01:00
if ( constraint ! = null ) {
// check bad handover parameter from older versions
boolean allon = true ;
for ( int i = 0 ; i < 32 ; i + + ) {
if ( ! constraint . get ( i ) ) { allon = false ; break ; }
}
if ( allon ) constraint = null ;
2008-02-05 17:32:10 +01:00
}
2008-03-12 01:05:18 +01:00
// final boolean global = ((String) post.get("resource", "global")).equals("global"); // if true, then result may consist of answers from other peers
// Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time
2006-10-10 14:22:16 +02:00
// test:
// http://localhost:8080/yacy/search.html?query=4galTpdpDM5Q (search for linux)
// http://localhost:8080/yacy/search.html?query=gh8DKIhGKXws (search for book)
2007-09-07 13:45:38 +02:00
// http://localhost:8080/yacy/search.html?query=UEhMGfGv2vOE (search for kernel)
// http://localhost:8080/yacy/search.html?query=ZX-LjaYo74PP (search for help)
// http://localhost:8080/yacy/search.html?query=uDqIalxDfM2a (search for mail)
2006-10-10 14:22:16 +02:00
// http://localhost:8080/yacy/search.html?query=4galTpdpDM5Qgh8DKIhGKXws&abstracts=auto (search for linux and book, generate abstract automatically)
// http://localhost:8080/yacy/search.html?query=&abstracts=4galTpdpDM5Q (only abstracts for linux)
2007-07-05 01:48:52 +02:00
2008-03-12 01:05:18 +01:00
if ( ( sb . isRobinsonMode ( ) ) & &
( ! ( ( sb . isPublicRobinson ( ) ) | |
2008-08-25 20:11:47 +02:00
( sb . isInMyCluster ( header . get ( httpRequestHeader . CONNECTION_PROP_CLIENTIP ) ) ) ) ) ) {
2008-03-12 01:05:18 +01:00
// if we are a robinson cluster, answer only if this client is known by our network definition
prop . put ( " links " , " " ) ;
prop . put ( " linkcount " , " 0 " ) ;
prop . put ( " references " , " " ) ;
return prop ;
2007-04-24 17:11:12 +02:00
}
2008-03-12 01:05:18 +01:00
2008-05-17 02:11:35 +02:00
// check the search tracker
TreeSet < Long > trackerHandles = sb . remoteSearchTracker . get ( client ) ;
if ( trackerHandles = = null ) trackerHandles = new TreeSet < Long > ( ) ;
boolean block = false ;
2008-10-03 21:44:42 +02:00
if ( trackerHandles . tailSet ( Long . valueOf ( System . currentTimeMillis ( ) - 3000 ) ) . size ( ) > 1 ) {
2008-05-17 02:11:35 +02:00
block = true ;
2008-10-03 21:44:42 +02:00
}
if ( trackerHandles . tailSet ( Long . valueOf ( System . currentTimeMillis ( ) - 60000 ) ) . size ( ) > 12 ) {
2008-05-17 02:11:35 +02:00
block = true ;
2008-10-03 21:44:42 +02:00
}
if ( trackerHandles . tailSet ( Long . valueOf ( System . currentTimeMillis ( ) - 600000 ) ) . size ( ) > 36 ) {
2008-05-17 02:11:35 +02:00
block = true ;
2008-10-03 21:44:42 +02:00
}
2008-05-17 02:11:35 +02:00
if ( block ) {
prop . put ( " links " , " " ) ;
prop . put ( " linkcount " , " 0 " ) ;
prop . put ( " references " , " " ) ;
return prop ;
}
2006-01-20 16:14:21 +01:00
// tell all threads to do nothing for a specific time
2008-02-03 00:53:39 +01:00
sb . intermissionAllThreads ( 3000 ) ;
2006-01-20 16:14:21 +01:00
2008-08-02 14:12:04 +02:00
final TreeSet < String > abstractSet = ( ( abstracts . length ( ) = = 0 ) | | ( abstracts . equals ( " auto " ) ) ) ? null : plasmaSearchQuery . hashes2Set ( abstracts ) ;
2008-03-12 01:05:18 +01:00
2006-01-20 16:14:21 +01:00
// store accessing peer
2008-08-02 14:12:04 +02:00
final yacySeed remoteSeed = yacySeed . genRemoteSeed ( oseed , key , false ) ;
2009-03-13 11:34:51 +01:00
if ( sb . webIndex . peers ( ) = = null ) {
2005-08-30 23:32:59 +02:00
yacyCore . log . logSevere ( " yacy.search: seed cache not initialized " ) ;
2005-04-07 21:19:42 +02:00
} else {
2009-03-13 11:34:51 +01:00
sb . webIndex . peers ( ) . peerActions . peerArrival ( remoteSeed , true ) ;
2008-02-06 20:00:18 +01:00
}
2006-01-20 16:14:21 +01:00
// prepare search
2008-01-11 01:12:01 +01:00
final TreeSet < String > queryhashes = plasmaSearchQuery . hashes2Set ( query ) ;
2009-01-30 16:33:00 +01:00
final TreeSet < String > excludehashes = ( exclude . length ( ) = = 0 ) ? new TreeSet < String > ( Base64Order . enhancedComparator ) : plasmaSearchQuery . hashes2Set ( exclude ) ;
2005-10-05 15:14:18 +02:00
final long timestamp = System . currentTimeMillis ( ) ;
2008-03-12 01:05:18 +01:00
// prepare a search profile
2008-08-02 14:12:04 +02:00
final plasmaSearchRankingProfile rankingProfile = ( profile . length ( ) = = 0 ) ? new plasmaSearchRankingProfile ( plasmaSearchQuery . contentdomParser ( contentdom ) ) : new plasmaSearchRankingProfile ( " " , profile ) ;
2008-03-12 01:05:18 +01:00
2006-10-10 14:22:16 +02:00
// prepare an abstract result
2008-12-04 13:54:16 +01:00
final StringBuilder indexabstract = new StringBuilder ( ) ;
2007-07-31 12:00:17 +02:00
int indexabstractContainercount = 0 ;
2006-09-14 00:19:34 +02:00
int joincount = 0 ;
2007-08-28 14:15:46 +02:00
plasmaSearchQuery theQuery = null ;
2009-01-30 23:44:20 +01:00
ArrayList < SortStack < ResultEntry > . stackElement > accu = null ;
2008-02-18 00:35:48 +01:00
plasmaSearchEvent theSearch = null ;
2006-10-10 14:22:16 +02:00
if ( ( query . length ( ) = = 0 ) & & ( abstractSet ! = null ) ) {
// this is _not_ a normal search, only a request for index abstracts
2009-01-30 16:33:00 +01:00
theQuery = new plasmaSearchQuery ( null , abstractSet , new TreeSet < String > ( Base64Order . enhancedComparator ) , null , rankingProfile , maxdist , prefer , plasmaSearchQuery . contentdomParser ( contentdom ) , language , false , count , 0 , filter , plasmaSearchQuery . SEARCHDOM_LOCAL , null , - 1 , null , false , yacyURL . TLD_any_zone_filter , client , false ) ;
2007-08-28 14:15:46 +02:00
theQuery . domType = plasmaSearchQuery . SEARCHDOM_LOCAL ;
2007-09-04 01:43:55 +02:00
yacyCore . log . logInfo ( " INIT HASH SEARCH (abstracts only): " + plasmaSearchQuery . anonymizedQueryHashes ( theQuery . queryHashes ) + " - " + theQuery . displayResults ( ) + " links " ) ;
2006-10-10 14:22:16 +02:00
2008-08-02 14:12:04 +02:00
final long timer = System . currentTimeMillis ( ) ;
2009-03-16 17:24:53 +01:00
final Map < String , ReferenceContainer > [ ] containers = sb . webIndex . localSearchContainers ( theQuery . queryHashes , theQuery . excludeHashes , plasmaSearchQuery . hashes2Set ( urls ) ) ;
2009-03-02 09:48:27 +01:00
2009-03-13 01:13:47 +01:00
serverProfiling . update ( " SEARCH " , new plasmaProfiling . searchEvent ( theQuery . id ( true ) , plasmaSearchEvent . COLLECTION , containers [ 0 ] . size ( ) , System . currentTimeMillis ( ) - timer ) , false ) ;
2006-10-10 14:22:16 +02:00
if ( containers ! = null ) {
2009-03-02 00:58:14 +01:00
final Iterator < Map . Entry < String , ReferenceContainer > > ci = containers [ 0 ] . entrySet ( ) . iterator ( ) ;
Map . Entry < String , ReferenceContainer > entry ;
2006-10-10 14:22:16 +02:00
String wordhash ;
while ( ci . hasNext ( ) ) {
2008-01-11 01:12:01 +01:00
entry = ci . next ( ) ;
wordhash = entry . getKey ( ) ;
2009-03-02 00:58:14 +01:00
final ReferenceContainer container = entry . getValue ( ) ;
2007-07-31 12:00:17 +02:00
indexabstractContainercount + = container . size ( ) ;
2009-03-02 00:58:14 +01:00
indexabstract . append ( " indexabstract. " + wordhash + " = " ) . append ( ReferenceContainer . compressIndex ( container , null , 1000 ) . toString ( ) ) . append ( serverCore . CRLF_STRING ) ;
2006-09-12 02:42:42 +02:00
}
2006-09-06 19:51:28 +02:00
}
2008-03-12 01:05:18 +01:00
2007-10-24 23:38:19 +02:00
prop . put ( " indexcount " , " " ) ;
prop . put ( " joincount " , " 0 " ) ;
prop . put ( " references " , " " ) ;
2008-03-12 01:05:18 +01:00
2006-10-10 14:22:16 +02:00
} else {
// retrieve index containers from search request
2008-11-26 20:43:40 +01:00
theQuery = new plasmaSearchQuery ( null , queryhashes , excludehashes , null , rankingProfile , maxdist , prefer , plasmaSearchQuery . contentdomParser ( contentdom ) , language , false , count , 0 , filter , plasmaSearchQuery . SEARCHDOM_LOCAL , null , - 1 , constraint , false , yacyURL . TLD_any_zone_filter , client , false ) ;
2007-08-28 14:15:46 +02:00
theQuery . domType = plasmaSearchQuery . SEARCHDOM_LOCAL ;
2007-09-04 01:43:55 +02:00
yacyCore . log . logInfo ( " INIT HASH SEARCH (query- " + abstracts + " ): " + plasmaSearchQuery . anonymizedQueryHashes ( theQuery . queryHashes ) + " - " + theQuery . displayResults ( ) + " links " ) ;
2008-06-05 15:08:40 +02:00
RSSFeed . channels ( RSSFeed . REMOTESEARCH ) . addMessage ( new RSSMessage ( " Remote Search Request from " + ( ( remoteSeed = = null ) ? " unknown " : remoteSeed . getName ( ) ) , plasmaSearchQuery . anonymizedQueryHashes ( theQuery . queryHashes ) , " " ) ) ;
2008-03-12 01:05:18 +01:00
2008-01-08 21:12:31 +01:00
// make event
2008-05-14 23:36:02 +02:00
theSearch = plasmaSearchEvent . getEvent ( theQuery , rankingProfile , sb . webIndex , sb . crawlResults , null , true ) ;
2008-03-12 01:05:18 +01:00
2006-10-10 14:22:16 +02:00
// set statistic details of search result and find best result index set
2008-01-30 22:58:30 +01:00
if ( theSearch . getRankingResult ( ) . getLocalResourceSize ( ) = = 0 ) {
2007-10-24 23:38:19 +02:00
prop . put ( " indexcount " , " " ) ;
prop . put ( " joincount " , " 0 " ) ;
2006-09-14 00:19:34 +02:00
} else {
2007-08-28 14:15:46 +02:00
// attach information about index abstracts
2008-12-04 13:54:16 +01:00
final StringBuilder indexcount = new StringBuilder ( ) ;
2008-01-11 01:12:01 +01:00
Map . Entry < String , Integer > entry ;
2008-08-02 14:12:04 +02:00
final Iterator < Map . Entry < String , Integer > > i = theSearch . IACount . entrySet ( ) . iterator ( ) ;
2007-08-28 14:15:46 +02:00
while ( i . hasNext ( ) ) {
2008-01-11 01:12:01 +01:00
entry = i . next ( ) ;
2008-06-06 18:01:27 +02:00
indexcount . append ( " indexcount. " ) . append ( entry . getKey ( ) ) . append ( '=' ) . append ( ( entry . getValue ( ) ) . toString ( ) ) . append ( serverCore . CRLF_STRING ) ;
2007-08-28 14:15:46 +02:00
}
if ( abstractSet ! = null ) {
// if a specific index-abstract is demanded, attach it here
2008-08-02 14:12:04 +02:00
final Iterator < String > j = abstractSet . iterator ( ) ;
2007-08-28 14:15:46 +02:00
String wordhash ;
2008-01-11 01:12:01 +01:00
while ( j . hasNext ( ) ) {
2008-06-06 18:01:27 +02:00
wordhash = j . next ( ) ;
indexabstractContainercount + = ( theSearch . IACount . get ( wordhash ) ) . intValue ( ) ;
indexabstract . append ( " indexabstract. " + wordhash + " = " ) . append ( theSearch . IAResults . get ( wordhash ) ) . append ( serverCore . CRLF_STRING ) ;
2006-10-10 14:22:16 +02:00
}
}
2007-10-24 23:38:19 +02:00
prop . put ( " indexcount " , indexcount . toString ( ) ) ;
2008-03-12 01:05:18 +01:00
2008-01-30 22:58:30 +01:00
if ( theSearch . getRankingResult ( ) . getLocalResourceSize ( ) = = 0 ) {
2006-11-05 03:10:40 +01:00
joincount = 0 ;
2007-10-24 23:38:19 +02:00
prop . put ( " joincount " , " 0 " ) ;
2006-11-05 03:10:40 +01:00
} else {
2008-01-30 22:58:30 +01:00
joincount = theSearch . getRankingResult ( ) . getLocalResourceSize ( ) ;
2007-10-24 23:38:19 +02:00
prop . put ( " joincount " , Integer . toString ( joincount ) ) ;
2008-02-03 00:53:39 +01:00
accu = theSearch . completeResults ( 3000 ) ;
2006-11-05 03:10:40 +01:00
}
2008-03-12 01:05:18 +01:00
2006-10-10 14:22:16 +02:00
// generate compressed index for maxcounthash
// this is not needed if the search is restricted to specific
// urls, because it is a re-search
2007-09-05 11:01:35 +02:00
if ( ( theSearch . IAmaxcounthash = = null ) | | ( urls . length ( ) ! = 0 ) | | ( queryhashes . size ( ) < = 1 ) | | ( abstracts . length ( ) = = 0 ) ) {
2007-10-24 23:38:19 +02:00
prop . put ( " indexabstract " , " " ) ;
2006-10-10 14:22:16 +02:00
} else if ( abstracts . equals ( " auto " ) ) {
2007-07-31 12:00:17 +02:00
// automatically attach the index abstract for the index that has the most references. This should be our target dht position
2008-06-06 18:01:27 +02:00
indexabstractContainercount + = ( theSearch . IACount . get ( theSearch . IAmaxcounthash ) ) . intValue ( ) ;
indexabstract . append ( " indexabstract. " + theSearch . IAmaxcounthash + " = " ) . append ( theSearch . IAResults . get ( theSearch . IAmaxcounthash ) ) . append ( serverCore . CRLF_STRING ) ;
2007-08-28 14:15:46 +02:00
if ( ( theSearch . IAneardhthash ! = null ) & & ( ! ( theSearch . IAneardhthash . equals ( theSearch . IAmaxcounthash ) ) ) ) {
2007-07-31 12:00:17 +02:00
// in case that the neardhthash is different from the maxcounthash attach also the neardhthash-container
2008-06-06 18:01:27 +02:00
indexabstractContainercount + = ( theSearch . IACount . get ( theSearch . IAneardhthash ) ) . intValue ( ) ;
indexabstract . append ( " indexabstract. " + theSearch . IAneardhthash + " = " ) . append ( theSearch . IAResults . get ( theSearch . IAneardhthash ) ) . append ( serverCore . CRLF_STRING ) ;
2006-10-10 14:22:16 +02:00
}
//System.out.println("DEBUG-ABSTRACTGENERATION: maxcounthash = " + maxcounthash);
//System.out.println("DEBUG-ABSTRACTGENERATION: neardhthash = "+ neardhthash);
//yacyCore.log.logFine("DEBUG HASH SEARCH: " + indexabstract);
2006-09-14 00:19:34 +02:00
}
2006-09-12 02:42:42 +02:00
}
2007-10-19 06:13:46 +02:00
if ( partitions > 0 ) sb . requestedQueries = sb . requestedQueries + 1d / partitions ; // increase query counter
2008-03-12 01:05:18 +01:00
2007-08-28 14:15:46 +02:00
// prepare reference hints
2008-08-02 14:12:04 +02:00
final long timer = System . currentTimeMillis ( ) ;
final Set < String > ws = theSearch . references ( 10 ) ;
2008-12-04 13:54:16 +01:00
final StringBuilder refstr = new StringBuilder ( ) ;
2008-08-02 14:12:04 +02:00
final Iterator < String > j = ws . iterator ( ) ;
2007-09-08 13:50:19 +02:00
while ( j . hasNext ( ) ) {
2008-06-06 18:01:27 +02:00
refstr . append ( " , " ) . append ( j . next ( ) ) ;
2007-09-08 13:50:19 +02:00
}
2007-10-24 23:38:19 +02:00
prop . put ( " references " , ( refstr . length ( ) > 0 ) ? refstr . substring ( 1 ) : refstr . toString ( ) ) ;
2009-03-13 01:13:47 +01:00
serverProfiling . update ( " SEARCH " , new plasmaProfiling . searchEvent ( theQuery . id ( true ) , " reference collection " , ws . size ( ) , System . currentTimeMillis ( ) - timer ) , false ) ;
2006-09-11 00:36:47 +02:00
}
2007-10-24 23:38:19 +02:00
prop . put ( " indexabstract " , indexabstract . toString ( ) ) ;
2008-03-12 01:05:18 +01:00
2008-02-06 20:00:18 +01:00
// prepare result
2008-03-12 01:05:18 +01:00
if ( ( joincount = = 0 ) | | ( accu = = null ) ) {
// no results
prop . put ( " links " , " " ) ;
prop . put ( " linkcount " , " 0 " ) ;
prop . put ( " references " , " " ) ;
} else {
2006-09-06 19:51:28 +02:00
// result is a List of urlEntry elements
2008-08-02 14:12:04 +02:00
final long timer = System . currentTimeMillis ( ) ;
2008-12-04 13:54:16 +01:00
final StringBuilder links = new StringBuilder ( ) ;
2006-12-11 02:31:23 +01:00
String resource = null ;
2009-01-30 23:44:20 +01:00
SortStack < plasmaSearchEvent . ResultEntry > . stackElement entry ;
2007-08-28 14:15:46 +02:00
for ( int i = 0 ; i < accu . size ( ) ; i + + ) {
2008-02-21 11:06:57 +01:00
entry = accu . get ( i ) ;
resource = entry . element . resource ( ) ;
2006-12-11 02:31:23 +01:00
if ( resource ! = null ) {
2007-12-14 20:17:54 +01:00
links . append ( " resource " ) . append ( i ) . append ( '=' ) . append ( resource ) . append ( serverCore . CRLF_STRING ) ;
2006-01-20 16:14:21 +01:00
}
}
2007-10-24 23:38:19 +02:00
prop . put ( " links " , links . toString ( ) ) ;
2007-08-28 14:15:46 +02:00
prop . put ( " linkcount " , accu . size ( ) ) ;
2009-03-13 01:13:47 +01:00
serverProfiling . update ( " SEARCH " , new plasmaProfiling . searchEvent ( theQuery . id ( true ) , " result list preparation " , accu . size ( ) , System . currentTimeMillis ( ) - timer ) , false ) ;
2006-01-20 16:14:21 +01:00
}
2008-03-12 01:05:18 +01:00
2006-09-06 19:51:28 +02:00
// add information about forward peers
2007-10-24 23:38:19 +02:00
prop . put ( " fwhop " , " " ) ; // hops (depth) of forwards that had been performed to construct this result
prop . put ( " fwsrc " , " " ) ; // peers that helped to construct this result
prop . put ( " fwrec " , " " ) ; // peers that would have helped to construct this result (recommendations)
2007-09-04 11:04:47 +02:00
// prepare search statistics
2009-03-13 11:34:51 +01:00
theQuery . remotepeer = sb . webIndex . peers ( ) . lookupByIP ( natLib . getInetAddress ( client ) , true , false , false ) ;
2008-02-18 00:35:48 +01:00
theQuery . resultcount = ( theSearch = = null ) ? 0 : theSearch . getRankingResult ( ) . getLocalResourceSize ( ) + theSearch . getRankingResult ( ) . getRemoteResourceSize ( ) ;
theQuery . searchtime = System . currentTimeMillis ( ) - timestamp ;
theQuery . urlretrievaltime = ( theSearch = = null ) ? 0 : theSearch . getURLRetrievalTime ( ) ;
theQuery . snippetcomputationtime = ( theSearch = = null ) ? 0 : theSearch . getSnippetComputationTime ( ) ;
sb . remoteSearches . add ( theQuery ) ;
2008-05-17 02:11:35 +02:00
// update the search tracker
trackerHandles . add ( theQuery . handle ) ;
sb . remoteSearchTracker . put ( client , trackerHandles ) ;
2008-03-12 01:05:18 +01:00
2006-01-20 16:14:21 +01:00
// log
2007-07-31 12:00:17 +02:00
yacyCore . log . logInfo ( " EXIT HASH SEARCH: " +
2007-08-28 14:15:46 +02:00
plasmaSearchQuery . anonymizedQueryHashes ( theQuery . queryHashes ) + " - " + joincount + " links found, " +
2007-07-31 12:00:17 +02:00
prop . get ( " linkcount " , " ? " ) + " links selected, " +
2007-09-05 11:01:35 +02:00
indexabstractContainercount + " index abstracts, " +
2007-07-31 12:00:17 +02:00
( System . currentTimeMillis ( ) - timestamp ) + " milliseconds " ) ;
2008-03-12 01:05:18 +01:00
2007-10-24 23:38:19 +02:00
prop . put ( " searchtime " , System . currentTimeMillis ( ) - timestamp ) ;
2005-10-05 15:14:18 +02:00
2008-03-12 01:05:18 +01:00
final int links = Integer . parseInt ( prop . get ( " linkcount " , " 0 " ) ) ;
2009-03-13 11:34:51 +01:00
sb . webIndex . peers ( ) . mySeed ( ) . incSI ( links ) ;
sb . webIndex . peers ( ) . mySeed ( ) . incSU ( links ) ;
2005-10-07 17:04:03 +02:00
return prop ;
2005-04-07 21:19:42 +02:00
}
2008-03-12 01:05:18 +01:00
2007-01-16 15:07:54 +01:00
}