From 7213539d72a278548fe8d4ac416acc6fffe42687 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 12 Jan 2011 20:51:19 +0200 Subject: [PATCH] factor out exists collector --- .../elasticsearch/common/lucene/Lucene.java | 52 +++++++++++++++++ .../index/percolator/PercolatorService.java | 58 +------------------ 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java index ca7186e5550..e06520d1cb9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -416,6 +416,58 @@ public class Lucene { } } + public static class ExistsCollector extends Collector { + + private boolean exists; + + public boolean exists() { + return exists; + } + + @Override public void setScorer(Scorer scorer) throws IOException { + this.exists = false; + } + + @Override public void collect(int doc) throws IOException { + exists = true; + } + + @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { + } + + @Override public boolean acceptsDocsOutOfOrder() { + return true; + } + } + + public static class SingleScoreCollector extends Collector { + + private Scorer scorer; + + private float score; + + public float score() { + return this.score; + } + + @Override public void setScorer(Scorer scorer) throws IOException { + this.score = 0; + this.scorer = scorer; + } + + @Override public void collect(int doc) throws IOException { + score = scorer.score(); + } + + @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { + } + + @Override public boolean acceptsDocsOutOfOrder() { + return true; + } + } + + private Lucene() { } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/percolator/PercolatorService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/percolator/PercolatorService.java index dfd71db2fde..9df2845e704 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/percolator/PercolatorService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/percolator/PercolatorService.java @@ -21,18 +21,16 @@ package org.elasticsearch.index.percolator; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Fieldable; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.memory.MemoryIndex; -import org.apache.lucene.search.Collector; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; -import org.apache.lucene.search.Scorer; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FastByteArrayOutputStream; import org.elasticsearch.common.io.FastStringReader; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; @@ -196,7 +194,7 @@ public class PercolatorService extends AbstractIndexComponent { } } - ExistsCollector collector = new ExistsCollector(); + Lucene.ExistsCollector collector = new Lucene.ExistsCollector(); List matches = new ArrayList(); IndexSearcher searcher = memoryIndex.createSearcher(); for (Map.Entry entry : queries.entrySet()) { @@ -224,56 +222,4 @@ public class PercolatorService extends AbstractIndexComponent { return new Response(matches, doc.mappersAdded()); } - - static class ExistsCollector extends Collector { - - private boolean exists; - - public boolean exists() { - return exists; - } - - @Override public void setScorer(Scorer scorer) throws IOException { - this.exists = false; - } - - @Override public void collect(int doc) throws IOException { - exists = true; - } - - @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { - } - - @Override public boolean acceptsDocsOutOfOrder() { - return true; - } - } - - - static class SingleScoreCollector extends Collector { - - private Scorer scorer; - - private float score; - - public float score() { - return this.score; - } - - @Override public void setScorer(Scorer scorer) throws IOException { - this.score = 0; - this.scorer = scorer; - } - - @Override public void collect(int doc) throws IOException { - score = scorer.score(); - } - - @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { - } - - @Override public boolean acceptsDocsOutOfOrder() { - return true; - } - } }