summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMichael Peter Christen <mc@yacy.net>2014-02-09 14:45:12 +0100
committerMichael Peter Christen <mc@yacy.net>2014-02-09 14:45:12 +0100
commit0cabcbbe8357726852a4e3ea509a6c654ad18cd5 (patch)
tree122187b8704d5427f545d425d6014daee9bbdebe /source
parent3d474a843e2048915f0a651d8a97401fabef4fca (diff)
more efficient wordcount
Diffstat (limited to 'source')
-rw-r--r--source/net/yacy/search/index/Segment.java4
-rw-r--r--source/net/yacy/search/query/SearchEvent.java3
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<String, Float> ce : counts.entrySet() ) {