incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [3/3] git commit: Created a new project for all things lucene query related. Moved some query code from blur-core and the writable implementations from blur-store.
Date Sun, 10 Feb 2013 15:07:05 GMT
Updated Branches:
  refs/heads/0.2-dev 4e1baef65 -> 0f78613d6


Created a new project for all things lucene query related. Moved some query code from blur-core and the writable implementations from blur-store.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/0f78613d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/0f78613d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/0f78613d

Branch: refs/heads/0.2-dev
Commit: 0f78613d64927b1d813ee855ad6a122055328a59
Parents: 4e1baef
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sun Feb 10 10:04:40 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sun Feb 10 10:04:40 2013 -0500

----------------------------------------------------------------------
 src/blur-core/pom.xml                              |    5 +
 .../blur/lucene/search/AbstractWrapperQuery.java   |   76 ----
 .../org/apache/blur/lucene/search/FacetQuery.java  |  200 -----------
 .../apache/blur/lucene/search/QueryConverter.java  |   27 --
 .../blur/lucene/search/QueryConverterImpl.java     |   52 ---
 .../org/apache/blur/lucene/search/ScoreType.java   |   22 --
 .../blur/lucene/search/StopExecutionCollector.java |   67 ----
 .../org/apache/blur/lucene/search/SuperQuery.java  |  275 --------------
 .../java/org/apache/blur/server/BlurServer.java    |    1 -
 .../org/apache/blur/server/QueryConverter.java     |   27 ++
 .../org/apache/blur/server/QueryConverterImpl.java |   50 +++
 .../java/org/apache/blur/server/TableContext.java  |    2 -
 .../java/org/apache/blur/utils/PrimeDocCache.java  |   89 -----
 .../apache/blur/lucene/search/FacetQueryTest.java  |  105 ------
 .../apache/blur/search/RandomSuperQueryTest.java   |  151 --------
 .../org/apache/blur/search/SuperQueryTest.java     |  205 -----------
 src/blur-query/pom.xml                             |  137 +++++++
 .../blur/lucene/search/AbstractWrapperQuery.java   |   76 ++++
 .../org/apache/blur/lucene/search/FacetQuery.java  |  200 +++++++++++
 .../apache/blur/lucene/search/PrimeDocCache.java   |  100 +++++
 .../org/apache/blur/lucene/search/ScoreType.java   |   22 ++
 .../org/apache/blur/lucene/search/SlowQuery.java   |  137 +++++++
 .../blur/lucene/search/StopExecutionCollector.java |   67 ++++
 .../org/apache/blur/lucene/search/SuperQuery.java  |  279 +++++++++++++++
 .../lucene/serializer/AbtractQueryWritable.java    |   28 ++
 .../lucene/serializer/BooleanClauseWritable.java   |   87 +++++
 .../lucene/serializer/BooleanQueryWritable.java    |   73 ++++
 .../blur/lucene/serializer/FuzzyQueryWritable.java |  105 ++++++
 .../serializer/MatchAllDocsQueryWritable.java      |   36 ++
 .../blur/lucene/serializer/ProtoSerializer.java    |   79 ++++
 .../apache/blur/lucene/serializer/QUERY_TYPE.java  |  133 +++++++
 .../blur/lucene/serializer/QueryWritable.java      |   70 ++++
 .../blur/lucene/serializer/SerializerUtil.java     |   53 +++
 .../blur/lucene/serializer/TermQueryWritable.java  |   62 ++++
 .../blur/lucene/serializer/TermWritable.java       |   62 ++++
 .../apache/blur/lucene/search/FacetQueryTest.java  |  105 ++++++
 .../blur/lucene/serializer/QueryWritableTest.java  |   38 ++
 .../apache/blur/search/RandomSuperQueryTest.java   |  152 ++++++++
 .../org/apache/blur/search/SuperQueryTest.java     |  199 ++++++++++
 .../lucene/serializer/AbtractQueryWritable.java    |   28 --
 .../lucene/serializer/BooleanClauseWritable.java   |   87 -----
 .../lucene/serializer/BooleanQueryWritable.java    |   73 ----
 .../blur/lucene/serializer/FuzzyQueryWritable.java |  105 ------
 .../serializer/MatchAllDocsQueryWritable.java      |   36 --
 .../blur/lucene/serializer/ProtoSerializer.java    |   79 ----
 .../apache/blur/lucene/serializer/QUERY_TYPE.java  |  133 -------
 .../blur/lucene/serializer/QueryWritable.java      |   70 ----
 .../blur/lucene/serializer/SerializerUtil.java     |   53 ---
 .../blur/lucene/serializer/TermQueryWritable.java  |   62 ----
 .../blur/lucene/serializer/TermWritable.java       |   62 ----
 .../blur/lucene/serializer/QueryWritableTest.java  |   38 --
 src/pom.xml                                        |    1 +
 52 files changed, 2383 insertions(+), 2098 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/pom.xml
----------------------------------------------------------------------
diff --git a/src/blur-core/pom.xml b/src/blur-core/pom.xml
index defbfaf..c650694 100644
--- a/src/blur-core/pom.xml
+++ b/src/blur-core/pom.xml
@@ -48,6 +48,11 @@ under the License.
 		</dependency>
 		<dependency>
 			<groupId>org.apache.blur</groupId>
+			<artifactId>blur-query</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.blur</groupId>
 			<artifactId>blur-util</artifactId>
 			<version>${project.version}</version>
 		</dependency>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
