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/05/07 13:21:14 UTC
svn commit: r1479862 [20/38] - in /lucene/dev/branches/lucene4258: ./
dev-tools/ dev-tools/idea/.idea/ dev-tools/idea/.idea/libraries/
dev-tools/maven/ dev-tools/maven/solr/ dev-tools/maven/solr/core/src/java/
dev-tools/maven/solr/solrj/src/java/ dev-t...
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java Tue May 7 11:20:55 2013
@@ -78,7 +78,7 @@ public class TopGroups<GROUP_VALUE_TYPE>
Total,
/* Avg score across all shards for this group. */
Avg,
- };
+ }
/** Merges an array of TopGroups, for example obtained
* from the second-pass collector across multiple
@@ -202,7 +202,7 @@ public class TopGroups<GROUP_VALUE_TYPE>
}
//System.out.println("SHARDS=" + Arrays.toString(mergedTopDocs.shardIndex));
- mergedGroupDocs[groupIDX] = new GroupDocs<T>(groupScore,
+ mergedGroupDocs[groupIDX] = new GroupDocs<>(groupScore,
maxScore,
totalHits,
mergedScoreDocs,
@@ -212,15 +212,15 @@ public class TopGroups<GROUP_VALUE_TYPE>
}
if (totalGroupCount != null) {
- TopGroups<T> result = new TopGroups<T>(groupSort.getSort(),
+ TopGroups<T> result = new TopGroups<>(groupSort.getSort(),
docSort == null ? null : docSort.getSort(),
totalHitCount,
totalGroupedHitCount,
mergedGroupDocs,
totalMaxScore);
- return new TopGroups<T>(result, totalGroupCount);
+ return new TopGroups<>(result, totalGroupCount);
} else {
- return new TopGroups<T>(groupSort.getSort(),
+ return new TopGroups<>(groupSort.getSort(),
docSort == null ? null : docSort.getSort(),
totalHitCount,
totalGroupedHitCount,
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java Tue May 7 11:20:55 2013
@@ -59,7 +59,7 @@ public class FunctionAllGroupHeadsCollec
*/
public FunctionAllGroupHeadsCollector(ValueSource groupBy, Map<?, ?> vsContext, Sort sortWithinGroup) {
super(sortWithinGroup.getSort().length);
- groups = new HashMap<MutableValue, GroupHead>();
+ groups = new HashMap<>();
this.sortWithinGroup = sortWithinGroup;
this.groupBy = groupBy;
this.vsContext = vsContext;
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java Tue May 7 11:20:55 2013
@@ -48,7 +48,7 @@ public class FunctionDistinctValuesColle
this.vsContext = vsContext;
this.groupSource = groupSource;
this.countSource = countSource;
- groupMap = new LinkedHashMap<MutableValue, GroupCount>();
+ groupMap = new LinkedHashMap<>();
for (SearchGroup<MutableValue> group : groups) {
groupMap.put(group.groupValue, new GroupCount(group.groupValue));
}
@@ -56,7 +56,7 @@ public class FunctionDistinctValuesColle
@Override
public List<GroupCount> getGroups() {
- return new ArrayList<GroupCount>(groupMap.values());
+ return new ArrayList<>(groupMap.values());
}
@Override
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java Tue May 7 11:20:55 2013
@@ -17,16 +17,24 @@ package org.apache.lucene.search.groupin
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.*;
-
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.search.*;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
import org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.SentinelIntSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* A base implementation of {@link org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector} for retrieving the most relevant groups when grouping
* on a string based group field. More specifically this all concrete implementations of this base implementation
@@ -115,7 +123,7 @@ public abstract class TermAllGroupHeadsC
GeneralAllGroupHeadsCollector(String groupField, Sort sortWithinGroup) {
super(groupField, sortWithinGroup.getSort().length);
this.sortWithinGroup = sortWithinGroup;
- groups = new HashMap<BytesRef, GroupHead>();
+ groups = new HashMap<>();
final SortField[] sortFields = sortWithinGroup.getSort();
for (int i = 0; i < sortFields.length; i++) {
@@ -219,7 +227,7 @@ public abstract class TermAllGroupHeadsC
OrdScoreAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
super(groupField, sortWithinGroup.getSort().length);
ordSet = new SentinelIntSet(initialSize, -2);
- collectedGroups = new ArrayList<GroupHead>(initialSize);
+ collectedGroups = new ArrayList<>(initialSize);
final SortField[] sortFields = sortWithinGroup.getSort();
fields = new SortField[sortFields.length];
@@ -388,7 +396,7 @@ public abstract class TermAllGroupHeadsC
OrdAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
super(groupField, sortWithinGroup.getSort().length);
ordSet = new SentinelIntSet(initialSize, -2);
- collectedGroups = new ArrayList<GroupHead>(initialSize);
+ collectedGroups = new ArrayList<>(initialSize);
final SortField[] sortFields = sortWithinGroup.getSort();
fields = new SortField[sortFields.length];
@@ -531,7 +539,7 @@ public abstract class TermAllGroupHeadsC
ScoreAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
super(groupField, sortWithinGroup.getSort().length);
ordSet = new SentinelIntSet(initialSize, -2);
- collectedGroups = new ArrayList<GroupHead>(initialSize);
+ collectedGroups = new ArrayList<>(initialSize);
final SortField[] sortFields = sortWithinGroup.getSort();
fields = new SortField[sortFields.length];
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java Tue May 7 11:20:55 2013
@@ -17,11 +17,6 @@ package org.apache.lucene.search.groupin
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.search.FieldCache;
@@ -29,6 +24,11 @@ import org.apache.lucene.search.grouping
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.SentinelIntSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
/**
* A collector that collects all groups that match the
* query. Only the group value is collected, and the order
@@ -66,7 +66,7 @@ public class TermAllGroupsCollector exte
*/
public TermAllGroupsCollector(String groupField, int initialSize) {
ordSet = new SentinelIntSet(initialSize, -2);
- groups = new ArrayList<BytesRef>(initialSize);
+ groups = new ArrayList<>(initialSize);
this.groupField = groupField;
}
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java Tue May 7 11:20:55 2013
@@ -17,9 +17,6 @@ package org.apache.lucene.search.groupin
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.*;
-
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.search.FieldCache;
@@ -28,6 +25,12 @@ import org.apache.lucene.search.grouping
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.SentinelIntSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
/**
* A term based implementation of {@link org.apache.lucene.search.grouping.AbstractDistinctValuesCollector} that relies
* on {@link SortedDocValues} to count the distinct values per group.
@@ -55,7 +58,7 @@ public class TermDistinctValuesCollector
public TermDistinctValuesCollector(String groupField, String countField, Collection<SearchGroup<BytesRef>> groups) {
this.groupField = groupField;
this.countField = countField;
- this.groups = new ArrayList<GroupCount>(groups.size());
+ this.groups = new ArrayList<>(groups.size());
for (SearchGroup<BytesRef> group : groups) {
this.groups.add(new GroupCount(group.groupValue));
}
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java Tue May 7 11:20:55 2013
@@ -17,18 +17,19 @@ package org.apache.lucene.search.groupin
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.DocTermOrds;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.grouping.AbstractGroupFacetCollector;
-import org.apache.lucene.util.*;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.SentinelIntSet;
+import org.apache.lucene.util.UnicodeUtil;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
/**
* An implementation of {@link AbstractGroupFacetCollector} that computes grouped facets based on the indexed terms
@@ -70,7 +71,7 @@ public abstract class TermGroupFacetColl
TermGroupFacetCollector(String groupField, String facetField, BytesRef facetPrefix, int initialSize) {
super(groupField, facetField, facetPrefix);
- groupedFacetHits = new ArrayList<GroupedFacetHit>(initialSize);
+ groupedFacetHits = new ArrayList<>(initialSize);
segmentGroupedFacetHits = new SentinelIntSet(initialSize, Integer.MIN_VALUE);
}
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java Tue May 7 11:20:55 2013
@@ -17,11 +17,13 @@ package org.apache.lucene.search.groupin
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.*;
-
import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
+import org.apache.lucene.document.BinaryDocValuesField;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.IntField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.index.IndexReader;
@@ -30,7 +32,14 @@ import org.apache.lucene.index.SlowCompo
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
-import org.apache.lucene.search.*;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.QueryUtils;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.grouping.function.FunctionAllGroupHeadsCollector;
import org.apache.lucene.search.grouping.term.TermAllGroupHeadsCollector;
import org.apache.lucene.store.Directory;
@@ -39,6 +48,16 @@ import org.apache.lucene.util.FixedBitSe
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
public class AllGroupHeadsCollectorTest extends LuceneTestCase {
private static final DocValuesType[] vts = new DocValuesType[]{
@@ -112,7 +131,7 @@ public class AllGroupHeadsCollectorTest
w.addDocument(doc);
IndexReader reader = w.getReader();
- IndexSearcher indexSearcher = new IndexSearcher(reader);
+ IndexSearcher indexSearcher = newSearcher(reader);
if (SlowCompositeReaderWrapper.class.isAssignableFrom(reader.getClass())) {
canUseIDV = false;
}
@@ -121,30 +140,30 @@ public class AllGroupHeadsCollectorTest
int maxDoc = reader.maxDoc();
Sort sortWithinGroup = new Sort(new SortField("id", SortField.Type.INT, true));
- AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup, canUseIDV, valueType);
+ AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
assertTrue(openBitSetContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
- allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup, canUseIDV, valueType);
+ allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
indexSearcher.search(new TermQuery(new Term("content", "some")), allGroupHeadsCollector);
assertTrue(arrayContains(new int[]{2, 3, 4}, allGroupHeadsCollector.retrieveGroupHeads()));
assertTrue(openBitSetContains(new int[]{2, 3, 4}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
- allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup, canUseIDV, valueType);
+ allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
indexSearcher.search(new TermQuery(new Term("content", "blob")), allGroupHeadsCollector);
assertTrue(arrayContains(new int[]{1, 5}, allGroupHeadsCollector.retrieveGroupHeads()));
assertTrue(openBitSetContains(new int[]{1, 5}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
// STRING sort type triggers different implementation
Sort sortWithinGroup2 = new Sort(new SortField("id", SortField.Type.STRING, true));
- allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup2, canUseIDV, valueType);
+ allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup2);
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
assertTrue(openBitSetContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
Sort sortWithinGroup3 = new Sort(new SortField("id", SortField.Type.STRING, false));
- allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup3, canUseIDV, valueType);
+ allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup3);
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
// 7 b/c higher doc id wins, even if order of field is in not in reverse.
assertTrue(arrayContains(new int[]{0, 3, 4, 6}, allGroupHeadsCollector.retrieveGroupHeads()));
@@ -168,7 +187,7 @@ public class AllGroupHeadsCollectorTest
System.out.println("TEST: numDocs=" + numDocs + " numGroups=" + numGroups);
}
- final List<BytesRef> groups = new ArrayList<BytesRef>();
+ final List<BytesRef> groups = new ArrayList<>();
for (int i = 0; i < numGroups; i++) {
String randomValue;
do {
@@ -201,7 +220,6 @@ public class AllGroupHeadsCollectorTest
dir,
newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())));
- boolean canUseIDV = true;
DocValuesType valueType = vts[random().nextInt(vts.length)];
Document doc = new Document();
@@ -209,8 +227,7 @@ public class AllGroupHeadsCollectorTest
Field group = newStringField("group", "", Field.Store.NO);
doc.add(group);
Field valuesField = null;
- if (canUseIDV) {
- switch(valueType) {
+ switch(valueType) {
case BINARY:
valuesField = new BinaryDocValuesField("group_dv", new BytesRef());
break;
@@ -219,9 +236,8 @@ public class AllGroupHeadsCollectorTest
break;
default:
fail("unhandled type");
- }
- doc.add(valuesField);
}
+ doc.add(valuesField);
Field sort1 = newStringField("sort1", "", Field.Store.NO);
doc.add(sort1);
docNoGroup.add(sort1);
@@ -264,9 +280,7 @@ public class AllGroupHeadsCollectorTest
groupDocs[i] = groupDoc;
if (groupDoc.group != null) {
group.setStringValue(groupDoc.group.utf8ToString());
- if (canUseIDV) {
- valuesField.setBytesValue(new BytesRef(groupDoc.group.utf8ToString()));
- }
+ valuesField.setBytesValue(new BytesRef(groupDoc.group.utf8ToString()));
}
sort1.setStringValue(groupDoc.sort1.utf8ToString());
sort2.setStringValue(groupDoc.sort2.utf8ToString());
@@ -293,11 +307,6 @@ public class AllGroupHeadsCollectorTest
try {
final IndexSearcher s = newSearcher(r);
- if (SlowCompositeReaderWrapper.class.isAssignableFrom(s.getIndexReader().getClass())) {
- canUseIDV = false;
- } else {
- canUseIDV = true;
- }
for (int contentID = 0; contentID < 3; contentID++) {
final ScoreDoc[] hits = s.search(new TermQuery(new Term("content", "real" + contentID)), numDocs).scoreDocs;
@@ -323,7 +332,7 @@ public class AllGroupHeadsCollectorTest
final String searchTerm = "real" + random().nextInt(3);
boolean sortByScoreOnly = random().nextBoolean();
Sort sortWithinGroup = getRandomSort(sortByScoreOnly);
- AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector("group", sortWithinGroup, canUseIDV, valueType);
+ AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector("group", sortWithinGroup);
s.search(new TermQuery(new Term("content", searchTerm)), allGroupHeadsCollector);
int[] expectedGroupHeads = createExpectedGroupHeads(searchTerm, groupDocs, sortWithinGroup, sortByScoreOnly, fieldIdToDocID);
int[] actualGroupHeads = allGroupHeadsCollector.retrieveGroupHeads();
@@ -426,14 +435,14 @@ public class AllGroupHeadsCollectorTest
}
private int[] createExpectedGroupHeads(String searchTerm, GroupDoc[] groupDocs, Sort docSort, boolean sortByScoreOnly, int[] fieldIdToDocID) {
- Map<BytesRef, List<GroupDoc>> groupHeads = new HashMap<BytesRef, List<GroupDoc>>();
+ Map<BytesRef, List<GroupDoc>> groupHeads = new HashMap<>();
for (GroupDoc groupDoc : groupDocs) {
if (!groupDoc.content.startsWith(searchTerm)) {
continue;
}
if (!groupHeads.containsKey(groupDoc.group)) {
- List<GroupDoc> list = new ArrayList<GroupDoc>();
+ List<GroupDoc> list = new ArrayList<>();
list.add(groupDoc);
groupHeads.put(groupDoc.group, list);
continue;
@@ -453,7 +462,7 @@ public class AllGroupHeadsCollectorTest
}
private Sort getRandomSort(boolean scoreOnly) {
- final List<SortField> sortFields = new ArrayList<SortField>();
+ final List<SortField> sortFields = new ArrayList<>();
if (random().nextInt(7) == 2 || scoreOnly) {
sortFields.add(SortField.FIELD_SCORE);
} else {
@@ -514,11 +523,11 @@ public class AllGroupHeadsCollectorTest
}
@SuppressWarnings({"unchecked","rawtypes"})
- private AbstractAllGroupHeadsCollector<?> createRandomCollector(String groupField, Sort sortWithinGroup, boolean canUseIDV, DocValuesType valueType) {
+ private AbstractAllGroupHeadsCollector<?> createRandomCollector(String groupField, Sort sortWithinGroup) {
AbstractAllGroupHeadsCollector<? extends AbstractAllGroupHeadsCollector.GroupHead> collector;
if (random().nextBoolean()) {
ValueSource vs = new BytesRefFieldSource(groupField);
- collector = new FunctionAllGroupHeadsCollector(vs, new HashMap<Object, Object>(), sortWithinGroup);
+ collector = new FunctionAllGroupHeadsCollector(vs, new HashMap<>(), sortWithinGroup);
} else {
collector = TermAllGroupHeadsCollector.create(groupField, sortWithinGroup);
}
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java Tue May 7 11:20:55 2013
@@ -18,10 +18,13 @@ package org.apache.lucene.search.groupin
*/
import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
import org.apache.lucene.search.IndexSearcher;
@@ -48,25 +51,24 @@ public class AllGroupsCollectorTest exte
dir,
newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
- boolean canUseIDV = true;
// 0
Document doc = new Document();
- addGroupField(doc, groupField, "author1", canUseIDV);
+ addGroupField(doc, groupField, "author1");
doc.add(new TextField("content", "random text", Field.Store.YES));
doc.add(new Field("id", "1", customType));
w.addDocument(doc);
// 1
doc = new Document();
- addGroupField(doc, groupField, "author1", canUseIDV);
+ addGroupField(doc, groupField, "author1");
doc.add(new TextField("content", "some more random text blob", Field.Store.YES));
doc.add(new Field("id", "2", customType));
w.addDocument(doc);
// 2
doc = new Document();
- addGroupField(doc, groupField, "author1", canUseIDV);
+ addGroupField(doc, groupField, "author1");
doc.add(new TextField("content", "some more random textual data", Field.Store.YES));
doc.add(new Field("id", "3", customType));
w.addDocument(doc);
@@ -74,21 +76,21 @@ public class AllGroupsCollectorTest exte
// 3
doc = new Document();
- addGroupField(doc, groupField, "author2", canUseIDV);
+ addGroupField(doc, groupField, "author2");
doc.add(new TextField("content", "some random text", Field.Store.YES));
doc.add(new Field("id", "4", customType));
w.addDocument(doc);
// 4
doc = new Document();
- addGroupField(doc, groupField, "author3", canUseIDV);
+ addGroupField(doc, groupField, "author3");
doc.add(new TextField("content", "some more random text", Field.Store.YES));
doc.add(new Field("id", "5", customType));
w.addDocument(doc);
// 5
doc = new Document();
- addGroupField(doc, groupField, "author3", canUseIDV);
+ addGroupField(doc, groupField, "author3");
doc.add(new TextField("content", "random blob", Field.Store.YES));
doc.add(new Field("id", "6", customType));
w.addDocument(doc);
@@ -99,18 +101,18 @@ public class AllGroupsCollectorTest exte
doc.add(new Field("id", "6", customType));
w.addDocument(doc);
- IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+ IndexSearcher indexSearcher = newSearcher(w.getReader());
w.close();
- AbstractAllGroupsCollector<?> allGroupsCollector = createRandomCollector(groupField, canUseIDV);
+ AbstractAllGroupsCollector<?> allGroupsCollector = createRandomCollector(groupField);
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupsCollector);
assertEquals(4, allGroupsCollector.getGroupCount());
- allGroupsCollector = createRandomCollector(groupField, canUseIDV);
+ allGroupsCollector = createRandomCollector(groupField);
indexSearcher.search(new TermQuery(new Term("content", "some")), allGroupsCollector);
assertEquals(3, allGroupsCollector.getGroupCount());
- allGroupsCollector = createRandomCollector(groupField, canUseIDV);
+ allGroupsCollector = createRandomCollector(groupField);
indexSearcher.search(new TermQuery(new Term("content", "blob")), allGroupsCollector);
assertEquals(2, allGroupsCollector.getGroupCount());
@@ -118,20 +120,18 @@ public class AllGroupsCollectorTest exte
dir.close();
}
- private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV) {
+ private void addGroupField(Document doc, String groupField, String value) {
doc.add(new TextField(groupField, value, Field.Store.YES));
- if (canUseIDV) {
- doc.add(new SortedDocValuesField(groupField, new BytesRef(value)));
- }
+ doc.add(new SortedDocValuesField(groupField, new BytesRef(value)));
}
- private AbstractAllGroupsCollector<?> createRandomCollector(String groupField, boolean canUseIDV) {
+ private AbstractAllGroupsCollector<?> createRandomCollector(String groupField) {
AbstractAllGroupsCollector<?> selected;
if (random().nextBoolean()) {
selected = new TermAllGroupsCollector(groupField);
} else {
ValueSource vs = new BytesRefFieldSource(groupField);
- selected = new FunctionAllGroupsCollector(vs, new HashMap<Object, Object>());
+ selected = new FunctionAllGroupsCollector(vs, new HashMap<>());
}
if (VERBOSE) {
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java Tue May 7 11:20:55 2013
@@ -17,13 +17,19 @@ package org.apache.lucene.search.groupin
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.*;
-
import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
-import org.apache.lucene.index.*;
+import org.apache.lucene.document.BinaryDocValuesField;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInfo.DocValuesType;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.StoredDocument;
+import org.apache.lucene.index.Term;
import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Sort;
@@ -39,6 +45,20 @@ import org.apache.lucene.util._TestUtil;
import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueStr;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
public class DistinctValuesCollectorTest extends AbstractGroupingTestCase {
private final static NullComparator nullComparator = new NullComparator();
@@ -267,9 +287,9 @@ public class DistinctValuesCollectorTest
AbstractDistinctValuesCollector.GroupCount<Comparable<?>> actual = actualResult.get(i);
assertValues(expected.groupValue, actual.groupValue);
assertEquals(expected.uniqueValues.size(), actual.uniqueValues.size());
- List<Comparable<?>> expectedUniqueValues = new ArrayList<Comparable<?>>(expected.uniqueValues);
+ List<Comparable<?>> expectedUniqueValues = new ArrayList<>(expected.uniqueValues);
Collections.sort(expectedUniqueValues, nullComparator);
- List<Comparable<?>> actualUniqueValues = new ArrayList<Comparable<?>>(actual.uniqueValues);
+ List<Comparable<?>> actualUniqueValues = new ArrayList<>(actual.uniqueValues);
Collections.sort(actualUniqueValues, nullComparator);
for (int j = 0; j < expectedUniqueValues.size(); j++) {
assertValues(expectedUniqueValues.get(j), actualUniqueValues.get(j));
@@ -373,7 +393,7 @@ public class DistinctValuesCollectorTest
Random random = random();
Collection<SearchGroup<T>> searchGroups = firstPassGroupingCollector.getTopGroups(0, false);
if (FunctionFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
- return (AbstractDistinctValuesCollector) new FunctionDistinctValuesCollector(new HashMap<Object, Object>(), new BytesRefFieldSource(groupField), new BytesRefFieldSource(countField), (Collection) searchGroups);
+ return (AbstractDistinctValuesCollector) new FunctionDistinctValuesCollector(new HashMap<>(), new BytesRefFieldSource(groupField), new BytesRefFieldSource(countField), (Collection) searchGroups);
} else {
return (AbstractDistinctValuesCollector) new TermDistinctValuesCollector(groupField, countField, (Collection) searchGroups);
}
@@ -384,13 +404,13 @@ public class DistinctValuesCollectorTest
Random random = random();
if (dvType != null) {
if (random.nextBoolean()) {
- return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<Object, Object>(), groupSort, topNGroups);
+ return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<>(), groupSort, topNGroups);
} else {
return (AbstractFirstPassGroupingCollector<T>) new TermFirstPassGroupingCollector(groupField, groupSort, topNGroups);
}
} else {
if (random.nextBoolean()) {
- return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<Object, Object>(), groupSort, topNGroups);
+ return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<>(), groupSort, topNGroups);
} else {
return (AbstractFirstPassGroupingCollector<T>) new TermFirstPassGroupingCollector(groupField, groupSort, topNGroups);
}
@@ -413,7 +433,7 @@ public class DistinctValuesCollectorTest
if (topN <= i++) {
break;
}
- Set<BytesRef> uniqueValues = new HashSet<BytesRef>();
+ Set<BytesRef> uniqueValues = new HashSet<>();
for (String val : groupCounts.get(group)) {
uniqueValues.add(val != null ? new BytesRef(val) : null);
}
@@ -450,8 +470,8 @@ public class DistinctValuesCollectorTest
countValues[i] = generateRandomNonEmptyString();
}
- List<String> contentStrings = new ArrayList<String>();
- Map<String, Map<String, Set<String>>> searchTermToGroupCounts = new HashMap<String, Map<String, Set<String>>>();
+ List<String> contentStrings = new ArrayList<>();
+ Map<String, Map<String, Set<String>>> searchTermToGroupCounts = new HashMap<>();
for (int i = 1; i <= numDocs; i++) {
String groupValue = random.nextInt(23) == 14 ? null : groupValues[random.nextInt(groupValues.length)];
String countValue = random.nextInt(21) == 13 ? null : countValues[random.nextInt(countValues.length)];
@@ -459,13 +479,13 @@ public class DistinctValuesCollectorTest
Map<String, Set<String>> groupToCounts = searchTermToGroupCounts.get(content);
if (groupToCounts == null) {
// Groups sort always DOCID asc...
- searchTermToGroupCounts.put(content, groupToCounts = new LinkedHashMap<String, Set<String>>());
+ searchTermToGroupCounts.put(content, groupToCounts = new LinkedHashMap<>());
contentStrings.add(content);
}
Set<String> countsVals = groupToCounts.get(groupValue);
if (countsVals == null) {
- groupToCounts.put(groupValue, countsVals = new HashSet<String>());
+ groupToCounts.put(groupValue, countsVals = new HashSet<>());
}
countsVals.add(countValue);
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java Tue May 7 11:20:55 2013
@@ -18,7 +18,11 @@ package org.apache.lucene.search.groupin
*/
import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.RandomIndexWriter;
@@ -28,12 +32,22 @@ import org.apache.lucene.search.MatchAll
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.grouping.term.TermGroupFacetCollector;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util._TestUtil;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.TreeSet;
public class GroupFacetCollectorTest extends AbstractGroupingTestCase {
@@ -48,8 +62,7 @@ public class GroupFacetCollectorTest ext
dir,
newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
- boolean canUseDV = true;
- boolean useDv = canUseDV && random().nextBoolean();
+ boolean useDv = random().nextBoolean();
// 0
Document doc = new Document();
@@ -87,20 +100,41 @@ public class GroupFacetCollectorTest ext
addField(doc, "duration", "5", useDv);
w.addDocument(doc);
- IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
- AbstractGroupFacetCollector groupedAirportFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "airport_dv" : "airport", null, false);
- indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
- TermGroupFacetCollector.GroupedFacetResult airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
- assertEquals(3, airportResult.getTotalCount());
- assertEquals(0, airportResult.getTotalMissingCount());
+ IndexSearcher indexSearcher = newSearcher(w.getReader());
- List<TermGroupFacetCollector.FacetEntry> entries = airportResult.getFacetEntries(0, 10);
- assertEquals(2, entries.size());
- assertEquals("ams", entries.get(0).getValue().utf8ToString());
- assertEquals(2, entries.get(0).getCount());
- assertEquals("dus", entries.get(1).getValue().utf8ToString());
- assertEquals(1, entries.get(1).getCount());
+ List<TermGroupFacetCollector.FacetEntry> entries;
+ AbstractGroupFacetCollector groupedAirportFacetCollector;
+ TermGroupFacetCollector.GroupedFacetResult airportResult;
+
+ for (int limit : new int[] { 2, 10, 100, Integer.MAX_VALUE }) {
+ // any of these limits is plenty for the data we have
+
+ groupedAirportFacetCollector = createRandomCollector
+ (useDv ? "hotel_dv" : "hotel",
+ useDv ? "airport_dv" : "airport", null, false);
+ indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
+ int maxOffset = 5;
+ airportResult = groupedAirportFacetCollector.mergeSegmentResults
+ (Integer.MAX_VALUE == limit ? limit : maxOffset + limit, 0, false);
+
+ assertEquals(3, airportResult.getTotalCount());
+ assertEquals(0, airportResult.getTotalMissingCount());
+
+ entries = airportResult.getFacetEntries(maxOffset, limit);
+ assertEquals(0, entries.size());
+ entries = airportResult.getFacetEntries(0, limit);
+ assertEquals(2, entries.size());
+ assertEquals("ams", entries.get(0).getValue().utf8ToString());
+ assertEquals(2, entries.get(0).getCount());
+ assertEquals("dus", entries.get(1).getValue().utf8ToString());
+ assertEquals(1, entries.get(1).getCount());
+
+ entries = airportResult.getFacetEntries(1, limit);
+ assertEquals(1, entries.size());
+ assertEquals("dus", entries.get(0).getValue().utf8ToString());
+ assertEquals(1, entries.get(0).getCount());
+ }
AbstractGroupFacetCollector groupedDurationFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "duration_dv" : "duration", null, false);
indexSearcher.search(new MatchAllDocsQuery(), groupedDurationFacetCollector);
@@ -147,7 +181,7 @@ public class GroupFacetCollectorTest ext
w.addDocument(doc);
indexSearcher.getIndexReader().close();
- indexSearcher = new IndexSearcher(w.getReader());
+ indexSearcher = newSearcher(w.getReader());
groupedAirportFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "airport_dv" : "airport", null, !useDv);
indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
airportResult = groupedAirportFacetCollector.mergeSegmentResults(3, 0, true);
@@ -195,7 +229,7 @@ public class GroupFacetCollectorTest ext
w.addDocument(doc);
indexSearcher.getIndexReader().close();
- indexSearcher = new IndexSearcher(w.getReader());
+ indexSearcher = newSearcher(w.getReader());
groupedAirportFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "airport_dv" : "airport", null, false);
indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
@@ -311,7 +345,7 @@ public class GroupFacetCollectorTest ext
w.commit();
w.close();
- IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(dir));
+ IndexSearcher indexSearcher = newSearcher(DirectoryReader.open(dir));
AbstractGroupFacetCollector groupedAirportFacetCollector = createRandomCollector(groupField, "airport", null, true);
indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
TermGroupFacetCollector.GroupedFacetResult airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
@@ -452,11 +486,11 @@ public class GroupFacetCollectorTest ext
System.out.println("TEST: numDocs=" + numDocs + " numGroups=" + numGroups);
}
- final List<String> groups = new ArrayList<String>();
+ final List<String> groups = new ArrayList<>();
for (int i = 0; i < numGroups; i++) {
groups.add(generateRandomNonEmptyString());
}
- final List<String> facetValues = new ArrayList<String>();
+ final List<String> facetValues = new ArrayList<>();
for (int i = 0; i < numFacets; i++) {
facetValues.add(generateRandomNonEmptyString());
}
@@ -519,7 +553,7 @@ public class GroupFacetCollectorTest ext
docNoFacet.add(content);
docNoGroupNoFacet.add(content);
- NavigableSet<String> uniqueFacetValues = new TreeSet<String>(new Comparator<String>() {
+ NavigableSet<String> uniqueFacetValues = new TreeSet<>(new Comparator<String>() {
@Override
public int compare(String a, String b) {
@@ -535,7 +569,7 @@ public class GroupFacetCollectorTest ext
}
});
- Map<String, Map<String, Set<String>>> searchTermToFacetToGroups = new HashMap<String, Map<String, Set<String>>>();
+ Map<String, Map<String, Set<String>>> searchTermToFacetToGroups = new HashMap<>();
int facetWithMostGroups = 0;
for (int i = 0; i < numDocs; i++) {
final String groupValue;
@@ -557,7 +591,7 @@ public class GroupFacetCollectorTest ext
}
Map<String, Set<String>> facetToGroups = searchTermToFacetToGroups.get(contentStr);
- List<String> facetVals = new ArrayList<String>();
+ List<String> facetVals = new ArrayList<>();
if (useDv || random.nextInt(24) != 18) {
if (useDv) {
String facetValue = facetValues.get(random.nextInt(facetValues.size()));
@@ -635,14 +669,14 @@ public class GroupFacetCollectorTest ext
private GroupedFacetResult createExpectedFacetResult(String searchTerm, IndexContext context, int offset, int limit, int minCount, final boolean orderByCount, String facetPrefix) {
Map<String, Set<String>> facetGroups = context.searchTermToFacetGroups.get(searchTerm);
if (facetGroups == null) {
- facetGroups = new HashMap<String, Set<String>>();
+ facetGroups = new HashMap<>();
}
int totalCount = 0;
int totalMissCount = 0;
Set<String> facetValues;
if (facetPrefix != null) {
- facetValues = new HashSet<String>();
+ facetValues = new HashSet<>();
for (String facetValue : context.facetValues) {
if (facetValue != null && facetValue.startsWith(facetPrefix)) {
facetValues.add(facetValue);
@@ -652,7 +686,7 @@ public class GroupFacetCollectorTest ext
facetValues = context.facetValues;
}
- List<TermGroupFacetCollector.FacetEntry> entries = new ArrayList<TermGroupFacetCollector.FacetEntry>(facetGroups.size());
+ List<TermGroupFacetCollector.FacetEntry> entries = new ArrayList<>(facetGroups.size());
// also includes facets with count 0
for (String facetValue : facetValues) {
if (facetValue == null) {
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java Tue May 7 11:20:55 2013
@@ -60,7 +60,7 @@ public class GroupingSearchTest extends
newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
boolean canUseIDV = true;
- List<Document> documents = new ArrayList<Document>();
+ List<Document> documents = new ArrayList<>();
// 0
Document doc = new Document();
addGroupField(doc, groupField, "author1", canUseIDV);
@@ -118,7 +118,7 @@ public class GroupingSearchTest extends
w.addDocument(doc);
- IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+ IndexSearcher indexSearcher = newSearcher(w.getReader());
w.close();
Sort groupSort = Sort.RELEVANCE;
@@ -207,7 +207,7 @@ public class GroupingSearchTest extends
GroupingSearch groupingSearch;
if (random().nextBoolean()) {
ValueSource vs = new BytesRefFieldSource(groupField);
- groupingSearch = new GroupingSearch(vs, new HashMap<Object, Object>());
+ groupingSearch = new GroupingSearch(vs, new HashMap<>());
} else {
groupingSearch = new GroupingSearch(groupField);
}
@@ -233,7 +233,7 @@ public class GroupingSearchTest extends
doc.add(newField("group", "foo", StringField.TYPE_NOT_STORED));
w.addDocument(doc);
- IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+ IndexSearcher indexSearcher = newSearcher(w.getReader());
w.close();
GroupingSearch gs = new GroupingSearch("group");
Modified: lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java (original)
+++ lucene/dev/branches/lucene4258/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java Tue May 7 11:20:55 2013
@@ -67,45 +67,44 @@ public class TestGrouping extends Lucene
dir,
newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
- boolean canUseIDV = true;
// 0
Document doc = new Document();
- addGroupField(doc, groupField, "author1", canUseIDV);
+ addGroupField(doc, groupField, "author1");
doc.add(new TextField("content", "random text", Field.Store.YES));
doc.add(new Field("id", "1", customType));
w.addDocument(doc);
// 1
doc = new Document();
- addGroupField(doc, groupField, "author1", canUseIDV);
+ addGroupField(doc, groupField, "author1");
doc.add(new TextField("content", "some more random text", Field.Store.YES));
doc.add(new Field("id", "2", customType));
w.addDocument(doc);
// 2
doc = new Document();
- addGroupField(doc, groupField, "author1", canUseIDV);
+ addGroupField(doc, groupField, "author1");
doc.add(new TextField("content", "some more random textual data", Field.Store.YES));
doc.add(new Field("id", "3", customType));
w.addDocument(doc);
// 3
doc = new Document();
- addGroupField(doc, groupField, "author2", canUseIDV);
+ addGroupField(doc, groupField, "author2");
doc.add(new TextField("content", "some random text", Field.Store.YES));
doc.add(new Field("id", "4", customType));
w.addDocument(doc);
// 4
doc = new Document();
- addGroupField(doc, groupField, "author3", canUseIDV);
+ addGroupField(doc, groupField, "author3");
doc.add(new TextField("content", "some more random text", Field.Store.YES));
doc.add(new Field("id", "5", customType));
w.addDocument(doc);
// 5
doc = new Document();
- addGroupField(doc, groupField, "author3", canUseIDV);
+ addGroupField(doc, groupField, "author3");
doc.add(new TextField("content", "random", Field.Store.YES));
doc.add(new Field("id", "6", customType));
w.addDocument(doc);
@@ -116,12 +115,12 @@ public class TestGrouping extends Lucene
doc.add(new Field("id", "6", customType));
w.addDocument(doc);
- IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+ IndexSearcher indexSearcher = newSearcher(w.getReader());
w.close();
final Sort groupSort = Sort.RELEVANCE;
- if (canUseIDV && random().nextBoolean()) {
+ if (random().nextBoolean()) {
groupField += "_dv";
}
@@ -172,18 +171,16 @@ public class TestGrouping extends Lucene
dir.close();
}
- private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV) {
+ private void addGroupField(Document doc, String groupField, String value) {
doc.add(new TextField(groupField, value, Field.Store.YES));
- if (canUseIDV) {
- doc.add(new SortedDocValuesField(groupField + "_dv", new BytesRef(value)));
- }
+ doc.add(new SortedDocValuesField(groupField + "_dv", new BytesRef(value)));
}
private AbstractFirstPassGroupingCollector<?> createRandomFirstPassCollector(String groupField, Sort groupSort, int topDocs) throws IOException {
AbstractFirstPassGroupingCollector<?> selected;
if (random().nextBoolean()) {
ValueSource vs = new BytesRefFieldSource(groupField);
- selected = new FunctionFirstPassGroupingCollector(vs, new HashMap<Object, Object>(), groupSort, topDocs);
+ selected = new FunctionFirstPassGroupingCollector(vs, new HashMap<>(), groupSort, topDocs);
} else {
selected = new TermFirstPassGroupingCollector(groupField, groupSort, topDocs);
}
@@ -196,7 +193,7 @@ public class TestGrouping extends Lucene
private AbstractFirstPassGroupingCollector<?> createFirstPassCollector(String groupField, Sort groupSort, int topDocs, AbstractFirstPassGroupingCollector<?> firstPassGroupingCollector) throws IOException {
if (TermFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
ValueSource vs = new BytesRefFieldSource(groupField);
- return new FunctionFirstPassGroupingCollector(vs, new HashMap<Object, Object>(), groupSort, topDocs);
+ return new FunctionFirstPassGroupingCollector(vs, new HashMap<>(), groupSort, topDocs);
} else {
return new TermFirstPassGroupingCollector(groupField, groupSort, topDocs);
}
@@ -238,9 +235,9 @@ public class TestGrouping extends Lucene
return new TermSecondPassGroupingCollector(groupField, searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup , getScores, getMaxScores, fillSortFields);
} else {
ValueSource vs = new BytesRefFieldSource(groupField);
- List<SearchGroup<MutableValue>> mvalSearchGroups = new ArrayList<SearchGroup<MutableValue>>(searchGroups.size());
+ List<SearchGroup<MutableValue>> mvalSearchGroups = new ArrayList<>(searchGroups.size());
for (SearchGroup<BytesRef> mergedTopGroup : searchGroups) {
- SearchGroup<MutableValue> sg = new SearchGroup<MutableValue>();
+ SearchGroup<MutableValue> sg = new SearchGroup<>();
MutableValueStr groupValue = new MutableValueStr();
if (mergedTopGroup.groupValue != null) {
groupValue.value = mergedTopGroup.groupValue;
@@ -253,7 +250,7 @@ public class TestGrouping extends Lucene
mvalSearchGroups.add(sg);
}
- return new FunctionSecondPassGroupingCollector(mvalSearchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields, vs, new HashMap<Object, Object>());
+ return new FunctionSecondPassGroupingCollector(mvalSearchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields, vs, new HashMap<>());
}
}
@@ -263,7 +260,7 @@ public class TestGrouping extends Lucene
return new TermAllGroupsCollector(groupField);
} else {
ValueSource vs = new BytesRefFieldSource(groupField);
- return new FunctionAllGroupsCollector(vs, new HashMap<Object, Object>());
+ return new FunctionAllGroupsCollector(vs, new HashMap<>());
}
}
@@ -299,9 +296,9 @@ public class TestGrouping extends Lucene
return null;
}
- List<SearchGroup<BytesRef>> groups = new ArrayList<SearchGroup<BytesRef>>(mutableValueGroups.size());
+ List<SearchGroup<BytesRef>> groups = new ArrayList<>(mutableValueGroups.size());
for (SearchGroup<MutableValue> mutableValueGroup : mutableValueGroups) {
- SearchGroup<BytesRef> sg = new SearchGroup<BytesRef>();
+ SearchGroup<BytesRef> sg = new SearchGroup<>();
sg.groupValue = mutableValueGroup.groupValue.exists() ? ((MutableValueStr) mutableValueGroup.groupValue).value : null;
sg.sortValues = mutableValueGroup.sortValues;
groups.add(sg);
@@ -318,10 +315,10 @@ public class TestGrouping extends Lucene
return ((TermSecondPassGroupingCollector) c).getTopGroups(withinGroupOffset);
} else if (c.getClass().isAssignableFrom(FunctionSecondPassGroupingCollector.class)) {
TopGroups<MutableValue> mvalTopGroups = ((FunctionSecondPassGroupingCollector) c).getTopGroups(withinGroupOffset);
- List<GroupDocs<BytesRef>> groups = new ArrayList<GroupDocs<BytesRef>>(mvalTopGroups.groups.length);
+ List<GroupDocs<BytesRef>> groups = new ArrayList<>(mvalTopGroups.groups.length);
for (GroupDocs<MutableValue> mvalGd : mvalTopGroups.groups) {
BytesRef groupValue = mvalGd.groupValue.exists() ? ((MutableValueStr) mvalGd.groupValue).value : null;
- groups.add(new GroupDocs<BytesRef>(Float.NaN, mvalGd.maxScore, mvalGd.totalHits, mvalGd.scoreDocs, groupValue, mvalGd.groupSortValues));
+ groups.add(new GroupDocs<>(Float.NaN, mvalGd.maxScore, mvalGd.totalHits, mvalGd.scoreDocs, groupValue, mvalGd.groupSortValues));
}
return new TopGroups<BytesRef>(mvalTopGroups.groupSort, mvalTopGroups.withinGroupSort, mvalTopGroups.totalHitCount, mvalTopGroups.totalGroupedHitCount, groups.toArray(new GroupDocs[groups.size()]), Float.NaN);
}
@@ -349,7 +346,7 @@ public class TestGrouping extends Lucene
}
private Sort getRandomSort() {
- final List<SortField> sortFields = new ArrayList<SortField>();
+ final List<SortField> sortFields = new ArrayList<>();
if (random().nextInt(7) == 2) {
sortFields.add(SortField.FIELD_SCORE);
} else {
@@ -411,14 +408,14 @@ public class TestGrouping extends Lucene
final Comparable<?> c;
final SortField sf = sortFields[fieldIDX];
if (sf.getType() == SortField.Type.SCORE) {
- c = new Float(d.score);
+ c = d.score;
} else if (sf.getField().equals("sort1")) {
c = d.sort1;
} else if (sf.getField().equals("sort2")) {
c = d.sort2;
} else {
assertEquals("id", sf.getField());
- c = new Integer(d.id);
+ c = d.id;
}
fields[fieldIDX] = c;
}
@@ -449,12 +446,12 @@ public class TestGrouping extends Lucene
final Comparator<GroupDoc> groupSortComp = getComparator(groupSort);
Arrays.sort(groupDocs, groupSortComp);
- final HashMap<BytesRef,List<GroupDoc>> groups = new HashMap<BytesRef,List<GroupDoc>>();
- final List<BytesRef> sortedGroups = new ArrayList<BytesRef>();
- final List<Comparable<?>[]> sortedGroupFields = new ArrayList<Comparable<?>[]>();
+ final HashMap<BytesRef,List<GroupDoc>> groups = new HashMap<>();
+ final List<BytesRef> sortedGroups = new ArrayList<>();
+ final List<Comparable<?>[]> sortedGroupFields = new ArrayList<>();
int totalHitCount = 0;
- Set<BytesRef> knownGroups = new HashSet<BytesRef>();
+ Set<BytesRef> knownGroups = new HashSet<>();
//System.out.println("TEST: slowGrouping");
for(GroupDoc d : groupDocs) {
@@ -479,7 +476,7 @@ public class TestGrouping extends Lucene
if (fillFields) {
sortedGroupFields.add(fillFields(d, groupSort));
}
- l = new ArrayList<GroupDoc>();
+ l = new ArrayList<>();
groups.put(d.group, l);
}
l.add(d);
@@ -519,7 +516,7 @@ public class TestGrouping extends Lucene
hits = new ScoreDoc[0];
}
- result[idx-groupOffset] = new GroupDocs<BytesRef>(Float.NaN,
+ result[idx-groupOffset] = new GroupDocs<>(Float.NaN,
0.0f,
docs.size(),
hits,
@@ -528,20 +525,20 @@ public class TestGrouping extends Lucene
}
if (doAllGroups) {
- return new TopGroups<BytesRef>(
- new TopGroups<BytesRef>(groupSort.getSort(), docSort.getSort(), totalHitCount, totalGroupedHitCount, result, Float.NaN),
- knownGroups.size()
+ return new TopGroups<>(
+ new TopGroups<>(groupSort.getSort(), docSort.getSort(), totalHitCount, totalGroupedHitCount, result, Float.NaN),
+ knownGroups.size()
);
} else {
- return new TopGroups<BytesRef>(groupSort.getSort(), docSort.getSort(), totalHitCount, totalGroupedHitCount, result, Float.NaN);
+ return new TopGroups<>(groupSort.getSort(), docSort.getSort(), totalHitCount, totalGroupedHitCount, result, Float.NaN);
}
}
private DirectoryReader getDocBlockReader(Directory dir, GroupDoc[] groupDocs) throws IOException {
// Coalesce by group, but in random order:
Collections.shuffle(Arrays.asList(groupDocs), random());
- final Map<BytesRef,List<GroupDoc>> groupMap = new HashMap<BytesRef,List<GroupDoc>>();
- final List<BytesRef> groupValues = new ArrayList<BytesRef>();
+ final Map<BytesRef,List<GroupDoc>> groupMap = new HashMap<>();
+ final List<BytesRef> groupValues = new ArrayList<>();
for(GroupDoc groupDoc : groupDocs) {
if (!groupMap.containsKey(groupDoc.group)) {
@@ -557,7 +554,7 @@ public class TestGrouping extends Lucene
newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())));
- final List<List<Document>> updateDocs = new ArrayList<List<Document>>();
+ final List<List<Document>> updateDocs = new ArrayList<>();
FieldType groupEndType = new FieldType(StringField.TYPE_NOT_STORED);
groupEndType.setIndexOptions(IndexOptions.DOCS_ONLY);
@@ -565,7 +562,7 @@ public class TestGrouping extends Lucene
//System.out.println("TEST: index groups");
for(BytesRef group : groupValues) {
- final List<Document> docs = new ArrayList<Document>();
+ final List<Document> docs = new ArrayList<>();
//System.out.println("TEST: group=" + (group == null ? "null" : group.utf8ToString()));
for(GroupDoc groupValue : groupMap.get(group)) {
Document doc = new Document();
@@ -637,7 +634,7 @@ public class TestGrouping extends Lucene
System.out.println("TEST: numDocs=" + numDocs + " numGroups=" + numGroups);
}
- final List<BytesRef> groups = new ArrayList<BytesRef>();
+ final List<BytesRef> groups = new ArrayList<>();
for(int i=0;i<numGroups;i++) {
String randomValue;
do {
@@ -790,14 +787,14 @@ public class TestGrouping extends Lucene
// ReaderBlocks only increases maxDoc() vs reader, which
// means a monotonic shift in scores, so we can
// reliably remap them w/ Map:
- final Map<String,Map<Float,Float>> scoreMap = new HashMap<String,Map<Float,Float>>();
+ final Map<String,Map<Float,Float>> scoreMap = new HashMap<>();
// Tricky: must separately set .score2, because the doc
// block index was created with possible deletions!
//System.out.println("fixup score2");
for(int contentID=0;contentID<3;contentID++) {
//System.out.println(" term=real" + contentID);
- final Map<Float,Float> termScoreMap = new HashMap<Float,Float>();
+ final Map<Float,Float> termScoreMap = new HashMap<>();
scoreMap.put("real"+contentID, termScoreMap);
//System.out.println("term=real" + contentID + " dfold=" + s.docFreq(new Term("content", "real"+contentID)) +
//" dfnew=" + sBlocks.docFreq(new Term("content", "real"+contentID)));
@@ -939,7 +936,7 @@ public class TestGrouping extends Lucene
// Get 1st pass top groups using shards
- ValueHolder<Boolean> idvBasedImplsUsedSharded = new ValueHolder<Boolean>(false);
+ ValueHolder<Boolean> idvBasedImplsUsedSharded = new ValueHolder<>(false);
final TopGroups<BytesRef> topGroupsShards = searchShards(s, shards.subSearchers, query, groupSort, docSort,
groupOffset, topNGroups, docOffset, docsPerGroup, getScores, getMaxScores, canUseIDV, false, idvBasedImplsUsedSharded);
final AbstractSecondPassGroupingCollector<?> c2;
@@ -971,7 +968,7 @@ public class TestGrouping extends Lucene
if (doAllGroups) {
TopGroups<BytesRef> tempTopGroups = getTopGroups(c2, docOffset);
- groupsResult = new TopGroups<BytesRef>(tempTopGroups, allGroupsCollector.getGroupCount());
+ groupsResult = new TopGroups<>(tempTopGroups, allGroupsCollector.getGroupCount());
} else {
groupsResult = getTopGroups(c2, docOffset);
}
@@ -1058,7 +1055,7 @@ public class TestGrouping extends Lucene
final TopGroups<BytesRef> groupsResultBlocks;
if (doAllGroups && tempTopGroupsBlocks != null) {
assertEquals((int) tempTopGroupsBlocks.totalGroupCount, allGroupsCollector2.getGroupCount());
- groupsResultBlocks = new TopGroups<BytesRef>(tempTopGroupsBlocks, allGroupsCollector2.getGroupCount());
+ groupsResultBlocks = new TopGroups<>(tempTopGroupsBlocks, allGroupsCollector2.getGroupCount());
} else {
groupsResultBlocks = tempTopGroupsBlocks;
}
@@ -1086,7 +1083,7 @@ public class TestGrouping extends Lucene
// Block index does not index DocValues so we pass
// false for canUseIDV:
final TopGroups<BytesRef> topGroupsBlockShards = searchShards(sBlocks, shardsBlocks.subSearchers, query,
- groupSort, docSort, groupOffset, topNGroups, docOffset, docsPerGroup, getScores, getMaxScores, false, false, new ValueHolder<Boolean>(false));
+ groupSort, docSort, groupOffset, topNGroups, docOffset, docsPerGroup, getScores, getMaxScores, false, false, new ValueHolder<>(false));
if (expectedGroups != null) {
// Fixup scores for reader2
@@ -1168,8 +1165,8 @@ public class TestGrouping extends Lucene
}
// Run 1st pass collector to get top groups per shard
final Weight w = topSearcher.createNormalizedWeight(query);
- final List<Collection<SearchGroup<BytesRef>>> shardGroups = new ArrayList<Collection<SearchGroup<BytesRef>>>();
- List<AbstractFirstPassGroupingCollector<?>> firstPassGroupingCollectors = new ArrayList<AbstractFirstPassGroupingCollector<?>>();
+ final List<Collection<SearchGroup<BytesRef>>> shardGroups = new ArrayList<>();
+ List<AbstractFirstPassGroupingCollector<?>> firstPassGroupingCollectors = new ArrayList<>();
AbstractFirstPassGroupingCollector<?> firstPassCollector = null;
boolean shardsCanUseIDV;
if (canUseIDV) {
Modified: lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java (original)
+++ lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java Tue May 7 11:20:55 2013
@@ -251,7 +251,7 @@ public class TokenSources {
if (unsortedTokens != null) {
tokensInOriginalOrder = unsortedTokens.toArray(new Token[unsortedTokens
.size()]);
- ArrayUtil.mergeSort(tokensInOriginalOrder, new Comparator<Token>() {
+ ArrayUtil.timSort(tokensInOriginalOrder, new Comparator<Token>() {
@Override
public int compare(Token t1, Token t2) {
if (t1.startOffset() == t2.startOffset()) return t1.endOffset()
Modified: lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java (original)
+++ lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java Tue May 7 11:20:55 2013
@@ -86,7 +86,7 @@ public final class TokenStreamFromTermPo
this.positionedTokens.add(token);
}
}
- CollectionUtil.mergeSort(this.positionedTokens, tokenComparator);
+ CollectionUtil.timSort(this.positionedTokens, tokenComparator);
int lastPosition = -1;
for (final Token token : this.positionedTokens) {
int thisPosition = token.getPositionIncrement();
Modified: lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java (original)
+++ lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java Tue May 7 11:20:55 2013
@@ -69,7 +69,7 @@ public class WeightedSpanTermExtractor {
private boolean cachedTokenStream;
private boolean wrapToCaching = true;
private int maxDocCharsToAnalyze;
- private AtomicReader reader = null;
+ private AtomicReader internalReader = null;
public WeightedSpanTermExtractor() {
@@ -350,7 +350,7 @@ public class WeightedSpanTermExtractor {
}
protected AtomicReaderContext getLeafContext() throws IOException {
- if (reader == null) {
+ if (internalReader == null) {
if(wrapToCaching && !(tokenStream instanceof CachingTokenFilter)) {
assert !cachedTokenStream;
tokenStream = new CachingTokenFilter(new OffsetLimitTokenFilter(tokenStream, maxDocCharsToAnalyze));
@@ -361,9 +361,9 @@ public class WeightedSpanTermExtractor {
tokenStream.reset();
final IndexSearcher searcher = indexer.createSearcher();
// MEM index has only atomic ctx
- reader = new DelegatingAtomicReader(((AtomicReaderContext)searcher.getTopReaderContext()).reader());
+ internalReader = new DelegatingAtomicReader(((AtomicReaderContext)searcher.getTopReaderContext()).reader());
}
- return reader.getContext();
+ return internalReader.getContext();
}
/*
@@ -468,7 +468,7 @@ public class WeightedSpanTermExtractor {
try {
extract(query, terms);
} finally {
- IOUtils.close(reader);
+ IOUtils.close(internalReader);
}
return terms;
@@ -516,7 +516,7 @@ public class WeightedSpanTermExtractor {
weightedSpanTerm.weight *= idf;
}
} finally {
- IOUtils.close(reader);
+ IOUtils.close(internalReader);
}
return terms;
Modified: lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java (original)
+++ lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java Tue May 7 11:20:55 2013
@@ -17,10 +17,10 @@ package org.apache.lucene.search.posting
* limitations under the License.
*/
-import org.apache.lucene.index.Term;
import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.InPlaceMergeSorter;
import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.SorterTemplate;
/**
* Represents a passage (typically a sentence of the document).
@@ -36,18 +36,24 @@ public final class Passage {
int matchStarts[] = new int[8];
int matchEnds[] = new int[8];
- Term matchTerms[] = new Term[8];
+ BytesRef matchTerms[] = new BytesRef[8];
int numMatches = 0;
- void addMatch(int startOffset, int endOffset, Term term) {
+ void addMatch(int startOffset, int endOffset, BytesRef term) {
assert startOffset >= this.startOffset && startOffset <= this.endOffset;
if (numMatches == matchStarts.length) {
- matchStarts = ArrayUtil.grow(matchStarts, numMatches+1);
- matchEnds = ArrayUtil.grow(matchEnds, numMatches+1);
- Term newMatchTerms[] = new Term[ArrayUtil.oversize(numMatches+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
+ int newLength = ArrayUtil.oversize(numMatches+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
+ int newMatchStarts[] = new int[newLength];
+ int newMatchEnds[] = new int[newLength];
+ BytesRef newMatchTerms[] = new BytesRef[newLength];
+ System.arraycopy(matchStarts, 0, newMatchStarts, 0, numMatches);
+ System.arraycopy(matchEnds, 0, newMatchEnds, 0, numMatches);
System.arraycopy(matchTerms, 0, newMatchTerms, 0, numMatches);
+ matchStarts = newMatchStarts;
+ matchEnds = newMatchEnds;
matchTerms = newMatchTerms;
}
+ assert matchStarts.length == matchEnds.length && matchEnds.length == matchTerms.length;
matchStarts[numMatches] = startOffset;
matchEnds[numMatches] = endOffset;
matchTerms[numMatches] = term;
@@ -57,8 +63,8 @@ public final class Passage {
void sort() {
final int starts[] = matchStarts;
final int ends[] = matchEnds;
- final Term terms[] = matchTerms;
- new SorterTemplate() {
+ final BytesRef terms[] = matchTerms;
+ new InPlaceMergeSorter() {
@Override
protected void swap(int i, int j) {
int temp = starts[i];
@@ -69,7 +75,7 @@ public final class Passage {
ends[i] = ends[j];
ends[j] = temp;
- Term tempTerm = terms[i];
+ BytesRef tempTerm = terms[i];
terms[i] = terms[j];
terms[j] = tempTerm;
}
@@ -79,18 +85,7 @@ public final class Passage {
return Integer.compare(starts[i], starts[j]);
}
- @Override
- protected void setPivot(int i) {
- pivot = starts[i];
- }
-
- @Override
- protected int comparePivot(int j) {
- return Integer.compare(pivot, starts[j]);
- }
-
- int pivot;
- }.mergeSort(0, numMatches-1);
+ }.sort(0, numMatches);
}
void reset() {
@@ -155,11 +150,11 @@ public final class Passage {
}
/**
- * Term of the matches, corresponding with {@link #getMatchStarts()}.
+ * BytesRef (term text) of the matches, corresponding with {@link #getMatchStarts()}.
* <p>
* Only {@link #getNumMatches()} are valid.
*/
- public Term[] getMatchTerms() {
+ public BytesRef[] getMatchTerms() {
return matchTerms;
}
}
Modified: lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PassageFormatter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PassageFormatter.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PassageFormatter.java (original)
+++ lucene/dev/branches/lucene4258/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PassageFormatter.java Tue May 7 11:20:55 2013
@@ -19,74 +19,20 @@ package org.apache.lucene.search.posting
/**
* Creates a formatted snippet from the top passages.
- * <p>
- * The default implementation marks the query terms as bold, and places
- * ellipses between unconnected passages.
+ *
* @lucene.experimental
*/
-public class PassageFormatter {
- private final String preTag;
- private final String postTag;
- private final String ellipsis;
-
- /**
- * Creates a new PassageFormatter with the default tags.
- */
- public PassageFormatter() {
- this("<b>", "</b>", "... ");
- }
-
- /**
- * Creates a new PassageFormatter with custom tags.
- * @param preTag text which should appear before a highlighted term.
- * @param postTag text which should appear after a highlighted term.
- * @param ellipsis text which should be used to connect two unconnected passages.
- */
- public PassageFormatter(String preTag, String postTag, String ellipsis) {
- if (preTag == null || postTag == null || ellipsis == null) {
- throw new NullPointerException();
- }
- this.preTag = preTag;
- this.postTag = postTag;
- this.ellipsis = ellipsis;
- }
-
+public abstract class PassageFormatter {
+
/**
* Formats the top <code>passages</code> from <code>content</code>
* into a human-readable text snippet.
- *
+ *
* @param passages top-N passages for the field. Note these are sorted in
* the order that they appear in the document for convenience.
* @param content content for the field.
* @return formatted highlight
*/
- public String format(Passage passages[], String content) {
- StringBuilder sb = new StringBuilder();
- int pos = 0;
- for (Passage passage : passages) {
- // don't add ellipsis if its the first one, or if its connected.
- if (passage.startOffset > pos && pos > 0) {
- sb.append(ellipsis);
- }
- pos = passage.startOffset;
- for (int i = 0; i < passage.numMatches; i++) {
- int start = passage.matchStarts[i];
- int end = passage.matchEnds[i];
- // its possible to have overlapping terms
- if (start > pos) {
- sb.append(content.substring(pos, start));
- }
- if (end > pos) {
- sb.append(preTag);
- sb.append(content.substring(Math.max(pos, start), end));
- sb.append(postTag);
- pos = end;
- }
- }
- // its possible a "term" from the analyzer could span a sentence boundary.
- sb.append(content.substring(pos, Math.max(pos, passage.endOffset)));
- pos = passage.endOffset;
- }
- return sb.toString();
- }
+ public abstract String format(Passage passages[], String content);
+
}