added a timeout for topic computation (solr is here much slower than the

old metadata-db)
pull/1/head
Michael Peter Christen 12 years ago
parent d2d5be032d
commit 4faa07c214

@ -364,7 +364,7 @@ public final class search {
// prepare reference hints // prepare reference hints
final long timer = System.currentTimeMillis(); final long timer = System.currentTimeMillis();
final ScoreMap<String> topicNavigator = theSearch.rankingProcess.getTopics(5); final ScoreMap<String> topicNavigator = theSearch.rankingProcess.getTopics(5, 100);
final StringBuilder refstr = new StringBuilder(6000); final StringBuilder refstr = new StringBuilder(6000);
final Iterator<String> navigatorIterator = topicNavigator.keys(false); final Iterator<String> navigatorIterator = topicNavigator.keys(false);
int i = 0; int i = 0;

@ -361,7 +361,7 @@ public final class RankingProcess extends Thread {
return this.localSearchInclusion; return this.localSearchInclusion;
} }
public ScoreMap<String> getTopics(final int count) { public ScoreMap<String> getTopics(final int maxcount, final long maxtime) {
// create a list of words that had been computed by statistics over all // create a list of words that had been computed by statistics over all
// words that appeared in the url or the description of all urls // words that appeared in the url or the description of all urls
final ScoreMap<String> result = new ConcurrentScoreMap<String>(); final ScoreMap<String> result = new ConcurrentScoreMap<String>();
@ -373,7 +373,8 @@ public final class RankingProcess extends Thread {
String word; String word;
int c; int c;
float q, min = Float.MAX_VALUE, max = Float.MIN_VALUE; float q, min = Float.MAX_VALUE, max = Float.MIN_VALUE;
int ic = count; int ic = maxcount;
long timeout = System.currentTimeMillis() + maxtime;
while ( ic-- > 0 && i.hasNext() ) { while ( ic-- > 0 && i.hasNext() ) {
word = i.next(); word = i.next();
if ( word == null ) { if ( word == null ) {
@ -386,10 +387,11 @@ public final class RankingProcess extends Thread {
max = Math.max(max, q); max = Math.max(max, q);
counts.put(word, q); counts.put(word, q);
} }
if (System.currentTimeMillis() > timeout) break;
} }
if ( max > min ) { if ( max > min ) {
for ( final Map.Entry<String, Float> ce : counts.entrySet() ) { for ( final Map.Entry<String, Float> ce : counts.entrySet() ) {
result.set(ce.getKey(), (int) (((double) count) * (ce.getValue() - min) / (max - min))); result.set(ce.getKey(), (int) (((double) maxcount) * (ce.getValue() - min) / (max - min)));
} }
} }
return this.ref; return this.ref;

@ -895,7 +895,7 @@ public final class SearchEvent {
*/ */
public ScoreMap<String> getTopicNavigator(final int count ) { public ScoreMap<String> getTopicNavigator(final int count ) {
if (this.topicNavigatorCount > 0 && count >= 0) { //topicNavigatorCount set during init, 0=no nav if (this.topicNavigatorCount > 0 && count >= 0) { //topicNavigatorCount set during init, 0=no nav
return this.rankingProcess.getTopics(count != 0 ? count : this.topicNavigatorCount); return this.rankingProcess.getTopics(count != 0 ? count : this.topicNavigatorCount, 500);
} }
return null; return null;
} }

Loading…
Cancel
Save