more efficient wordcount

pull/1/head
Michael Peter Christen 11 years ago
parent 3d474a843e
commit 0cabcbbe83

@ -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) {

@ -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() ) {

Loading…
Cancel
Save