deleted file mode 100644
index f9c4c6b..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-import java.util.Set;
-
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Weight;
-import org.apache.lucene.search.similarities.Similarity;
-
-public abstract class AbstractWrapperQuery extends Query {
-  protected Query _query;
-  protected boolean _rewritten;
-
-  public AbstractWrapperQuery(Query query) {
-    this(query, false);
-  }
-
-  public AbstractWrapperQuery(Query query, boolean rewritten) {
-    this._query = query;
-    this._rewritten = rewritten;
-  }
-
-  public abstract Query clone();
-
-  public abstract Weight createWeight(IndexSearcher searcher) throws IOException;
-
-  public boolean equals(Object obj) {
-    return _query.equals(obj);
-  }
-
-  public void extractTerms(Set<Term> terms) {
-    _query.extractTerms(terms);
-  }
-
-  public float getBoost() {
-    return _query.getBoost();
-  }
-
-  public Similarity getSimilarity(IndexSearcher searcher) {
-    return searcher.getSimilarity();
-  }
-
-  public int hashCode() {
-    return _query.hashCode();
-  }
-
-  public abstract Query rewrite(IndexReader reader) throws IOException;
-
-  public void setBoost(float b) {
-    _query.setBoost(b);
-  }
-
-  public abstract String toString();
-
-  public abstract String toString(String field);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/FacetQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/FacetQuery.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/FacetQuery.java
deleted file mode 100644
index 38cc866..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/FacetQuery.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicLongArray;
-
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Explanation;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.Bits;
-
-public class FacetQuery extends AbstractWrapperQuery {
-
-  private Query[] facets;
-  private AtomicLongArray counts;
-
-  public FacetQuery(Query query, Query[] facets, AtomicLongArray counts) {
-    super(query, false);
-    this.facets = facets;
-    this.counts = counts;
-  }
-
-  public FacetQuery(Query query, Query[] facets, AtomicLongArray counts, boolean rewritten) {
-    super(query, rewritten);
-    this.facets = facets;
-    this.counts = counts;
-  }
-
-  public String toString() {
-    return "facet:{" + _query.toString() + "}";
-  }
-
-  public String toString(String field) {
-    return "facet:{" + _query.toString(field) + "}";
-  }
-
-  @Override
-  public Query clone() {
-    return new FacetQuery((Query) _query.clone(), facets, counts, _rewritten);
-  }
-
-  @Override
-  public Query rewrite(IndexReader reader) throws IOException {
-    if (_rewritten) {
-      return this;
-    }
-    for (int i = 0; i < facets.length; i++) {
-      facets[i] = facets[i].rewrite(reader);
-    }
-    return new FacetQuery(_query.rewrite(reader), facets, counts, true);
-  }
-
-  @Override
-  public Weight createWeight(IndexSearcher searcher) throws IOException {
-    Weight weight = _query.createWeight(searcher);
-    return new FacetWeight(weight, getWeights(searcher), counts);
-  }
-
-  private Weight[] getWeights(IndexSearcher searcher) throws IOException {
-    Weight[] weights = new Weight[facets.length];
-    for (int i = 0; i < weights.length; i++) {
-      weights[i] = facets[i].createWeight(searcher);
-    }
-    return weights;
-  }
-
-  public static class FacetWeight extends Weight {
-
-    private Weight weight;
-    private Weight[] facets;
-    private AtomicLongArray counts;
-
-    public FacetWeight(Weight weight, Weight[] facets, AtomicLongArray counts) {
-      this.weight = weight;
-      this.facets = facets;
-      this.counts = counts;
-    }
-
-    @Override
-    public Explanation explain(AtomicReaderContext reader, int doc) throws IOException {
-      return weight.explain(reader, doc);
-    }
-
-    @Override
-    public Query getQuery() {
-      return weight.getQuery();
-    }
-
-    @Override
-    public void normalize(float norm, float topLevelBoost) {
-      weight.normalize(norm, topLevelBoost);
-    }
-
-    @Override
-    public Scorer scorer(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
-      Scorer scorer = weight.scorer(context, true, topScorer, acceptDocs);
-      if (scorer == null) {
-        return null;
-      }
-      return new FacetScorer(scorer, getScorers(context, true, topScorer, acceptDocs), counts);
-    }
-
-    private Scorer[] getScorers(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
-      Scorer[] scorers = new Scorer[facets.length];
-      for (int i = 0; i < scorers.length; i++) {
-        scorers[i] = facets[i].scorer(context, scoreDocsInOrder, topScorer, acceptDocs);
-      }
-      return scorers;
-    }
-
-    @Override
-    public float getValueForNormalization() throws IOException {
-      return weight.getValueForNormalization();
-    }
-  }
-
-  public static class FacetScorer extends Scorer {
-
-    private Scorer baseScorer;
-    private Scorer[] facets;
-    private AtomicLongArray counts;
-    private int facetLength;
-
-    public FacetScorer(Scorer scorer, Scorer[] facets, AtomicLongArray counts) {
-      super(scorer.getWeight());
-      this.baseScorer = scorer;
-      this.facets = facets;
-      this.counts = counts;
-      this.facetLength = facets.length;
-    }
-
-    private int processFacets(int doc) throws IOException {
-      if (doc == NO_MORE_DOCS) {
-        return doc;
-      }
-      for (int i = 0; i < facetLength; i++) {
-        Scorer facet = facets[i];
-        if (facet == null) {
-          continue;
-        }
-        int docID = facet.docID();
-        if (docID == NO_MORE_DOCS) {
-          continue;
-        }
-        if (docID == doc) {
-          counts.incrementAndGet(i);
-        } else if (docID < doc) {
-          if (facet.advance(doc) == doc) {
-            counts.incrementAndGet(i);
-          }
-        }
-      }
-      return doc;
-    }
-
-    @Override
-    public float score() throws IOException {
-      return baseScorer.score();
-    }
-
-    @Override
-    public int advance(int target) throws IOException {
-      return processFacets(baseScorer.advance(target));
-    }
-
-    @Override
-    public int docID() {
-      return baseScorer.docID();
-    }
-
-    @Override
-    public int nextDoc() throws IOException {
-      return processFacets(baseScorer.nextDoc());
-    }
-
-    @Override
-    public float freq() throws IOException {
-      return baseScorer.freq();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverter.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverter.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverter.java
deleted file mode 100644
index 40e59d6..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverter.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-
-import org.apache.blur.thrift.generated.Query;
-
-public interface QueryConverter {
-
-  org.apache.lucene.search.Query convert(Query query) throws IOException;
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverterImpl.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverterImpl.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverterImpl.java
deleted file mode 100644
index 9cbeff4..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/QueryConverterImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-
-import org.apache.blur.analysis.BlurAnalyzer;
-import org.apache.blur.lucene.LuceneVersionConstant;
-import org.apache.blur.server.Configured;
-import org.apache.blur.server.TableContext;
-import org.apache.lucene.queryparser.classic.ParseException;
-import org.apache.lucene.queryparser.classic.QueryParser;
-import org.apache.lucene.search.Query;
-
-public class QueryConverterImpl extends Configured implements QueryConverter {
-
-  @Override
-  public Query convert(org.apache.blur.thrift.generated.Query query) throws IOException {
-    TableContext tableContext = getTableContext();
-    switch (query.getType()) {
-    case STRING:
-      BlurAnalyzer analyzer = tableContext.getAnalyzer();
-      QueryParser queryParser = new QueryParser(LuceneVersionConstant.LUCENE_VERSION, tableContext.getDefaultFieldName(), analyzer);
-      try {
-        return queryParser.parse(query.getQueryString());
-      } catch (ParseException e) {
-        throw new IOException(e);
-      }
-    case BINARY:
-      throw new IOException("Not supported.");
-    case JSON:
-      throw new IOException("Not supported.");
-    default:
-      throw new IOException("Not supported.");
-    }
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/ScoreType.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/ScoreType.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/ScoreType.java
deleted file mode 100644
index f32c7f0..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/ScoreType.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-public enum ScoreType {
-  AGGREGATE, BEST, CONSTANT, SUPER
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java
deleted file mode 100644
index d97a14f..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.search.Collector;
-import org.apache.lucene.search.Scorer;
-
-public class StopExecutionCollector extends Collector {
-
-  private static final long _5MS = TimeUnit.MILLISECONDS.toNanos(5);
-
-  private Collector _collector;
-  private AtomicBoolean _running;
-  private long last;
-
-  public StopExecutionCollector(Collector collector, AtomicBoolean running) {
-    _collector = collector;
-    _running = running;
-  }
-
-  public static class StopExecutionCollectorException extends RuntimeException {
-    private static final long serialVersionUID = 5753875017543945163L;
-  }
-
-  public boolean acceptsDocsOutOfOrder() {
-    return _collector.acceptsDocsOutOfOrder();
-  }
-
-  public void collect(int doc) throws IOException {
-    long now = System.nanoTime();
-    if (last + _5MS < now) {
-      if (!_running.get()) {
-        throw new StopExecutionCollectorException();
-      }
-      last = now;
-    }
-    _collector.collect(doc);
-  }
-
-  public void setNextReader(AtomicReaderContext context) throws IOException {
-    _collector.setNextReader(context);
-  }
-
-  public void setScorer(Scorer scorer) throws IOException {
-    _collector.setScorer(scorer);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/lucene/search/SuperQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/SuperQuery.java b/src/blur-core/src/main/java/org/apache/blur/lucene/search/SuperQuery.java
deleted file mode 100644
index ddd14ef..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/SuperQuery.java
+++ /dev/null
@@ -1,275 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-
-import org.apache.blur.utils.PrimeDocCache;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Explanation;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.OpenBitSet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SuperQuery extends AbstractWrapperQuery {
-
-  private ScoreType scoreType;
-
-  public SuperQuery(Query query, ScoreType scoreType) {
-    super(query, false);
-    this.scoreType = scoreType;
-  }
-
-  public SuperQuery(Query query, ScoreType scoreType, boolean rewritten) {
-    super(query, rewritten);
-    this.scoreType = scoreType;
-  }
-
-  public Query clone() {
-    return new SuperQuery((Query) _query.clone(), scoreType, _rewritten);
-  }
-
-  public Weight createWeight(IndexSearcher searcher) throws IOException {
-    Weight weight = _query.createWeight(searcher);
-    return new SuperWeight(weight, _query.toString(), this, scoreType);
-  }
-
-  public Query rewrite(IndexReader reader) throws IOException {
-    if (_rewritten) {
-      return this;
-    }
-    return new SuperQuery(_query.rewrite(reader), scoreType, true);
-  }
-
-  public String toString() {
-    return "super:{" + _query.toString() + "}";
-  }
-
-  public String toString(String field) {
-    return "super:{" + _query.toString(field) + "}";
-  }
-
-  public static class SuperWeight extends Weight {
-
-    private Weight weight;
-    private String originalQueryStr;
-    private Query query;
-    private ScoreType scoreType;
-
-    public SuperWeight(Weight weight, String originalQueryStr, Query query, ScoreType scoreType) {
-      this.weight = weight;
-      this.originalQueryStr = originalQueryStr;
-      this.query = query;
-      this.scoreType = scoreType;
-    }
-
-    @Override
-    public Query getQuery() {
-      return query;
-    }
-
-    @Override
-    public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
-      throw new RuntimeException("not supported");
-    }
-
-    /*
-     * This method needs to implement in some other way Weight doesn't provide
-     * this method at all
-     * 
-     * @Override public float getValue() { return weight.getValue(); }
-     */
-
-    @Override
-    public void normalize(float norm, float topLevelBoost) {
-      weight.normalize(norm, topLevelBoost);
-    }
-
-    @Override
-    public Scorer scorer(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
-      Scorer scorer = weight.scorer(context, true, topScorer, acceptDocs);
-      if (scorer == null) {
-        return null;
-      }
-      OpenBitSet primeDocBitSet = PrimeDocCache.getPrimeDocBitSet(context.reader());
-      return new SuperScorer(scorer, primeDocBitSet, originalQueryStr, scoreType);
-    }
-
-    @Override
-    public float getValueForNormalization() throws IOException {
-      return weight.getValueForNormalization();
-    }
-
-  }
-
-  @SuppressWarnings("unused")
-  public static class SuperScorer extends Scorer {
-
-    private static final Logger LOG = LoggerFactory.getLogger(SuperScorer.class);
-
-    private static final String DOC_ID = "docId";
-    private static final String NEXT_DOC = "nextDoc";
-    private static final String ADVANCE = "advance";
-    private static final double SUPER_POWER_CONSTANT = 2;
-    private static final boolean debug = false;
-    private Scorer scorer;
-    private OpenBitSet bitSet;
-    private int nextPrimeDoc;
-    private int primeDoc = -1;
-    private String originalQueryStr;
-    private ScoreType scoreType;
-
-    private int numDocs;
-    private float bestScore;
-    private float aggregateScore;
-    private int hitsInEntity;
-
-    protected SuperScorer(Scorer scorer, OpenBitSet bitSet, String originalQueryStr, ScoreType scoreType) {
-      super(scorer.getWeight());
-      this.scorer = scorer;
-      this.bitSet = bitSet;
-      this.originalQueryStr = originalQueryStr;
-      this.scoreType = scoreType;
-    }
-
-    @Override
-    public float score() throws IOException {
-      switch (scoreType) {
-      case AGGREGATE:
-        return aggregateScore;
-      case BEST:
-        return bestScore;
-      case CONSTANT:
-        return 1;
-      case SUPER:
-        double log = Math.log10(aggregateScore) + 1.0;
-        double avg = aggregateScore / hitsInEntity;
-        double pow = Math.pow(avg, SUPER_POWER_CONSTANT);
-        return (float) Math.pow(log + pow, 1.0 / SUPER_POWER_CONSTANT);
-      }
-      throw new RuntimeException("Unknown Score type[" + scoreType + "]");
-    }
-
-    @Override
-    public int docID() {
-      return print(DOC_ID, primeDoc);
-    }
-
-    @Override
-    public int advance(int target) throws IOException {
-      if (target == NO_MORE_DOCS) {
-        return print(ADVANCE, primeDoc = scorer.advance(NO_MORE_DOCS));
-      }
-      int doc = scorer.docID();
-      int odoc = doc;
-      if (isScorerExhausted(doc)) {
-        return print(ADVANCE, primeDoc = doc);
-      }
-      if (target > doc || doc == -1) {
-        doc = scorer.advance(target);
-        if (isScorerExhausted(doc)) {
-          return print(ADVANCE, primeDoc = doc);
-        }
-      } else if (isScorerExhausted(doc)) {
-        return print(ADVANCE, primeDoc == -1 ? primeDoc = doc : primeDoc);
-      }
-      return print(ADVANCE, gatherAllHitsSuperDoc(doc));
-    }
-
-    private int print(String message, int i) {
-      if (debug) {
-        System.out.println(message + " [" + i + "] " + originalQueryStr);
-      }
-      return i;
-    }
-
-    @Override
-    public int nextDoc() throws IOException {
-      int doc = scorer.docID();
-      int odoc = doc;
-      if (isScorerExhausted(doc)) {
-        return primeDoc = doc;
-      }
-      if (doc == -1) {
-        doc = scorer.nextDoc();
-        if (isScorerExhausted(doc)) {
-          return print(NEXT_DOC, primeDoc = doc);
-        }
-      } else if (isScorerExhausted(doc)) {
-        return print(NEXT_DOC, primeDoc == -1 ? primeDoc = doc : primeDoc);
-      }
-
-      return print(NEXT_DOC, gatherAllHitsSuperDoc(doc));
-    }
-
-    private int gatherAllHitsSuperDoc(int doc) throws IOException {
-      reset();
-      primeDoc = getPrimeDoc(doc);
-      nextPrimeDoc = getNextPrimeDoc(doc);
-      numDocs = nextPrimeDoc - primeDoc;
-      float currentDocScore = 0;
-      while (doc < nextPrimeDoc) {
-        currentDocScore = scorer.score();
-        aggregateScore += currentDocScore;
-        if (currentDocScore > bestScore) {
-          bestScore = currentDocScore;
-        }
-        hitsInEntity++;
-        doc = scorer.nextDoc();
-      }
-      return primeDoc;
-    }
-
-    private void reset() {
-      numDocs = 0;
-      bestScore = 0;
-      aggregateScore = 0;
-      hitsInEntity = 0;
-    }
-
-    private int getNextPrimeDoc(int doc) {
-      int nextSetBit = bitSet.nextSetBit(doc + 1);
-      return nextSetBit == -1 ? NO_MORE_DOCS : nextSetBit;
-    }
-
-    private int getPrimeDoc(int doc) {
-      if (bitSet.fastGet(doc)) {
-        return doc;
-      }
-      return bitSet.prevSetBit(doc);
-    }
-
-    private boolean isScorerExhausted(int doc) {
-      return doc == NO_MORE_DOCS ? true : false;
-    }
-
-    @Override
-    public float freq() throws IOException {
-      return scorer.freq();
-    }
-  }
-
-  public Query getQuery() {
-    return _query;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java b/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java
index 524b0b0..d727f76 100644
--- a/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java
+++ b/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java
@@ -42,7 +42,6 @@ import org.apache.blur.analysis.BlurAnalyzer;
 import org.apache.blur.concurrent.Executors;
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
-import org.apache.blur.lucene.search.QueryConverter;
 import org.apache.blur.manager.IndexServer;
 import org.apache.blur.manager.writer.BlurIndex;
 import org.apache.blur.server.BlurServer.SearchAction.ACTION;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/server/QueryConverter.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/server/QueryConverter.java b/src/blur-core/src/main/java/org/apache/blur/server/QueryConverter.java
new file mode 100644
index 0000000..c3aa0dd
--- /dev/null
+++ b/src/blur-core/src/main/java/org/apache/blur/server/QueryConverter.java
@@ -0,0 +1,27 @@
+package org.apache.blur.server;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+
+import org.apache.blur.thrift.generated.Query;
+
+public interface QueryConverter {
+
+  org.apache.lucene.search.Query convert(Query query) throws IOException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/server/QueryConverterImpl.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/server/QueryConverterImpl.java b/src/blur-core/src/main/java/org/apache/blur/server/QueryConverterImpl.java
new file mode 100644
index 0000000..8b363f9
--- /dev/null
+++ b/src/blur-core/src/main/java/org/apache/blur/server/QueryConverterImpl.java
@@ -0,0 +1,50 @@
+package org.apache.blur.server;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+
+import org.apache.blur.analysis.BlurAnalyzer;
+import org.apache.blur.lucene.LuceneVersionConstant;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.apache.lucene.queryparser.classic.QueryParser;
+import org.apache.lucene.search.Query;
+
+public class QueryConverterImpl extends Configured implements QueryConverter {
+
+  @Override
+  public Query convert(org.apache.blur.thrift.generated.Query query) throws IOException {
+    TableContext tableContext = getTableContext();
+    switch (query.getType()) {
+    case STRING:
+      BlurAnalyzer analyzer = tableContext.getAnalyzer();
+      QueryParser queryParser = new QueryParser(LuceneVersionConstant.LUCENE_VERSION, tableContext.getDefaultFieldName(), analyzer);
+      try {
+        return queryParser.parse(query.getQueryString());
+      } catch (ParseException e) {
+        throw new IOException(e);
+      }
+    case BINARY:
+      throw new IOException("Not supported.");
+    case JSON:
+      throw new IOException("Not supported.");
+    default:
+      throw new IOException("Not supported.");
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java b/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java
index 23c384e..894f1c0 100644
--- a/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java
+++ b/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java
@@ -28,8 +28,6 @@ import java.util.Map.Entry;
 import org.apache.blur.analysis.BlurAnalyzer;
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
-import org.apache.blur.lucene.search.QueryConverter;
-import org.apache.blur.lucene.search.QueryConverterImpl;
 import org.apache.blur.thrift.generated.TableDescriptor;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/main/java/org/apache/blur/utils/PrimeDocCache.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/utils/PrimeDocCache.java b/src/blur-core/src/main/java/org/apache/blur/utils/PrimeDocCache.java
deleted file mode 100644
index f66116c..0000000
--- a/src/blur-core/src/main/java/org/apache/blur/utils/PrimeDocCache.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.apache.blur.utils;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.blur.log.Log;
-import org.apache.blur.log.LogFactory;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexReader.ReaderClosedListener;
-import org.apache.lucene.search.Collector;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.util.OpenBitSet;
-
-public class PrimeDocCache {
-
-  private static final Log LOG = LogFactory.getLog(PrimeDocCache.class);
-
-  public static final OpenBitSet EMPTY_BIT_SET = new OpenBitSet();
-
-  private static Map<Object, OpenBitSet> primeDocMap = new ConcurrentHashMap<Object, OpenBitSet>();
-
-  /**
-   * The way this method is called via warm up methods the likelihood of
-   * creating multiple bitsets during a race condition is very low, that's why
-   * this method is not synced.
-   */
-  public static OpenBitSet getPrimeDocBitSet(IndexReader reader) throws IOException {
-    Object key = reader.getCoreCacheKey();
-    OpenBitSet bitSet = primeDocMap.get(key);
-    if (bitSet == null) {
-      reader.addReaderClosedListener(new ReaderClosedListener() {
-        @Override
-        public void onClose(IndexReader reader) {
-          Object key = reader.getCoreCacheKey();
-          LOG.debug("Current size [" + primeDocMap.size() + "] Prime Doc BitSet removing for segment [" + reader + "]");
-          primeDocMap.remove(key);
-        }
-      });
-      LOG.debug("Prime Doc BitSet missing for segment [" + reader + "] current size [" + primeDocMap.size() + "]");
-      final OpenBitSet bs = new OpenBitSet(reader.maxDoc());
-      primeDocMap.put(key, bs);
-      IndexSearcher searcher = new IndexSearcher(reader);
-      searcher.search(new TermQuery(BlurConstants.PRIME_DOC_TERM), new Collector() {
-
-        @Override
-        public void setScorer(Scorer scorer) throws IOException {
-
-        }
-
-        @Override
-        public void setNextReader(AtomicReaderContext atomicReaderContext) throws IOException {
-        }
-
-        @Override
-        public void collect(int doc) throws IOException {
-          bs.set(doc);
-        }
-
-        @Override
-        public boolean acceptsDocsOutOfOrder() {
-          return false;
-        }
-      });
-      return bs;
-    }
-    return bitSet;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java b/src/blur-core/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java
deleted file mode 100644
index fadd0d5..0000000
--- a/src/blur-core/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.apache.blur.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicLongArray;
-
-import org.apache.lucene.analysis.core.KeywordAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.FieldType;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.store.LockObtainFailedException;
-import org.apache.lucene.store.RAMDirectory;
-import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-
-public class FacetQueryTest {
-
-  private IndexReader reader;
-
-  @Before
-  public void setup() throws CorruptIndexException, LockObtainFailedException, IOException {
-    reader = createIndex();
-  }
-
-  @After
-  public void tearDown() {
-
-  }
-
-  @Test
-  public void testFacetQueryNoSuper() throws IOException {
-    BooleanQuery bq = new BooleanQuery();
-    bq.add(new TermQuery(new Term("f1", "value")), Occur.SHOULD);
-    bq.add(new TermQuery(new Term("f2", "v3")), Occur.SHOULD);
-
-    Query f1 = new TermQuery(new Term("f2", "v4"));
-
-    BooleanQuery f2 = new BooleanQuery();
-    f2.add(new TermQuery(new Term("f1", "value")), Occur.MUST);
-    f2.add(new TermQuery(new Term("f2", "v3")), Occur.MUST);
-
-    Query[] facets = new Query[] { f1, f2 };
-
-    AtomicLongArray counts = new AtomicLongArray(facets.length);
-    FacetQuery facetQuery = new FacetQuery(bq, facets, counts);
-
-    IndexSearcher indexSearcher = new IndexSearcher(reader);
-    indexSearcher.search(facetQuery, 10);
-
-    //@TODO add actual assertion
-    for (int i = 0; i < counts.length(); i++) {
-      System.out.println(counts.get(i));
-    }
-  }
-
-  private IndexReader createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
-    RAMDirectory directory = new RAMDirectory();
-    IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer());
-    IndexWriter writer = new IndexWriter(directory, conf);
-    FieldType fieldType = new FieldType();
-    fieldType.setStored(true);
-    fieldType.setIndexed(true);
-    fieldType.setOmitNorms(true);
-    for (int i = 0; i < 10; i++) {
-      Document document = new Document();
-      
-      document.add(new Field("f1", "value", fieldType));
-      document.add(new Field("f2", "v" + i, fieldType));
-      writer.addDocument(document);
-    }
-    writer.close();
-    return DirectoryReader.open(directory);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java b/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
deleted file mode 100644
index 8c3b8bb..0000000
--- a/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package org.apache.blur.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import static junit.framework.Assert.assertTrue;
-import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-
-import org.apache.blur.lucene.search.ScoreType;
-import org.apache.blur.lucene.search.SuperQuery;
-import org.apache.blur.utils.BlurConstants;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.document.StringField;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.queryparser.classic.ParseException;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
-import org.apache.lucene.store.RAMDirectory;
-import org.junit.Test;
-
-public class RandomSuperQueryTest {
-
-  private static final int MOD_COLS_USED_FOR_SKIPPING = 3;
-  private static final int MAX_NUM_OF_DOCS = 10000;// 10000
-  private static final int MIN_NUM_COL_FAM = 3;// 3
-  private static final int MAX_NUM_COL_FAM = 20;// 20
-  private static final int MAX_NUM_DOCS_PER_COL_FAM = 25;// 25
-  private static final int MAX_NUM_COLS = 21;// 21
-  private static final int MIN_NUM_COLS = 3;// 3
-  private static final int MAX_NUM_OF_WORDS = 1000;
-  private static final int MOD_USED_FOR_SAMPLING = 7;//
-
-  private Random seedGen = new Random(1);
-
-  @Test
-  public void testRandomSuperQuery() throws CorruptIndexException, IOException, InterruptedException, ParseException {
-    long seed = seedGen.nextLong();
-
-    Random random = new Random(seed);
-    Collection<Query> sampler = new HashSet<Query>();
-    System.out.print("Creating index... ");
-    System.out.flush();
-    Directory directory = createIndex(random, sampler);
-    IndexReader reader = DirectoryReader.open(directory);
-    System.out.print("Running searches [" + sampler.size() + "]... ");
-    System.out.flush();
-    assertTrue(!sampler.isEmpty());
-    IndexSearcher searcher = new IndexSearcher(reader);
-    long s = System.currentTimeMillis();
-    for (Query query : sampler) {
-      TopDocs topDocs = searcher.search(query, 10);
-      assertTrue("seed [" + seed + "] {" + query + "} {" + s + "}", topDocs.totalHits > 0);
-    }
-    long e = System.currentTimeMillis();
-    System.out.println("Finished in [" + (e - s) + "] ms");
-  }
-
-  private Directory createIndex(Random random, Collection<Query> sampler) throws CorruptIndexException, LockObtainFailedException, IOException {
-    Directory directory = new RAMDirectory();
-    String[] columnFamilies = genWords(random, MIN_NUM_COL_FAM, MAX_NUM_COL_FAM, "colfam");
-    Map<String, String[]> columns = new HashMap<String, String[]>();
-    for (int i = 0; i < columnFamilies.length; i++) {
-      columns.put(columnFamilies[i], genWords(random, MIN_NUM_COLS, MAX_NUM_COLS, "col"));
-    }
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
-    int numberOfDocs = random.nextInt(MAX_NUM_OF_DOCS) + 1;
-    for (int i = 0; i < numberOfDocs; i++) {
-      writer.addDocuments(generatSuperDoc(random, columns, sampler));
-    }
-    writer.close();
-    return directory;
-  }
-
-  private String[] genWords(Random random, int min, int max, String prefix) {
-    int numberOfColFam = random.nextInt(max - min) + min;
-    String[] str = new String[numberOfColFam];
-    for (int i = 0; i < numberOfColFam; i++) {
-      str[i] = genWord(random, prefix);
-    }
-    return str;
-  }
-
-  private List<Document> generatSuperDoc(Random random, Map<String, String[]> columns, Collection<Query> sampler) {
-    List<Document> docs = new ArrayList<Document>();
-    BooleanQuery booleanQuery = new BooleanQuery();
-    for (String colFam : columns.keySet()) {
-      String[] cols = columns.get(colFam);
-      for (int i = 0; i < random.nextInt(MAX_NUM_DOCS_PER_COL_FAM); i++) {
-        Document doc = new Document();
-        for (String column : cols) {
-          if (random.nextInt() % MOD_COLS_USED_FOR_SKIPPING == 0) {
-            String word = genWord(random, "word");
-            doc.add(new StringField(colFam + "." + column, word, Store.YES));
-            if (random.nextInt() % MOD_USED_FOR_SAMPLING == 0) {
-              TermQuery termQuery = new TermQuery(new Term(colFam + "." + column, word));
-              SuperQuery query = new SuperQuery(termQuery, ScoreType.SUPER);
-              booleanQuery.add(query, Occur.MUST);
-            }
-          }
-        }
-        docs.add(doc);
-      }
-    }
-    if (!booleanQuery.clauses().isEmpty()) {
-      sampler.add(booleanQuery);
-    }
-    Document document = docs.get(0);
-    document.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO));
-    return docs;
-  }
-
-  private String genWord(Random random, String prefix) {
-    return prefix + random.nextInt(MAX_NUM_OF_WORDS);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java b/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java
deleted file mode 100644
index 52dae72..0000000
--- a/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-package org.apache.blur.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import static junit.framework.Assert.assertEquals;
-import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
-import static org.apache.blur.utils.BlurConstants.ROW_ID;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLongArray;
-
-import org.apache.blur.lucene.search.FacetQuery;
-import org.apache.blur.lucene.search.ScoreType;
-import org.apache.blur.lucene.search.SuperQuery;
-import org.apache.blur.utils.BlurConstants;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.document.StringField;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.IndexableField;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
-import org.apache.lucene.store.RAMDirectory;
-import org.junit.Test;
-
-public class SuperQueryTest {
-
-  private static final String PERSON_NAME = "person.name";
-  private static final String ADDRESS_STREET = "address.street";
-
-  private static final String NAME1 = "jon";
-  private static final String NAME2 = "jane";
-  private static final String STREET2 = "main st";
-  private static final String STREET1 = "main";
-
-  @Test
-  public void testSimpleSuperQuery() throws CorruptIndexException, IOException, InterruptedException {
-    BooleanQuery booleanQuery = new BooleanQuery();
-    booleanQuery.add(wrapSuper(new TermQuery(new Term(PERSON_NAME, NAME1))), Occur.MUST);
-    booleanQuery.add(wrapSuper(new TermQuery(new Term(ADDRESS_STREET, STREET1))), Occur.MUST);
-
-    Directory directory = createIndex();
-    IndexReader reader = DirectoryReader.open(directory);
-
-    IndexSearcher searcher = new IndexSearcher(reader);
-    TopDocs topDocs = searcher.search(booleanQuery, 10);
-    assertEquals(2, topDocs.totalHits);
-    assertEquals("1", searcher.doc(topDocs.scoreDocs[0].doc).get(ROW_ID));
-    assertEquals("3", searcher.doc(topDocs.scoreDocs[1].doc).get(ROW_ID));
-  }
-
-  @Test
-  public void testAggregateScoreTypes() throws Exception {
-    IndexSearcher searcher = createSearcher();
-    BooleanQuery booleanQuery = new BooleanQuery();
-    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.AGGREGATE), Occur.SHOULD);
-    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.AGGREGATE), Occur.MUST);
-    TopDocs topDocs = searcher.search(booleanQuery, 10);
-    printTopDocs(topDocs);
-    assertEquals(3, topDocs.totalHits);
-  }
-
-  @Test
-  public void testBestScoreTypes() throws Exception {
-    IndexSearcher searcher = createSearcher();
-    BooleanQuery booleanQuery = new BooleanQuery();
-    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.BEST), Occur.SHOULD);
-    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.BEST), Occur.MUST);
-    TopDocs topDocs = searcher.search(booleanQuery, 10);
-    assertEquals(3, topDocs.totalHits);
-    printTopDocs(topDocs);
-  }
-
-  private void printTopDocs(TopDocs topDocs) {
-    for (int i = 0; i < topDocs.totalHits; i++) {
-      System.out.println("doc " + i + " score " + topDocs.scoreDocs[i].score);
-    }
-
-  }
-
-  @Test
-  public void testConstantScoreTypes() throws Exception {
-    IndexSearcher searcher = createSearcher();
-    BooleanQuery booleanQuery = new BooleanQuery();
-    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.CONSTANT), Occur.SHOULD);
-    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.CONSTANT), Occur.MUST);
-    TopDocs topDocs = searcher.search(booleanQuery, 10);
-    assertEquals(3, topDocs.totalHits);
-    printTopDocs(topDocs);
-  }
-
-  @Test
-  public void testSuperScoreTypes() throws Exception {
-    IndexSearcher searcher = createSearcher();
-    BooleanQuery booleanQuery = new BooleanQuery();
-    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
-    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
-    TopDocs topDocs = searcher.search(booleanQuery, 10);
-    assertEquals(3, topDocs.totalHits);
-    printTopDocs(topDocs);
-  }
-
-  @Test
-  public void testSuperScoreTypesWithFacet() throws Exception {
-    IndexSearcher searcher = createSearcher();
-    BooleanQuery booleanQuery = new BooleanQuery();
-    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
-    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
-
-    BooleanQuery f1 = new BooleanQuery();
-    f1.add(new TermQuery(new Term(PERSON_NAME, NAME1)), Occur.MUST);
-    f1.add(new TermQuery(new Term(PERSON_NAME, NAME2)), Occur.MUST);
-
-    Query[] facets = new Query[] { new SuperQuery(f1, ScoreType.CONSTANT) };
-    AtomicLongArray counts = new AtomicLongArray(facets.length);
-    FacetQuery query = new FacetQuery(booleanQuery, facets, counts);
-
-    TopDocs topDocs = searcher.search(query, 10);
-    assertEquals(3, topDocs.totalHits);
-    printTopDocs(topDocs);
-  }
-
-  private static IndexSearcher createSearcher() throws Exception {
-    Directory directory = createIndex();
-    IndexReader reader = DirectoryReader.open(directory);
-    return new IndexSearcher(reader);
-  }
-
-  public static Directory createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
-    Directory directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
-    writer.addDocuments(
-        addPrime(Arrays.asList(
-            newDocument(newStringField(ROW_ID, "1"), newStringField(PERSON_NAME, NAME1)), 
-            newDocument(newStringField(ROW_ID, "1"), newStringField(PERSON_NAME, NAME1)),
-            newDocument(newStringField(ROW_ID, "1"), newStringField(ADDRESS_STREET, STREET1)))));
-    writer.addDocuments(
-        addPrime(Arrays.asList(
-            newDocument(newStringField(ROW_ID, "2"), newStringField(PERSON_NAME, NAME2)), 
-            newDocument(newStringField(ROW_ID, "2"), newStringField(ADDRESS_STREET, STREET1)))));
-    writer.addDocuments(
-        addPrime(Arrays.asList(
-            newDocument(newStringField(ROW_ID, "3"), newStringField(PERSON_NAME, NAME1)), 
-            newDocument(newStringField(ROW_ID, "3"), newStringField(ADDRESS_STREET, STREET1)), 
-            newDocument(newStringField(ROW_ID, "3"), newStringField(ADDRESS_STREET, STREET2)))));
-    writer.close();
-    return directory;
-  }
-
-  private static List<Document> addPrime(List<Document> docs) {
-    Document document = docs.get(0);
-    document.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO));
-    return docs;
-  }
-
-  private static Document newDocument(IndexableField... fields) {
-    Document document = new Document();
-    for (IndexableField field : fields) {
-      document.add(field);
-    }
-    return document;
-  }
-
-  private static IndexableField newStringField(String name, String value) {
-    return new StringField(name, value, Store.YES);
-  }
-
-  private Query wrapSuper(Query query) {
-    return new SuperQuery(query, ScoreType.AGGREGATE);
-  }
-
-  private Query wrapSuper(String field, String value, ScoreType scoreType) {
-    return new SuperQuery(new TermQuery(new Term(field, value)), scoreType);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/pom.xml
----------------------------------------------------------------------
diff --git a/src/blur-query/pom.xml b/src/blur-query/pom.xml
new file mode 100644
index 0000000..c59be7e
--- /dev/null
+++ b/src/blur-query/pom.xml
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.blur</groupId>
+		<artifactId>blur</artifactId>
+		<version>0.2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+	</parent>
+	<groupId>org.apache.blur</groupId>
+	<artifactId>blur-query</artifactId>
+	<packaging>jar</packaging>
+	<name>Blur Query</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.blur</groupId>
+			<artifactId>blur-util</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.blur</groupId>
+			<artifactId>blur-store</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.blur</groupId>
+			<artifactId>blur-thrift</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-core</artifactId>
+			<version>${lucene.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-codecs</artifactId>
+			<version>${lucene.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-analyzers-common</artifactId>
+			<version>${lucene.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-queryparser</artifactId>
+			<version>${lucene.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-cli</groupId>
+			<artifactId>commons-cli</artifactId>
+			<version>${commons-cli.version}</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.googlecode.concurrentlinkedhashmap</groupId>
+			<artifactId>concurrentlinkedhashmap-lru</artifactId>
+			<version>${concurrentlinkedhashmap-lru.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>${log4j.version}</version>
+			<scope>provided</scope>
+			<exclusions>
+				<exclusion>
+					<groupId>javax.mail</groupId>
+					<artifactId>mail</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>javax.jms</groupId>
+					<artifactId>jms</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>com.sun.jdmk</groupId>
+					<artifactId>jmxtools</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>com.sun.jmx</groupId>
+					<artifactId>jmxri</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+	</dependencies>
+
+	<repositories>
+		<repository>
+			<id>libdir</id>
+			<url>file://${basedir}/../lib</url>
+		</repository>
+	</repositories>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>test-jar</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
new file mode 100644
index 0000000..f9c4c6b
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
@@ -0,0 +1,76 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.search.similarities.Similarity;
+
+public abstract class AbstractWrapperQuery extends Query {
+  protected Query _query;
+  protected boolean _rewritten;
+
+  public AbstractWrapperQuery(Query query) {
+    this(query, false);
+  }
+
+  public AbstractWrapperQuery(Query query, boolean rewritten) {
+    this._query = query;
+    this._rewritten = rewritten;
+  }
+
+  public abstract Query clone();
+
+  public abstract Weight createWeight(IndexSearcher searcher) throws IOException;
+
+  public boolean equals(Object obj) {
+    return _query.equals(obj);
+  }
+
+  public void extractTerms(Set<Term> terms) {
+    _query.extractTerms(terms);
+  }
+
+  public float getBoost() {
+    return _query.getBoost();
+  }
+
+  public Similarity getSimilarity(IndexSearcher searcher) {
+    return searcher.getSimilarity();
+  }
+
+  public int hashCode() {
+    return _query.hashCode();
+  }
+
+  public abstract Query rewrite(IndexReader reader) throws IOException;
+
+  public void setBoost(float b) {
+    _query.setBoost(b);
+  }
+
+  public abstract String toString();
+
+  public abstract String toString(String field);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/FacetQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/FacetQuery.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/FacetQuery.java
new file mode 100644
index 0000000..38cc866
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/FacetQuery.java
@@ -0,0 +1,200 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLongArray;
+
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.util.Bits;
+
+public class FacetQuery extends AbstractWrapperQuery {
+
+  private Query[] facets;
+  private AtomicLongArray counts;
+
+  public FacetQuery(Query query, Query[] facets, AtomicLongArray counts) {
+    super(query, false);
+    this.facets = facets;
+    this.counts = counts;
+  }
+
+  public FacetQuery(Query query, Query[] facets, AtomicLongArray counts, boolean rewritten) {
+    super(query, rewritten);
+    this.facets = facets;
+    this.counts = counts;
+  }
+
+  public String toString() {
+    return "facet:{" + _query.toString() + "}";
+  }
+
+  public String toString(String field) {
+    return "facet:{" + _query.toString(field) + "}";
+  }
+
+  @Override
+  public Query clone() {
+    return new FacetQuery((Query) _query.clone(), facets, counts, _rewritten);
+  }
+
+  @Override
+  public Query rewrite(IndexReader reader) throws IOException {
+    if (_rewritten) {
+      return this;
+    }
+    for (int i = 0; i < facets.length; i++) {
+      facets[i] = facets[i].rewrite(reader);
+    }
+    return new FacetQuery(_query.rewrite(reader), facets, counts, true);
+  }
+
+  @Override
+  public Weight createWeight(IndexSearcher searcher) throws IOException {
+    Weight weight = _query.createWeight(searcher);
+    return new FacetWeight(weight, getWeights(searcher), counts);
+  }
+
+  private Weight[] getWeights(IndexSearcher searcher) throws IOException {
+    Weight[] weights = new Weight[facets.length];
+    for (int i = 0; i < weights.length; i++) {
+      weights[i] = facets[i].createWeight(searcher);
+    }
+    return weights;
+  }
+
+  public static class FacetWeight extends Weight {
+
+    private Weight weight;
+    private Weight[] facets;
+    private AtomicLongArray counts;
+
+    public FacetWeight(Weight weight, Weight[] facets, AtomicLongArray counts) {
+      this.weight = weight;
+      this.facets = facets;
+      this.counts = counts;
+    }
+
+    @Override
+    public Explanation explain(AtomicReaderContext reader, int doc) throws IOException {
+      return weight.explain(reader, doc);
+    }
+
+    @Override
+    public Query getQuery() {
+      return weight.getQuery();
+    }
+
+    @Override
+    public void normalize(float norm, float topLevelBoost) {
+      weight.normalize(norm, topLevelBoost);
+    }
+
+    @Override
+    public Scorer scorer(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
+      Scorer scorer = weight.scorer(context, true, topScorer, acceptDocs);
+      if (scorer == null) {
+        return null;
+      }
+      return new FacetScorer(scorer, getScorers(context, true, topScorer, acceptDocs), counts);
+    }
+
+    private Scorer[] getScorers(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
+      Scorer[] scorers = new Scorer[facets.length];
+      for (int i = 0; i < scorers.length; i++) {
+        scorers[i] = facets[i].scorer(context, scoreDocsInOrder, topScorer, acceptDocs);
+      }
+      return scorers;
+    }
+
+    @Override
+    public float getValueForNormalization() throws IOException {
+      return weight.getValueForNormalization();
+    }
+  }
+
+  public static class FacetScorer extends Scorer {
+
+    private Scorer baseScorer;
+    private Scorer[] facets;
+    private AtomicLongArray counts;
+    private int facetLength;
+
+    public FacetScorer(Scorer scorer, Scorer[] facets, AtomicLongArray counts) {
+      super(scorer.getWeight());
+      this.baseScorer = scorer;
+      this.facets = facets;
+      this.counts = counts;
+      this.facetLength = facets.length;
+    }
+
+    private int processFacets(int doc) throws IOException {
+      if (doc == NO_MORE_DOCS) {
+        return doc;
+      }
+      for (int i = 0; i < facetLength; i++) {
+        Scorer facet = facets[i];
+        if (facet == null) {
+          continue;
+        }
+        int docID = facet.docID();
+        if (docID == NO_MORE_DOCS) {
+          continue;
+        }
+        if (docID == doc) {
+          counts.incrementAndGet(i);
+        } else if (docID < doc) {
+          if (facet.advance(doc) == doc) {
+            counts.incrementAndGet(i);
+          }
+        }
+      }
+      return doc;
+    }
+
+    @Override
+    public float score() throws IOException {
+      return baseScorer.score();
+    }
+
+    @Override
+    public int advance(int target) throws IOException {
+      return processFacets(baseScorer.advance(target));
+    }
+
+    @Override
+    public int docID() {
+      return baseScorer.docID();
+    }
+
+    @Override
+    public int nextDoc() throws IOException {
+      return processFacets(baseScorer.nextDoc());
+    }
+
+    @Override
+    public float freq() throws IOException {
+      return baseScorer.freq();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
new file mode 100644
index 0000000..133522f
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
@@ -0,0 +1,100 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.blur.log.Log;
+import org.apache.blur.log.LogFactory;
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.ReaderClosedListener;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Collector;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.util.OpenBitSet;
+
+public class PrimeDocCache {
+
+  private static final Log LOG = LogFactory.getLog(PrimeDocCache.class);
+
+  public static final OpenBitSet EMPTY_BIT_SET = new OpenBitSet();
+
+  private static Map<Term,Map<Object, OpenBitSet>> termPrimeDocMap = new ConcurrentHashMap<Term, Map<Object,OpenBitSet>>();
+
+  /**
+   * The way this method is called via warm up methods the likelihood of
+   * creating multiple bitsets during a race condition is very low, that's why
+   * this method is not synced.
+   */
+  public static OpenBitSet getPrimeDocBitSet(Term primeDocTerm, IndexReader reader) throws IOException {
+    Object key = reader.getCoreCacheKey();
+    final Map<Object, OpenBitSet> primeDocMap = getPrimeDocMap(primeDocTerm);
+    OpenBitSet bitSet = primeDocMap.get(key);
+    if (bitSet == null) {
+      reader.addReaderClosedListener(new ReaderClosedListener() {
+        @Override
+        public void onClose(IndexReader reader) {
+          Object key = reader.getCoreCacheKey();
+          LOG.debug("Current size [" + primeDocMap.size() + "] Prime Doc BitSet removing for segment [" + reader + "]");
+          primeDocMap.remove(key);
+        }
+      });
+      LOG.debug("Prime Doc BitSet missing for segment [" + reader + "] current size [" + primeDocMap.size() + "]");
+      final OpenBitSet bs = new OpenBitSet(reader.maxDoc());
+      primeDocMap.put(key, bs);
+      IndexSearcher searcher = new IndexSearcher(reader);
+      searcher.search(new TermQuery(primeDocTerm), new Collector() {
+
+        @Override
+        public void setScorer(Scorer scorer) throws IOException {
+
+        }
+
+        @Override
+        public void setNextReader(AtomicReaderContext atomicReaderContext) throws IOException {
+        }
+
+        @Override
+        public void collect(int doc) throws IOException {
+          bs.set(doc);
+        }
+
+        @Override
+        public boolean acceptsDocsOutOfOrder() {
+          return false;
+        }
+      });
+      return bs;
+    }
+    return bitSet;
+  }
+
+  private static Map<Object, OpenBitSet> getPrimeDocMap(Term primeDocTerm) {
+    Map<Object, OpenBitSet> map = termPrimeDocMap.get(primeDocTerm);
+    if (map == null) {
+      termPrimeDocMap.put(primeDocTerm, new ConcurrentHashMap<Object, OpenBitSet>());
+      return termPrimeDocMap.get(primeDocTerm);
+    }
+    return map;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/ScoreType.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/ScoreType.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/ScoreType.java
new file mode 100644
index 0000000..f32c7f0
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/ScoreType.java
@@ -0,0 +1,22 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+public enum ScoreType {
+  AGGREGATE, BEST, CONSTANT, SUPER
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/SlowQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/SlowQuery.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/SlowQuery.java
new file mode 100644
index 0000000..46ee4f5
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/SlowQuery.java
@@ -0,0 +1,137 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.util.Bits;
+
+public class SlowQuery extends Query {
+
+  private Query query;
+  private boolean rewritten = false;
+
+  public SlowQuery(Query query) {
+    this.query = query;
+  }
+
+  @Override
+  public Weight createWeight(IndexSearcher searcher) throws IOException {
+    Weight weight = query.createWeight(searcher);
+    return new SlowWeight(this, weight);
+  }
+
+  @Override
+  public Query rewrite(IndexReader reader) throws IOException {
+    if (!rewritten) {
+      query = query.rewrite(reader);
+    }
+    return this;
+  }
+
+  @Override
+  public String toString(String field) {
+    return query.toString(field);
+  }
+
+  public static class SlowWeight extends Weight {
+
+    private final Weight weight;
+    private final Query query;
+
+    public SlowWeight(Query query, Weight weight) {
+      this.query = query;
+      this.weight = weight;
+    }
+
+    @Override
+    public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
+      return weight.explain(context, doc);
+    }
+
+    @Override
+    public Query getQuery() {
+      return query;
+    }
+
+    @Override
+    public float getValueForNormalization() throws IOException {
+      return weight.getValueForNormalization();
+    }
+
+    @Override
+    public void normalize(float norm, float topLevelBoost) {
+      weight.normalize(norm, topLevelBoost);
+    }
+
+    @Override
+    public Scorer scorer(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
+      Scorer scorer = weight.scorer(context, scoreDocsInOrder, topScorer, acceptDocs);
+      if (scorer == null) {
+        highCpuWait(1);
+        return null;
+      }
+      return new SlowScorer(weight, scorer);
+    }
+
+  }
+
+  public static class SlowScorer extends Scorer {
+
+    private final Scorer scorer;
+
+    protected SlowScorer(Weight weight, Scorer scorer) {
+      super(weight);
+      this.scorer = scorer;
+    }
+
+    public int docID() {
+      return scorer.docID();
+    }
+
+    public int nextDoc() throws IOException {
+      highCpuWait(1);
+      return scorer.nextDoc();
+    }
+
+    public int advance(int target) throws IOException {
+      highCpuWait(1);
+      return scorer.advance(target);
+    }
+
+    public float score() throws IOException {
+      return scorer.score();
+    }
+
+    public float freq() throws IOException {
+      return scorer.freq();
+    }
+
+  }
+
+  public static void highCpuWait(long ms) {
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java
new file mode 100644
index 0000000..d97a14f
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/StopExecutionCollector.java
@@ -0,0 +1,67 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.search.Collector;
+import org.apache.lucene.search.Scorer;
+
+public class StopExecutionCollector extends Collector {
+
+  private static final long _5MS = TimeUnit.MILLISECONDS.toNanos(5);
+
+  private Collector _collector;
+  private AtomicBoolean _running;
+  private long last;
+
+  public StopExecutionCollector(Collector collector, AtomicBoolean running) {
+    _collector = collector;
+    _running = running;
+  }
+
+  public static class StopExecutionCollectorException extends RuntimeException {
+    private static final long serialVersionUID = 5753875017543945163L;
+  }
+
+  public boolean acceptsDocsOutOfOrder() {
+    return _collector.acceptsDocsOutOfOrder();
+  }
+
+  public void collect(int doc) throws IOException {
+    long now = System.nanoTime();
+    if (last + _5MS < now) {
+      if (!_running.get()) {
+        throw new StopExecutionCollectorException();
+      }
+      last = now;
+    }
+    _collector.collect(doc);
+  }
+
+  public void setNextReader(AtomicReaderContext context) throws IOException {
+    _collector.setNextReader(context);
+  }
+
+  public void setScorer(Scorer scorer) throws IOException {
+    _collector.setScorer(scorer);
+  }
+
+}


Mime
View raw message