@ -368,7 +368,7 @@ public final class yacyClient {
}
}
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
public static String [ ] search (
public static int search (
final yacySeed mySeed ,
final yacySeed mySeed ,
final String wordhashes ,
final String wordhashes ,
final String excludehashes ,
final String excludehashes ,
@ -392,7 +392,6 @@ public final class yacyClient {
final Bitfield constraint
final Bitfield constraint
) {
) {
// send a search request to peer with remote Hash
// send a search request to peer with remote Hash
// this mainly converts the words into word hashes
// INPUT:
// INPUT:
// iam : complete seed of the requesting peer
// iam : complete seed of the requesting peer
@ -437,7 +436,7 @@ public final class yacyClient {
} catch ( final IOException e ) {
} catch ( final IOException e ) {
yacyCore . log . logInfo ( "SEARCH failed, Peer: " + target . hash + ":" + target . getName ( ) + " (" + e . getMessage ( ) + "), score=" + target . selectscore ) ;
yacyCore . log . logInfo ( "SEARCH failed, Peer: " + target . hash + ":" + target . getName ( ) + " (" + e . getMessage ( ) + "), score=" + target . selectscore ) ;
//yacyCore.peerActions.peerDeparture(target, "search request to peer created io exception: " + e.getMessage());
//yacyCore.peerActions.peerDeparture(target, "search request to peer created io exception: " + e.getMessage());
return null ;
return - 1 ;
}
}
if ( result = = null | | result . isEmpty ( ) ) {
if ( result = = null | | result . isEmpty ( ) ) {
@ -447,7 +446,7 @@ public final class yacyClient {
+ target . getName ( )
+ target . getName ( )
+ " (zero response), score="
+ " (zero response), score="
+ target . selectscore ) ;
+ target . selectscore ) ;
return null ;
return - 1 ;
}
}
// compute all computation times
// compute all computation times
@ -468,14 +467,14 @@ public final class yacyClient {
// now create a plasmaIndex out of this result
// now create a plasmaIndex out of this result
// System.out.println("yacyClient: " + ((urlhashes.length() == 0) ? "primary" : "secondary")+ " search result = " + result.toString()); // debug
// System.out.println("yacyClient: " + ((urlhashes.length() == 0) ? "primary" : "secondary")+ " search result = " + result.toString()); // debug
int results = 0 , joincount = 0 ;
int urlcount = 0 , joincount = 0 ;
try {
try {
results = Integer . parseInt ( result . get ( " count") ) ;
joincount = Integer . parseInt ( result . get ( " join count") ) ; // the complete number of hits at remote site
join count = Integer . parseInt ( result . get ( " join count") ) ;
url count = Integer . parseInt ( result . get ( " count") ) ; // the number of hits that are returned in the result list
} catch ( final NumberFormatException e ) {
} catch ( final NumberFormatException e ) {
yacyCore . log . logInfo ( "SEARCH failed FROM " + target . hash + ":" + target . getName ( ) + ", wrong output format: " + e . getMessage ( ) ) ;
yacyCore . log . logInfo ( "SEARCH failed FROM " + target . hash + ":" + target . getName ( ) + ", wrong output format: " + e . getMessage ( ) ) ;
//yacyCore.peerActions.peerDeparture(target, "search request to peer created number format exception");
//yacyCore.peerActions.peerDeparture(target, "search request to peer created number format exception");
return null ;
return - 1 ;
}
}
// System.out.println("***result count " + results);
// System.out.println("***result count " + results);
@ -488,14 +487,13 @@ public final class yacyClient {
container [ i ] = ReferenceContainer . emptyContainer ( Segment . wordReferenceFactory , wordhashes . substring ( i * Word . commonHashLength , ( i + 1 ) * Word . commonHashLength ) . getBytes ( ) , count ) ;
container [ i ] = ReferenceContainer . emptyContainer ( Segment . wordReferenceFactory , wordhashes . substring ( i * Word . commonHashLength , ( i + 1 ) * Word . commonHashLength ) . getBytes ( ) , count ) ;
} catch ( RowSpaceExceededException e ) {
} catch ( RowSpaceExceededException e ) {
Log . logException ( e ) ;
Log . logException ( e ) ;
return null ;
return - 1 ;
}
}
}
}
// insert results to containers
// insert results to containers
URIMetadataRow urlEntry ;
URIMetadataRow urlEntry ;
final String [ ] urls = new String [ results ] ;
for ( int n = 0 ; n < urlcount ; n + + ) {
for ( int n = 0 ; n < results ; n + + ) {
// get one single search result
// get one single search result
urlEntry = URIMetadataRow . importEntry ( result . get ( "resource" + n ) ) ;
urlEntry = URIMetadataRow . importEntry ( result . get ( "resource" + n ) ) ;
if ( urlEntry = = null ) continue ;
if ( urlEntry = = null ) continue ;
@ -504,27 +502,26 @@ public final class yacyClient {
final URIMetadataRow . Components metadata = urlEntry . metadata ( ) ;
final URIMetadataRow . Components metadata = urlEntry . metadata ( ) ;
if ( metadata = = null ) continue ;
if ( metadata = = null ) continue ;
if ( blacklist . isListed ( Blacklist . BLACKLIST_SEARCH , metadata . url ( ) ) ) {
if ( blacklist . isListed ( Blacklist . BLACKLIST_SEARCH , metadata . url ( ) ) ) {
if ( yacyCore . log . isInfo ( ) ) yacyCore . log . logInfo ( "remote search (client) : filtered blacklisted url " + metadata . url ( ) + " from peer " + target . getName ( ) ) ;
if ( yacyCore . log . isInfo ( ) ) yacyCore . log . logInfo ( "remote search : filtered blacklisted url " + metadata . url ( ) + " from peer " + target . getName ( ) ) ;
continue ; // block with backlist
continue ; // block with backlist
}
}
final String urlRejectReason = Switchboard . getSwitchboard ( ) . crawlStacker . urlInAcceptedDomain ( metadata . url ( ) ) ;
final String urlRejectReason = Switchboard . getSwitchboard ( ) . crawlStacker . urlInAcceptedDomain ( metadata . url ( ) ) ;
if ( urlRejectReason ! = null ) {
if ( urlRejectReason ! = null ) {
if ( yacyCore . log . isInfo ( ) ) yacyCore . log . logInfo ( "remote search (client) : rejected url '" + metadata . url ( ) + "' (" + urlRejectReason + ") from peer " + target . getName ( ) ) ;
if ( yacyCore . log . isInfo ( ) ) yacyCore . log . logInfo ( "remote search : rejected url '" + metadata . url ( ) + "' (" + urlRejectReason + ") from peer " + target . getName ( ) ) ;
continue ; // reject url outside of our domain
continue ; // reject url outside of our domain
}
}
// save the url entry
// save the url entry
Reference entry ;
Reference entry = urlEntry . word ( ) ;
if ( urlEntry. word ( ) = = null ) {
if ( entry = = null ) {
if ( yacyCore . log . isWarning ( ) ) yacyCore . log . logWarning ( "remote search (client) : no word attached from peer " + target . getName ( ) + ", version " + target . getVersion ( ) ) ;
if ( yacyCore . log . isWarning ( ) ) yacyCore . log . logWarning ( "remote search : no word attached from peer " + target . getName ( ) + ", version " + target . getVersion ( ) ) ;
continue ; // no word attached
continue ; // no word attached
}
}
// the search-result-url transports all the attributes of word indexes
// the search-result-url transports all the attributes of word indexes
entry = urlEntry . word ( ) ;
if ( ! Base64Order . enhancedCoder . equal ( entry . metadataHash ( ) , urlEntry . hash ( ) ) ) {
if ( ! Base64Order . enhancedCoder . equal ( entry . metadataHash ( ) , urlEntry . hash ( ) ) ) {
if ( yacyCore . log . isInfo ( ) ) yacyCore . log . logInfo ( "remote search (client) : url-hash " + new String ( urlEntry . hash ( ) ) + " does not belong to word-attached-hash " + new String ( entry . metadataHash ( ) ) + "; url = " + metadata . url ( ) + " from peer " + target . getName ( ) ) ;
yacyCore . log . logInfo ( "remote search : url-hash " + new String ( urlEntry . hash ( ) ) + " does not belong to word-attached-hash " + new String ( entry . metadataHash ( ) ) + "; url = " + metadata . url ( ) + " from peer " + target . getName ( ) ) ;
continue ; // spammed
continue ; // spammed
}
}
@ -554,23 +551,30 @@ public final class yacyClient {
break ;
break ;
}
}
}
}
// store url hash for statistics
urls [ n ] = new String ( urlEntry . hash ( ) ) ;
}
}
// store remote result to local result container
// store remote result to local result container
synchronized ( containerCache ) {
synchronized ( containerCache ) {
// insert one container into the search result buffer
// insert one container into the search result buffer
containerCache . add ( container [ 0 ] , false , joincount ) ; // one is enough
containerCache . add ( container [ 0 ] , false , joincount ) ; // one is enough, only the references are used, not the word
}
// integrate remote topwords
// insert the containers to the index
final String references = result . get ( "references" ) ;
for ( ReferenceContainer < WordReference > c : container ) try {
yacyCore . log . logInfo ( "remote search (client): peer " + target . getName ( ) + " sent references " + references ) ;
indexSegment . termIndex ( ) . add ( c ) ;
if ( references ! = null ) {
} catch ( Exception e ) {
// add references twice, so they can be counted (must have at least 2 entries)
Log . logException ( e ) ;
containerCache . addTopic ( references . split ( "," ) ) ;
}
containerCache . addTopic ( references . split ( "," ) ) ;
yacyCore . log . logInfo ( "remote search: peer " + target . getName ( ) + " sent " + container [ 0 ] . size ( ) + "/" + joincount + " references for joined word queries" ) ;
// integrate remote top-words/topics
final String references = result . get ( "references" ) ;
if ( references ! = null & & references . length ( ) > 0 ) {
yacyCore . log . logInfo ( "remote search: peer " + target . getName ( ) + " sent topics: " + references ) ;
// add references twice, so they can be counted (must have at least 2 entries)
String [ ] rs = references . split ( "," ) ;
synchronized ( containerCache ) {
containerCache . addTopic ( rs ) ;
containerCache . addTopic ( rs ) ;
}
}
}
}
@ -592,7 +596,7 @@ public final class yacyClient {
ci = new ByteBuffer ( entry . getValue ( ) . getBytes ( "UTF-8" ) ) ;
ci = new ByteBuffer ( entry . getValue ( ) . getBytes ( "UTF-8" ) ) ;
} catch ( UnsupportedEncodingException e ) {
} catch ( UnsupportedEncodingException e ) {
Log . logException ( e ) ;
Log . logException ( e ) ;
return null ;
return - 1 ;
}
}
//System.out.println("DEBUG-ABSTRACTFETCH: for word hash " + wordhash + " received " + ci.toString());
//System.out.println("DEBUG-ABSTRACTFETCH: for word hash " + wordhash + " received " + ci.toString());
ReferenceContainer . decompressIndex ( singleAbstract , ci , target . hash ) ;
ReferenceContainer . decompressIndex ( singleAbstract , ci , target . hash ) ;
@ -600,14 +604,8 @@ public final class yacyClient {
}
}
}
}
}
}
if ( abstractCache . size ( ) > 0 ) yacyCore . log . logInfo ( "remote search: peer " + target . getName ( ) + " sent " + abstractCache . size ( ) + " index abstracts" ) ;
}
}
// insert the containers to the index
for ( int m = 0 ; m < words ; m + + ) try {
indexSegment . termIndex ( ) . add ( container [ m ] ) ;
} catch ( Exception e ) {
Log . logException ( e ) ;
}
// generate statistics
// generate statistics
long searchtime ;
long searchtime ;
@ -617,7 +615,7 @@ public final class yacyClient {
searchtime = totalrequesttime ;
searchtime = totalrequesttime ;
}
}
if ( yacyCore . log . isFine ( ) ) yacyCore . log . logFine ( "SEARCH "
if ( yacyCore . log . isFine ( ) ) yacyCore . log . logFine ( "SEARCH "
+ results
+ urlcount
+ " URLS FROM "
+ " URLS FROM "
+ target . hash
+ target . hash
+ ":"
+ ":"
@ -627,7 +625,7 @@ public final class yacyClient {
+ ", searchtime=" + searchtime + ", netdelay="
+ ", searchtime=" + searchtime + ", netdelay="
+ ( totalrequesttime - searchtime ) + ", references="
+ ( totalrequesttime - searchtime ) + ", references="
+ result . get ( "references" ) ) ;
+ result . get ( "references" ) ) ;
return url s ;
return url count ;
}
}
public static Map < String , String > permissionMessage ( final yacySeedDB seedDB , final String targetHash ) {
public static Map < String , String > permissionMessage ( final yacySeedDB seedDB , final String targetHash ) {