From 0cabcbbe8357726852a4e3ea509a6c654ad18cd5 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Sun, 9 Feb 2014 14:45:12 +0100 Subject: [PATCH] more efficient wordcount --- source/net/yacy/search/index/Segment.java | 4 ++-- source/net/yacy/search/query/SearchEvent.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/source/net/yacy/search/index/Segment.java b/source/net/yacy/search/index/Segment.java index e3a5ac687..b2d2ba535 100644 --- a/source/net/yacy/search/index/Segment.java +++ b/source/net/yacy/search/index/Segment.java @@ -452,12 +452,12 @@ public class Segment { * @return the number of references for this word. */ public int getWordCountGuess(String word) { - if (this.fulltext.getDefaultConnector() == null) return 0; if (word == null || word.indexOf(':') >= 0 || word.indexOf(' ') >= 0 || word.indexOf('/') >= 0 || word.indexOf('\"') >= 0) return 0; if (this.termIndex != null) { int count = this.termIndex.count(Word.word2hash(word)); - if (count > 0) return count; + return count; } + if (this.fulltext.getDefaultConnector() == null) return 0; try { return (int) this.fulltext.getDefaultConnector().getCountByQuery(CollectionSchema.text_t.getSolrFieldName() + ":\"" + word + "\""); } catch (final Throwable e) { diff --git a/source/net/yacy/search/query/SearchEvent.java b/source/net/yacy/search/query/SearchEvent.java index 4d104b480..f22af1728 100644 --- a/source/net/yacy/search/query/SearchEvent.java +++ b/source/net/yacy/search/query/SearchEvent.java @@ -1639,7 +1639,7 @@ public final class SearchEvent { float q, min = Float.MAX_VALUE, max = Float.MIN_VALUE; int ic = maxcount; long timeout = maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime; - while ( ic-- > 0 && i.hasNext() ) { + while ( ic-- > 0 && i.hasNext() && System.currentTimeMillis() < timeout) { word = i.next(); if ( word == null ) { continue; @@ -1651,7 +1651,6 @@ public final class SearchEvent { max = Math.max(max, q); counts.put(word, q); } - if (System.currentTimeMillis() > timeout) break; } if ( max > min ) { for ( final Map.Entry ce : counts.entrySet() ) {