You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/01/14 13:07:43 UTC
svn commit: r1432894 [2/2] - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/util/ lucene/facet/
lucene/facet/src/java/org/apache/lucene/facet/associations/
lucene/facet/src/java/org/apache/lucene/facet...
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java?rev=1432894&r1=1432893&r2=1432894&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java Mon Jan 14 12:07:42 2013
@@ -59,9 +59,8 @@ public abstract class BaseSampleTestTopK
return res;
}
- protected abstract FacetsAccumulator getSamplingAccumulator(Sampler sampler,
- TaxonomyReader taxoReader, IndexReader indexReader,
- FacetSearchParams searchParams);
+ protected abstract FacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader,
+ IndexReader indexReader, FacetSearchParams searchParams);
/**
* Try out faceted search with sampling enabled and complements either disabled or enforced
@@ -89,7 +88,7 @@ public abstract class BaseSampleTestTopK
// try several times in case of failure, because the test has a chance to fail
// if the top K facets are not sufficiently common with the sample set
- for (int nTrial=0; nTrial<RETRIES; nTrial++) {
+ for (int nTrial = 0; nTrial < RETRIES; nTrial++) {
try {
// complement with sampling!
final Sampler sampler = createSampler(nTrial, docCollector.getScoredDocIDs(), useRandomSampler);
@@ -99,7 +98,7 @@ public abstract class BaseSampleTestTopK
break; // succeeded
} catch (NotSameResultError e) {
- if (nTrial>=RETRIES-1) {
+ if (nTrial >= RETRIES - 1) {
throw e; // no more retries allowed, must fail
}
}
@@ -119,14 +118,11 @@ public abstract class BaseSampleTestTopK
assertSameResults(expected, sampledResults);
}
- private FacetsCollector samplingCollector(
- final boolean complement,
- final Sampler sampler,
+ private FacetsCollector samplingCollector(final boolean complement, final Sampler sampler,
FacetSearchParams samplingSearchParams) {
FacetsCollector samplingFC = new FacetsCollector(samplingSearchParams, indexReader, taxoReader) {
@Override
- protected FacetsAccumulator initFacetsAccumulator(
- FacetSearchParams facetSearchParams, IndexReader indexReader,
+ protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader,
TaxonomyReader taxonomyReader) {
FacetsAccumulator acc = getSamplingAccumulator(sampler, taxonomyReader, indexReader, facetSearchParams);
acc.setComplementThreshold(complement ? FacetsAccumulator.FORCE_COMPLEMENT : FacetsAccumulator.DISABLE_COMPLEMENT);
@@ -144,12 +140,13 @@ public abstract class BaseSampleTestTopK
samplingParams.setMinSampleSize((int) (100 * retryFactor));
samplingParams.setMaxSampleSize((int) (10000 * retryFactor));
samplingParams.setOversampleFactor(5.0 * retryFactor);
+ samplingParams.setSamplingThreshold(11000); //force sampling
- samplingParams.setSamplingThreshold(11000); //force sampling
Sampler sampler = useRandomSampler ?
new RandomSampler(samplingParams, new Random(random().nextLong())) :
new RepeatableSampler(samplingParams);
assertTrue("must enable sampling for this test!",sampler.shouldSample(scoredDocIDs));
return sampler;
}
+
}
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java?rev=1432894&r1=1432893&r2=1432894&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java Mon Jan 14 12:07:42 2013
@@ -9,6 +9,9 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.StringField;
+import org.apache.lucene.facet.search.ScoredDocIDs;
+import org.apache.lucene.facet.search.ScoredDocIDsIterator;
+import org.apache.lucene.facet.search.ScoredDocIdCollector;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiFields;
@@ -21,14 +24,9 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.OpenBitSet;
-import org.apache.lucene.util.OpenBitSetDISI;
-import org.junit.Test;
-
+import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.search.ScoredDocIDs;
-import org.apache.lucene.facet.search.ScoredDocIDsIterator;
-import org.apache.lucene.facet.search.ScoredDocIdCollector;
+import org.junit.Test;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -52,21 +50,21 @@ public class TestScoredDocIDsUtils exten
@Test
public void testComplementIterator() throws Exception {
final int n = atLeast(10000);
- final OpenBitSet bits = new OpenBitSet(n);
- for (int i = 0; i < 5 * n; i++) {
- bits.flip(random().nextInt(n));
+ final FixedBitSet bits = new FixedBitSet(n);
+ Random random = random();
+ for (int i = 0; i < n; i++) {
+ int idx = random.nextInt(n);
+ bits.flip(idx, idx + 1);
}
- OpenBitSet verify = new OpenBitSet(n);
- verify.or(bits);
+ FixedBitSet verify = new FixedBitSet(bits);
ScoredDocIDs scoredDocIDs = ScoredDocIdsUtils.createScoredDocIds(bits, n);
Directory dir = newDirectory();
- IndexReader reader = createReaderWithNDocs(random(), n, dir);
+ IndexReader reader = createReaderWithNDocs(random, n, dir);
try {
- assertEquals(n - verify.cardinality(), ScoredDocIdsUtils.getComplementSet(scoredDocIDs,
- reader).size());
+ assertEquals(n - verify.cardinality(), ScoredDocIdsUtils.getComplementSet(scoredDocIDs, reader).size());
} finally {
reader.close();
dir.close();
@@ -147,7 +145,7 @@ public class TestScoredDocIDsUtils exten
searcher.search(q, collector);
ScoredDocIDs scoredDocIds = collector.getScoredDocIDs();
- OpenBitSet resultSet = new OpenBitSetDISI(scoredDocIds.getDocIDs().iterator(), reader.maxDoc());
+ FixedBitSet resultSet = (FixedBitSet) scoredDocIds.getDocIDs();
// Getting the complement set of the query result
ScoredDocIDs complementSet = ScoredDocIdsUtils.getComplementSet(scoredDocIds, reader);
@@ -164,12 +162,11 @@ public class TestScoredDocIDsUtils exten
assertFalse(
"Complement-Set must not contain deleted documents (doc="+docNum+")",
live != null && !live.get(docNum));
- assertNull(
- "Complement-Set must not contain docs from the original set (doc="+ docNum+")",
+ assertNull("Complement-Set must not contain docs from the original set (doc="+ docNum+")",
reader.document(docNum).getField("del"));
assertFalse(
"Complement-Set must not contain docs from the original set (doc="+docNum+")",
- resultSet.fastGet(docNum));
+ resultSet.get(docNum));
}
} finally {
reader.close();