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
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 Iterator<String> navigatorIterator = topicNavigator.keys(false);
int i = 0;

@ -361,7 +361,7 @@ public final class RankingProcess extends Thread {
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
// words that appeared in the url or the description of all urls
final ScoreMap<String> result = new ConcurrentScoreMap<String>();
@ -373,7 +373,8 @@ public final class RankingProcess extends Thread {
String word;
int c;
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() ) {
word = i.next();
if ( word == null ) {
@ -386,10 +387,11 @@ public final class RankingProcess extends Thread {
max = Math.max(max, q);
counts.put(word, q);
}
if (System.currentTimeMillis() > timeout) break;
}
if ( max > min ) {
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;

@ -895,7 +895,7 @@ public final class SearchEvent {
*/
public ScoreMap<String> getTopicNavigator(final int count ) {
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;
}

Loading…
Cancel
Save