2006-10-14 16:13:12 +02:00
// Surftips.java
2008-07-20 19:14:51 +02:00
// (C) 2006 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
2006-09-30 00:27:20 +02:00
// first published 2006 on http://www.anomic.de
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
2009-09-29 23:28:49 +02:00
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2006-09-30 00:27:20 +02:00
//
// LICENSE
//
// 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
2007-06-04 17:36:10 +02:00
import java.net.MalformedURLException ;
2006-09-30 00:27:20 +02:00
import java.util.Date ;
import java.util.HashMap ;
import java.util.Iterator ;
2011-01-03 21:52:54 +01:00
import net.yacy.cora.date.GenericFormatter ;
2011-03-07 21:36:40 +01:00
import net.yacy.cora.document.UTF8 ;
2010-08-23 14:32:02 +02:00
import net.yacy.cora.protocol.RequestHeader ;
2011-08-23 00:37:53 +02:00
import net.yacy.cora.ranking.ConcurrentScoreMap ;
import net.yacy.cora.ranking.ScoreMap ;
2009-10-11 02:12:19 +02:00
import net.yacy.kelondro.data.meta.DigestURI ;
2009-10-10 01:32:08 +02:00
import net.yacy.kelondro.index.Row ;
import net.yacy.kelondro.index.Row.Entry ;
2009-10-10 01:22:22 +02:00
import net.yacy.kelondro.order.NaturalOrder ;
2009-10-21 22:14:30 +02:00
import net.yacy.repository.Blacklist ;
2009-10-10 01:22:22 +02:00
2009-07-19 22:37:44 +02:00
import de.anomic.search.Switchboard ;
2006-09-30 00:27:20 +02:00
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
import de.anomic.tools.crypt ;
import de.anomic.tools.nxTools ;
2010-05-19 14:53:09 +02:00
import de.anomic.yacy.yacyNewsDB ;
2006-09-30 00:27:20 +02:00
import de.anomic.yacy.yacyNewsPool ;
import de.anomic.yacy.yacySeed ;
2006-10-14 16:13:12 +02:00
public class Surftips {
2006-09-30 00:27:20 +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 ;
2006-09-30 00:27:20 +02:00
final serverObjects prop = new serverObjects ( ) ;
2008-08-02 14:12:04 +02:00
final boolean authenticated = sb . adminAuthenticated ( header ) > = 2 ;
final int display = ( ( post = = null ) | | ( ! authenticated ) ) ? 0 : post . getInt ( " display " , 0 ) ;
2006-09-30 00:27:20 +02:00
prop . put ( " display " , display ) ;
2008-08-02 14:12:04 +02:00
final boolean showScore = ( ( post ! = null ) & & ( post . containsKey ( " score " ) ) ) ;
2006-10-01 01:28:03 +02:00
2007-05-23 21:09:19 +02:00
// access control
2007-05-23 19:49:16 +02:00
boolean publicPage = sb . getConfigBool ( " publicSurftips " , true ) ;
2008-08-02 14:12:04 +02:00
final boolean authorizedAccess = sb . verifyAuthentication ( header , false ) ;
2007-05-23 19:49:16 +02:00
if ( ( post ! = null ) & & ( post . containsKey ( " publicPage " ) ) ) {
if ( ! authorizedAccess ) {
2006-09-30 00:27:20 +02:00
prop . put ( " AUTHENTICATE " , " admin log-in " ) ; // force log-in
return prop ;
}
2007-05-23 19:49:16 +02:00
publicPage = post . get ( " publicPage " , " 0 " ) . equals ( " 1 " ) ;
sb . setConfig ( " publicSurftips " , publicPage ) ;
2006-09-30 00:27:20 +02:00
}
2007-05-23 19:49:16 +02:00
if ( ( publicPage ) | | ( authorizedAccess ) ) {
2006-09-30 00:27:20 +02:00
// read voting
String hash ;
if ( ( post ! = null ) & & ( ( hash = post . get ( " voteNegative " , null ) ) ! = null ) ) {
if ( ! sb . verifyAuthentication ( header , false ) ) {
prop . put ( " AUTHENTICATE " , " admin log-in " ) ; // force log-in
return prop ;
}
// make new news message with voting
2011-01-12 01:00:14 +01:00
if ( sb . isRobinsonMode ( ) ) {
final HashMap < String , String > map = new HashMap < String , String > ( ) ;
map . put ( " urlhash " , hash ) ;
map . put ( " vote " , " negative " ) ;
map . put ( " refid " , post . get ( " refid " , " " ) ) ;
sb . peers . newsPool . publishMyNews ( sb . peers . mySeed ( ) , yacyNewsPool . CATEGORY_SURFTIPP_VOTE_ADD , map ) ;
}
2006-09-30 00:27:20 +02:00
}
if ( ( post ! = null ) & & ( ( hash = post . get ( " votePositive " , null ) ) ! = null ) ) {
if ( ! sb . verifyAuthentication ( header , false ) ) {
prop . put ( " AUTHENTICATE " , " admin log-in " ) ; // force log-in
return prop ;
}
// make new news message with voting
2008-08-02 14:12:04 +02:00
final HashMap < String , String > map = new HashMap < String , String > ( ) ;
2006-09-30 00:27:20 +02:00
map . put ( " urlhash " , hash ) ;
map . put ( " url " , crypt . simpleDecode ( post . get ( " url " , " " ) , null ) ) ;
map . put ( " title " , crypt . simpleDecode ( post . get ( " title " , " " ) , null ) ) ;
map . put ( " description " , crypt . simpleDecode ( post . get ( " description " , " " ) , null ) ) ;
map . put ( " vote " , " positive " ) ;
map . put ( " refid " , post . get ( " refid " , " " ) ) ;
2006-10-23 03:10:29 +02:00
map . put ( " comment " , post . get ( " comment " , " " ) ) ;
2010-06-15 12:43:47 +02:00
sb . peers . newsPool . publishMyNews ( sb . peers . mySeed ( ) , yacyNewsPool . CATEGORY_SURFTIPP_VOTE_ADD , map ) ;
2006-09-30 00:27:20 +02:00
}
2006-10-14 16:13:12 +02:00
// create surftips
2008-08-02 14:12:04 +02:00
final HashMap < String , Integer > negativeHashes = new HashMap < String , Integer > ( ) ; // a mapping from an url hash to Integer (count of votes)
final HashMap < String , Integer > positiveHashes = new HashMap < String , Integer > ( ) ; // a mapping from an url hash to Integer (count of votes)
2008-05-06 01:13:47 +02:00
accumulateVotes ( sb , negativeHashes , positiveHashes , yacyNewsPool . INCOMING_DB ) ;
2006-09-30 00:27:20 +02:00
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
2011-03-13 02:41:44 +01:00
final ScoreMap < String > ranking = new ConcurrentScoreMap < String > ( ) ; // score cluster for url hashes
2011-01-03 21:52:54 +01:00
final Row rowdef = new Row ( " String url-255, String title-120, String description-120, String refid- " + ( GenericFormatter . PATTERN_SHORT_SECOND . length ( ) + 12 ) , NaturalOrder . naturalOrder ) ;
2008-08-02 14:12:04 +02:00
final HashMap < String , Entry > surftips = new HashMap < String , Entry > ( ) ; // a mapping from an url hash to a kelondroRow.Entry with display properties
2008-05-06 01:13:47 +02:00
accumulateSurftips ( sb , surftips , ranking , rowdef , negativeHashes , positiveHashes , yacyNewsPool . INCOMING_DB ) ;
2006-10-14 16:13:12 +02:00
//accumulateSurftips(surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
//accumulateSurftips(surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
2006-09-30 00:27:20 +02:00
// read out surftipp array and create property entries
2010-10-16 00:01:39 +02:00
final Iterator < String > k = ranking . keys ( false ) ;
2006-09-30 00:27:20 +02:00
int i = 0 ;
2009-01-30 16:33:00 +01:00
Row . Entry row ;
2006-09-30 00:27:20 +02:00
String url , urlhash , refid , title , description ;
boolean voted ;
while ( k . hasNext ( ) ) {
2008-01-29 17:41:09 +01:00
urlhash = k . next ( ) ;
2006-09-30 00:27:20 +02:00
if ( urlhash = = null ) continue ;
2008-01-29 17:41:09 +01:00
row = surftips . get ( urlhash ) ;
2006-09-30 00:27:20 +02:00
if ( row = = null ) continue ;
2011-03-10 13:35:32 +01:00
url = row . getColString ( 0 ) ;
2007-06-04 17:36:10 +02:00
try {
2010-10-26 18:10:20 +02:00
if ( Switchboard . urlBlacklist . isListed ( Blacklist . BLACKLIST_SURFTIPS , new DigestURI ( url ) ) )
2007-06-04 17:36:10 +02:00
continue ;
2008-08-02 14:12:04 +02:00
} catch ( final MalformedURLException e ) { continue ; } ;
2011-03-10 13:35:32 +01:00
title = row . getColString ( 1 ) ;
description = row . getColString ( 2 ) ;
2006-09-30 00:27:20 +02:00
if ( ( url = = null ) | | ( title = = null ) | | ( description = = null ) ) continue ;
2011-03-10 13:35:32 +01:00
refid = row . getColString ( 3 ) ;
2009-05-28 16:26:05 +02:00
voted = ( sb . peers . newsPool . getSpecific ( yacyNewsPool . OUTGOING_DB , yacyNewsPool . CATEGORY_SURFTIPP_VOTE_ADD , " refid " , refid ) ! = null ) | |
( sb . peers . newsPool . getSpecific ( yacyNewsPool . PUBLISHED_DB , yacyNewsPool . CATEGORY_SURFTIPP_VOTE_ADD , " refid " , refid ) ! = null ) ;
2007-10-24 23:38:19 +02:00
prop . put ( " surftips_results_ " + i + " _authorized " , ( authenticated ) ? " 1 " : " 0 " ) ;
prop . put ( " surftips_results_ " + i + " _authorized_recommend " , ( voted ) ? " 0 " : " 1 " ) ;
2007-01-18 17:53:31 +01:00
prop . put ( " surftips_results_ " + i + " _authorized_recommend_urlhash " , urlhash ) ;
prop . put ( " surftips_results_ " + i + " _authorized_recommend_refid " , refid ) ;
2007-10-24 23:38:19 +02:00
prop . put ( " surftips_results_ " + i + " _authorized_recommend_url " , crypt . simpleEncode ( url , null , 'b' ) ) ;
prop . put ( " surftips_results_ " + i + " _authorized_recommend_title " , crypt . simpleEncode ( title , null , 'b' ) ) ;
prop . put ( " surftips_results_ " + i + " _authorized_recommend_description " , crypt . simpleEncode ( description , null , 'b' ) ) ;
2007-01-18 17:53:31 +01:00
prop . put ( " surftips_results_ " + i + " _authorized_recommend_display " , display ) ;
2007-10-24 23:38:19 +02:00
prop . put ( " surftips_results_ " + i + " _authorized_recommend_showScore " , ( showScore ? " 1 " : " 0 " ) ) ;
2007-01-18 17:53:31 +01:00
2008-10-22 20:59:04 +02:00
prop . putXML ( " surftips_results_ " + i + " _authorized_urlhash " , urlhash ) ;
prop . putXML ( " surftips_results_ " + i + " _url " , url ) ;
prop . putXML ( " surftips_results_ " + i + " _urlname " , nxTools . shortenURLString ( url , 60 ) ) ;
prop . putXML ( " surftips_results_ " + i + " _urlhash " , urlhash ) ;
2010-10-16 00:01:39 +02:00
prop . putXML ( " surftips_results_ " + i + " _title " , ( showScore ) ? ( " ( " + ranking . get ( urlhash ) + " ) " + title ) : title ) ;
2007-10-24 23:38:19 +02:00
prop . putHTML ( " surftips_results_ " + i + " _description " , description ) ;
2006-09-30 00:27:20 +02:00
i + + ;
if ( i > = 50 ) break ;
}
2006-10-14 16:13:12 +02:00
prop . put ( " surftips_results " , i ) ;
2007-10-24 23:38:19 +02:00
prop . put ( " surftips " , " 1 " ) ;
2006-09-30 00:27:20 +02:00
} else {
2007-10-24 23:38:19 +02:00
prop . put ( " surftips " , " 0 " ) ;
2006-09-30 00:27:20 +02:00
}
return prop ;
}
2008-08-02 14:12:04 +02:00
private static int timeFactor ( final Date created ) {
2006-09-30 00:27:20 +02:00
return ( int ) Math . max ( 0 , 10 - ( ( System . currentTimeMillis ( ) - created . getTime ( ) ) / 24 / 60 / 60 / 1000 ) ) ;
}
2009-07-19 22:37:44 +02:00
private static void accumulateVotes ( final Switchboard sb , final HashMap < String , Integer > negativeHashes , final HashMap < String , Integer > positiveHashes , final int dbtype ) {
2009-05-28 16:26:05 +02:00
final int maxCount = Math . min ( 1000 , sb . peers . newsPool . size ( dbtype ) ) ;
2010-05-19 14:53:09 +02:00
yacyNewsDB . Record record ;
final Iterator < yacyNewsDB . Record > recordIterator = sb . peers . newsPool . recordIterator ( dbtype , true ) ;
2007-07-06 00:56:37 +02:00
int j = 0 ;
while ( ( recordIterator . hasNext ( ) ) & & ( j + + < maxCount ) ) {
2008-01-29 17:41:09 +01:00
record = recordIterator . next ( ) ;
2006-09-30 00:27:20 +02:00
if ( record = = null ) continue ;
2007-03-21 12:09:15 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_SURFTIPP_VOTE_ADD ) ) {
2008-08-02 14:12:04 +02:00
final String urlhash = record . attribute ( " urlhash " , " " ) ;
final String vote = record . attribute ( " vote " , " " ) ;
final int factor = ( ( dbtype = = yacyNewsPool . OUTGOING_DB ) | | ( dbtype = = yacyNewsPool . PUBLISHED_DB ) ) ? 2 : 1 ;
2006-09-30 00:27:20 +02:00
if ( vote . equals ( " negative " ) ) {
2008-08-02 14:12:04 +02:00
final Integer i = negativeHashes . get ( urlhash ) ;
2008-08-06 21:43:12 +02:00
if ( i = = null ) negativeHashes . put ( urlhash , Integer . valueOf ( factor ) ) ;
else negativeHashes . put ( urlhash , Integer . valueOf ( i . intValue ( ) + factor ) ) ;
2006-09-30 00:27:20 +02:00
}
if ( vote . equals ( " positive " ) ) {
2008-08-02 14:12:04 +02:00
final Integer i = positiveHashes . get ( urlhash ) ;
2008-08-06 21:43:12 +02:00
if ( i = = null ) positiveHashes . put ( urlhash , Integer . valueOf ( factor ) ) ;
else positiveHashes . put ( urlhash , Integer . valueOf ( i . intValue ( ) + factor ) ) ;
2006-09-30 00:27:20 +02:00
}
}
2007-07-06 00:56:37 +02:00
}
2006-09-30 00:27:20 +02:00
}
2006-10-14 16:13:12 +02:00
private static void accumulateSurftips (
2009-07-19 22:37:44 +02:00
final Switchboard sb ,
2011-03-13 02:41:44 +01:00
final HashMap < String , Entry > surftips , final ScoreMap < String > ranking , final Row rowdef ,
2008-08-02 14:12:04 +02:00
final HashMap < String , Integer > negativeHashes , final HashMap < String , Integer > positiveHashes , final int dbtype ) {
2009-05-28 16:26:05 +02:00
final int maxCount = Math . min ( 1000 , sb . peers . newsPool . size ( dbtype ) ) ;
2010-05-19 14:53:09 +02:00
yacyNewsDB . Record record ;
final Iterator < yacyNewsDB . Record > recordIterator = sb . peers . newsPool . recordIterator ( dbtype , true ) ;
2007-07-06 00:56:37 +02:00
int j = 0 ;
2006-09-30 00:27:20 +02:00
String url = " " , urlhash ;
2009-01-30 16:33:00 +01:00
Row . Entry entry ;
2006-09-30 00:27:20 +02:00
int score = 0 ;
Integer vote ;
2007-07-06 00:56:37 +02:00
while ( ( recordIterator . hasNext ( ) ) & & ( j + + < maxCount ) ) {
2008-01-29 17:41:09 +01:00
record = recordIterator . next ( ) ;
2006-09-30 00:27:20 +02:00
if ( record = = null ) continue ;
entry = null ;
2011-03-11 00:25:07 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_CRAWL_START ) ) {
2008-08-02 14:12:04 +02:00
final String intention = record . attribute ( " intention " , " " ) ;
2006-09-30 00:27:20 +02:00
url = record . attribute ( " startURL " , " " ) ;
2007-06-06 20:24:35 +02:00
if ( url . length ( ) < 12 ) continue ;
2006-09-30 00:27:20 +02:00
entry = rowdef . newEntry ( new byte [ ] [ ] {
url . getBytes ( ) ,
2009-04-08 09:35:08 +02:00
( ( ( intention . length ( ) = = 0 ) | | intention . equals ( " simple web crawl " ) | | intention . equals ( " Automatic ReCrawl! " ) ) ? record . attribute ( " startURL " , " " ) : intention ) . getBytes ( ) ,
2011-03-11 00:25:07 +01:00
intention . equals ( " Automatic ReCrawl! " ) ? UTF8 . getBytes ( " Automatic ReCrawl " ) : UTF8 . getBytes ( " Crawl Start Point " ) ,
2006-09-30 00:27:20 +02:00
record . id ( ) . getBytes ( )
} ) ;
score = 2 + Math . min ( 10 , intention . length ( ) / 4 ) + timeFactor ( record . created ( ) ) ;
2011-03-11 00:25:07 +01:00
}
2006-09-30 00:27:20 +02:00
2011-03-11 00:25:07 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_BOOKMARK_ADD ) ) {
2006-09-30 00:27:20 +02:00
url = record . attribute ( " url " , " " ) ;
2007-06-06 20:24:35 +02:00
if ( url . length ( ) < 12 ) continue ;
2006-09-30 00:27:20 +02:00
entry = rowdef . newEntry ( new byte [ ] [ ] {
url . getBytes ( ) ,
2011-03-11 00:25:07 +01:00
UTF8 . getBytes ( record . attribute ( " title " , " " ) ) ,
UTF8 . getBytes ( " Bookmark: " + record . attribute ( " description " , " " ) ) ,
2006-09-30 00:27:20 +02:00
record . id ( ) . getBytes ( )
} ) ;
score = 8 + timeFactor ( record . created ( ) ) ;
2011-03-11 00:25:07 +01:00
}
2006-09-30 00:27:20 +02:00
2011-03-11 00:25:07 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_SURFTIPP_ADD ) ) {
2006-09-30 00:27:20 +02:00
url = record . attribute ( " url " , " " ) ;
2007-06-06 20:24:35 +02:00
if ( url . length ( ) < 12 ) continue ;
2006-09-30 00:27:20 +02:00
entry = rowdef . newEntry ( new byte [ ] [ ] {
url . getBytes ( ) ,
2011-03-11 00:25:07 +01:00
UTF8 . getBytes ( record . attribute ( " title " , " " ) ) ,
UTF8 . getBytes ( " Surf Tipp: " + record . attribute ( " description " , " " ) ) ,
2006-09-30 00:27:20 +02:00
record . id ( ) . getBytes ( )
} ) ;
score = 5 + timeFactor ( record . created ( ) ) ;
2011-03-11 00:25:07 +01:00
}
2006-09-30 00:27:20 +02:00
2011-03-11 00:25:07 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_SURFTIPP_VOTE_ADD ) ) {
2006-09-30 00:27:20 +02:00
if ( ! ( record . attribute ( " vote " , " negative " ) . equals ( " positive " ) ) ) continue ;
url = record . attribute ( " url " , " " ) ;
2007-06-06 20:24:35 +02:00
if ( url . length ( ) < 12 ) continue ;
2006-09-30 00:27:20 +02:00
entry = rowdef . newEntry ( new byte [ ] [ ] {
url . getBytes ( ) ,
2011-03-11 00:25:07 +01:00
UTF8 . getBytes ( record . attribute ( " title " , " " ) ) ,
UTF8 . getBytes ( record . attribute ( " description " , " " ) ) ,
UTF8 . getBytes ( record . attribute ( " refid " , " " ) )
2006-09-30 00:27:20 +02:00
} ) ;
score = 5 + timeFactor ( record . created ( ) ) ;
2011-03-11 00:25:07 +01:00
}
2006-09-30 00:27:20 +02:00
2011-03-11 00:25:07 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_WIKI_UPDATE ) ) {
2009-05-28 16:26:05 +02:00
yacySeed seed = sb . peers . getConnected ( record . originator ( ) ) ;
if ( seed = = null ) seed = sb . peers . getDisconnected ( record . originator ( ) ) ;
2006-09-30 00:27:20 +02:00
if ( seed ! = null ) {
2007-04-30 00:05:34 +02:00
url = " http:// " + seed . getPublicAddress ( ) + " /Wiki.html?page= " + record . attribute ( " page " , " " ) ;
2006-09-30 00:27:20 +02:00
entry = rowdef . newEntry ( new byte [ ] [ ] {
2011-03-11 00:25:07 +01:00
UTF8 . getBytes ( url ) ,
UTF8 . getBytes ( record . attribute ( " author " , " Anonymous " ) + " : " + record . attribute ( " page " , " " ) ) ,
UTF8 . getBytes ( " Wiki Update: " + record . attribute ( " description " , " " ) ) ,
UTF8 . getBytes ( record . id ( ) )
2006-09-30 00:27:20 +02:00
} ) ;
score = 4 + timeFactor ( record . created ( ) ) ;
}
2011-03-11 00:25:07 +01:00
}
2006-09-30 00:27:20 +02:00
2011-03-11 00:25:07 +01:00
if ( record . category ( ) . equals ( yacyNewsPool . CATEGORY_BLOG_ADD ) ) {
2009-05-28 16:26:05 +02:00
yacySeed seed = sb . peers . getConnected ( record . originator ( ) ) ;
if ( seed = = null ) seed = sb . peers . getDisconnected ( record . originator ( ) ) ;
2006-09-30 00:27:20 +02:00
if ( seed ! = null ) {
2007-04-30 00:05:34 +02:00
url = " http:// " + seed . getPublicAddress ( ) + " /Blog.html?page= " + record . attribute ( " page " , " " ) ;
2006-09-30 00:27:20 +02:00
entry = rowdef . newEntry ( new byte [ ] [ ] {
2011-03-11 00:25:07 +01:00
UTF8 . getBytes ( url ) ,
UTF8 . getBytes ( record . attribute ( " author " , " Anonymous " ) + " : " + record . attribute ( " page " , " " ) ) ,
UTF8 . getBytes ( " Blog Entry: " + record . attribute ( " subject " , " " ) ) ,
UTF8 . getBytes ( record . id ( ) )
2006-09-30 00:27:20 +02:00
} ) ;
score = 4 + timeFactor ( record . created ( ) ) ;
}
2011-03-11 00:25:07 +01:00
}
2006-09-30 00:27:20 +02:00
// add/subtract votes and write record
if ( entry ! = null ) {
2007-09-05 11:01:35 +02:00
try {
2011-03-07 21:36:40 +01:00
urlhash = UTF8 . String ( ( new DigestURI ( url ) ) . hash ( ) ) ;
2008-08-02 14:12:04 +02:00
} catch ( final MalformedURLException e ) {
2007-09-05 11:01:35 +02:00
urlhash = null ;
}
2007-06-06 16:43:51 +02:00
if ( urlhash = = null )
2007-09-05 11:01:35 +02:00
try {
2011-03-07 21:36:40 +01:00
urlhash = UTF8 . String ( ( new DigestURI ( " http:// " + url ) ) . hash ( ) ) ;
2008-08-02 14:12:04 +02:00
} catch ( final MalformedURLException e ) {
2007-09-05 11:01:35 +02:00
urlhash = null ;
}
if ( urlhash = = null ) {
2007-06-06 16:43:51 +02:00
System . out . println ( " Surftips: bad url ' " + url + " ' from news record " + record . toString ( ) ) ;
continue ;
}
2008-01-29 17:41:09 +01:00
if ( ( vote = negativeHashes . get ( urlhash ) ) ! = null ) {
2006-09-30 00:27:20 +02:00
score = Math . max ( 0 , score - vote . intValue ( ) ) ; // do not go below zero
}
2008-01-29 17:41:09 +01:00
if ( ( vote = positiveHashes . get ( urlhash ) ) ! = null ) {
2006-09-30 00:27:20 +02:00
score + = 2 * vote . intValue ( ) ;
}
// consider double-entries
2006-10-14 16:13:12 +02:00
if ( surftips . containsKey ( urlhash ) ) {
2010-10-16 00:01:39 +02:00
ranking . inc ( urlhash , score ) ;
2006-09-30 00:27:20 +02:00
} else {
2010-10-16 00:01:39 +02:00
ranking . set ( urlhash , score ) ;
2006-10-14 16:13:12 +02:00
surftips . put ( urlhash , entry ) ;
2006-09-30 00:27:20 +02:00
}
}
2007-07-06 00:56:37 +02:00
}
2006-09-30 00:27:20 +02:00
}
}