LUCENE-5487: consolidate the FakeScorers within one package

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5487@1576273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-03-11 10:47:43 +00:00
parent d1ddcfa7c1
commit 9bdf937ac2
10 changed files with 118 additions and 276 deletions

View File

@ -109,57 +109,6 @@ final class BooleanScorer extends BulkScorer {
}
// An internal class which is used in score(Collector, int) for setting the
// current score. This is required since Collector exposes a setScorer method
// and implementations that need the score will call scorer.score().
// Therefore the only methods that are implemented are
// score(), doc() and freq().
private static final class FakeScorer extends Scorer {
float score;
int doc = -1;
int freq;
public FakeScorer() {
super(null);
}
@Override
public int advance(int target) {
throw new UnsupportedOperationException();
}
@Override
public int docID() {
return doc;
}
@Override
public int freq() {
return freq;
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException();
}
@Override
public float score() {
return score;
}
@Override
public long cost() {
throw new UnsupportedOperationException();
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
}
static final class Bucket {
int doc = -1; // tells if bucket is valid
double score; // incremental score

View File

@ -0,0 +1,72 @@
package org.apache.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.util.Collection;
/** Used by {@link BulkScorers} that need to pass a {@link
* Scorer} to {@link Collector#setScorer}. */
final class FakeScorer extends Scorer {
float score;
int doc = -1;
int freq = 1;
public FakeScorer() {
super(null);
}
@Override
public int advance(int target) {
throw new UnsupportedOperationException("FakeScorer doesn't support advance(int)");
}
@Override
public int docID() {
return doc;
}
@Override
public int freq() {
return freq;
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException("FakeScorer doesn't support nextDoc()");
}
@Override
public float score() {
return score;
}
@Override
public long cost() {
return 1;
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
@Override
public Collection<ChildScorer> getChildren() {
throw new UnsupportedOperationException();
}
}

View File

@ -768,50 +768,6 @@ public class IndexSearcher {
this.doMaxScore = doMaxScore;
}
private final class FakeScorer extends Scorer {
float score;
int doc;
public FakeScorer() {
super(null);
}
@Override
public int advance(int target) {
throw new UnsupportedOperationException("FakeScorer doesn't support advance(int)");
}
@Override
public int docID() {
return doc;
}
@Override
public int freq() {
throw new UnsupportedOperationException("FakeScorer doesn't support freq()");
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException("FakeScorer doesn't support nextDoc()");
}
@Override
public float score() {
return score;
}
@Override
public long cost() {
return 1;
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
}
private final FakeScorer fakeScorer = new FakeScorer();
@Override

View File

@ -87,37 +87,10 @@ public class TestBooleanScorer extends LuceneTestCase {
public boolean score(Collector c, int maxDoc) throws IOException {
assert doc == -1;
doc = 3000;
c.setScorer(new Scorer(null) {
@Override
public int advance(int target) {
throw new UnsupportedOperationException("FakeScorer doesn't support advance(int)");
}
@Override
public int docID() {
return doc;
}
@Override
public int freq() {
throw new UnsupportedOperationException("FakeScorer doesn't support freq()");
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException("FakeScorer doesn't support nextDoc()");
}
@Override
public float score() {
return 1.0f;
}
@Override
public long cost() {
return 1;
}
});
FakeScorer fs = new FakeScorer();
fs.doc = doc;
fs.score = 1.0f;
c.setScorer(fs);
c.collect(3000);
return false;
}
@ -182,7 +155,7 @@ public class TestBooleanScorer extends LuceneTestCase {
public void setScorer(Scorer scorer) {
// Make sure we got BooleanScorer:
final Class<?> clazz = scorer instanceof AssertingScorer ? ((AssertingScorer) scorer).getIn().getClass() : scorer.getClass();
assertEquals("Scorer is implemented by wrong class", BooleanScorer.class.getName() + "$FakeScorer", clazz.getName());
assertEquals("Scorer is implemented by wrong class", FakeScorer.class.getName(), clazz.getName());
}
@Override
@ -206,47 +179,6 @@ public class TestBooleanScorer extends LuceneTestCase {
d.close();
}
private static final class FakeScorer extends Scorer {
public FakeScorer() {
super(null);
}
@Override
public int advance(int target) {
throw new UnsupportedOperationException();
}
@Override
public int docID() {
throw new UnsupportedOperationException();
}
@Override
public int freq() {
throw new UnsupportedOperationException();
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException();
}
@Override
public float score() {
return 1.0f;
}
@Override
public long cost() {
throw new UnsupportedOperationException();
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
}
/** Throws UOE if Weight.scorer is called */
private static class CrazyMustUseBulkScorerQuery extends Query {

View File

@ -121,7 +121,7 @@ public class TestConstantScoreQuery extends LuceneTestCase {
checkHits(searcher, csq2, csq2.getBoost(), ConstantScoreQuery.ConstantScorer.class.getName(), ConstantScoreQuery.ConstantScorer.class.getName());
// for the combined BQ, the scorer should always be BooleanScorer's BucketScorer, because our scorer supports out-of order collection!
final String bucketScorerClass = BooleanScorer.class.getName() + "$FakeScorer";
final String bucketScorerClass = FakeScorer.class.getName();
checkHits(searcher, bq, csq1.getBoost() + csq2.getBoost(), bucketScorerClass, null);
checkHits(searcher, csqbq, csqbq.getBoost(), ConstantScoreQuery.ConstantScorer.class.getName(), bucketScorerClass);
} finally {

View File

@ -18,6 +18,7 @@ package org.apache.lucene.facet.taxonomy;
*/
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -76,6 +77,11 @@ public class TaxonomyFacetSumValueSource extends FloatTaxonomyFacets {
public Weight getWeight() {
throw new UnsupportedOperationException();
}
@Override
public Collection<ChildScorer> getChildren() {
throw new UnsupportedOperationException();
}
}
private final void sumValues(List<MatchingDocs> matchingDocs, boolean keepScores, ValueSource valueSource) throws IOException {

View File

@ -18,14 +18,15 @@ package org.apache.lucene.search.grouping;
*/
import java.io.IOException;
import java.util.Collection;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.*;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.PriorityQueue;
import java.io.IOException;
// TODO: this sentence is too long for the class summary.
/** BlockGroupingCollector performs grouping with a
* single pass collector, as long as you are grouping by a
@ -127,6 +128,11 @@ public class BlockGroupingCollector extends Collector {
public Weight getWeight() {
throw new UnsupportedOperationException();
}
@Override
public Collection<ChildScorer> getChildren() {
throw new UnsupportedOperationException();
}
}
private static final class OneGroup {

View File

@ -205,50 +205,6 @@ class TermsIncludingScoreQuery extends Query {
};
}
final static class FakeScorer extends Scorer {
float score;
int doc;
public FakeScorer() {
super(null);
}
@Override
public int advance(int target) {
throw new UnsupportedOperationException();
}
@Override
public int docID() {
return doc;
}
@Override
public int freq() {
throw new UnsupportedOperationException();
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException();
}
@Override
public float score() {
return score;
}
@Override
public long cost() {
throw new UnsupportedOperationException();
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
}
// This impl assumes that the 'join' values are used uniquely per doc per field. Used for one to many relations.
class SVInnerScorer extends BulkScorer {

View File

@ -325,51 +325,6 @@ public class ToParentBlockJoinCollector extends Collector {
}
}
private final static class FakeScorer extends Scorer {
float score;
int doc;
public FakeScorer() {
super(null);
}
@Override
public float score() {
return score;
}
@Override
public int freq() {
return 1; // TODO: does anything else make sense?... duplicate of grouping's FakeScorer btw?
}
@Override
public int docID() {
return doc;
}
@Override
public int advance(int target) {
throw new UnsupportedOperationException();
}
@Override
public int nextDoc() {
throw new UnsupportedOperationException();
}
@Override
public long cost() {
return 1;
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
}
private OneGroup[] sortedGroups;
private void sortQueue() {

View File

@ -17,6 +17,21 @@
package org.apache.solr.handler.component;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.ReaderUtil;
@ -28,6 +43,7 @@ import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.Weight;
import org.apache.lucene.search.grouping.GroupDocs;
import org.apache.lucene.search.grouping.SearchGroup;
import org.apache.lucene.search.grouping.TopGroups;
@ -83,22 +99,6 @@ import org.apache.solr.search.grouping.endresulttransformer.MainEndResultTransfo
import org.apache.solr.search.grouping.endresulttransformer.SimpleEndResultTransformer;
import org.apache.solr.util.SolrPluginUtils;
import org.apache.commons.lang.StringUtils;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* TODO!
*
@ -1227,5 +1227,15 @@ public class QueryComponent extends SearchComponent
public long cost() {
return 1;
}
@Override
public Weight getWeight() {
throw new UnsupportedOperationException();
}
@Override
public Collection<ChildScorer> getChildren() {
throw new UnsupportedOperationException();
}
}
}