mirror of https://github.com/apache/lucene.git
Fixed fieldcache insanity failure in testBasic.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1486012 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2d716bfa97
commit
ee3fb273bf
|
@ -72,74 +72,78 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
|
||||||
dir,
|
dir,
|
||||||
newIndexWriterConfig(TEST_VERSION_CURRENT,
|
newIndexWriterConfig(TEST_VERSION_CURRENT,
|
||||||
new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
|
new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
|
||||||
boolean canUseIDV = true;
|
|
||||||
DocValuesType valueType = vts[random().nextInt(vts.length)];
|
DocValuesType valueType = vts[random().nextInt(vts.length)];
|
||||||
|
|
||||||
// 0
|
// 0
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
addGroupField(doc, groupField, "author1", canUseIDV, valueType);
|
addGroupField(doc, groupField, "author1", valueType);
|
||||||
doc.add(newTextField("content", "random text", Field.Store.YES));
|
doc.add(newTextField("content", "random text", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "1", Field.Store.YES));
|
doc.add(newStringField("id_1", "1", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "1", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
// 1
|
// 1
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
addGroupField(doc, groupField, "author1", canUseIDV, valueType);
|
addGroupField(doc, groupField, "author1", valueType);
|
||||||
doc.add(newTextField("content", "some more random text blob", Field.Store.YES));
|
doc.add(newTextField("content", "some more random text blob", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "2", Field.Store.YES));
|
doc.add(newStringField("id_1", "2", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "2", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
// 2
|
// 2
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
addGroupField(doc, groupField, "author1", canUseIDV, valueType);
|
addGroupField(doc, groupField, "author1", valueType);
|
||||||
doc.add(newTextField("content", "some more random textual data", Field.Store.YES));
|
doc.add(newTextField("content", "some more random textual data", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "3", Field.Store.YES));
|
doc.add(newStringField("id_1", "3", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "3", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
w.commit(); // To ensure a second segment
|
w.commit(); // To ensure a second segment
|
||||||
|
|
||||||
// 3
|
// 3
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
addGroupField(doc, groupField, "author2", canUseIDV, valueType);
|
addGroupField(doc, groupField, "author2", valueType);
|
||||||
doc.add(newTextField("content", "some random text", Field.Store.YES));
|
doc.add(newTextField("content", "some random text", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "4", Field.Store.YES));
|
doc.add(newStringField("id_1", "4", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "4", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
// 4
|
// 4
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
addGroupField(doc, groupField, "author3", canUseIDV, valueType);
|
addGroupField(doc, groupField, "author3", valueType);
|
||||||
doc.add(newTextField("content", "some more random text", Field.Store.YES));
|
doc.add(newTextField("content", "some more random text", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "5", Field.Store.YES));
|
doc.add(newStringField("id_1", "5", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "5", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
// 5
|
// 5
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
addGroupField(doc, groupField, "author3", canUseIDV, valueType);
|
addGroupField(doc, groupField, "author3", valueType);
|
||||||
doc.add(newTextField("content", "random blob", Field.Store.YES));
|
doc.add(newTextField("content", "random blob", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "6", Field.Store.YES));
|
doc.add(newStringField("id_1", "6", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "6", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
// 6 -- no author field
|
// 6 -- no author field
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.YES));
|
doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "6", Field.Store.YES));
|
doc.add(newStringField("id_1", "6", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "6", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
// 7 -- no author field
|
// 7 -- no author field
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.YES));
|
doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.NO));
|
||||||
doc.add(newStringField("id", "7", Field.Store.YES));
|
doc.add(newStringField("id_1", "7", Field.Store.NO));
|
||||||
|
doc.add(newStringField("id_2", "7", Field.Store.NO));
|
||||||
w.addDocument(doc);
|
w.addDocument(doc);
|
||||||
|
|
||||||
IndexReader reader = w.getReader();
|
IndexReader reader = w.getReader();
|
||||||
IndexSearcher indexSearcher = newSearcher(reader);
|
IndexSearcher indexSearcher = newSearcher(reader);
|
||||||
if (SlowCompositeReaderWrapper.class.isAssignableFrom(reader.getClass())) {
|
|
||||||
canUseIDV = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
w.close();
|
w.close();
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
||||||
Sort sortWithinGroup = new Sort(new SortField("id", SortField.Type.INT, true));
|
Sort sortWithinGroup = new Sort(new SortField("id_1", SortField.Type.INT, true));
|
||||||
AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
|
AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
|
||||||
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
|
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
|
||||||
assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
|
assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
|
||||||
|
@ -156,13 +160,13 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
|
||||||
assertTrue(openBitSetContains(new int[]{1, 5}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
|
assertTrue(openBitSetContains(new int[]{1, 5}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
|
||||||
|
|
||||||
// STRING sort type triggers different implementation
|
// STRING sort type triggers different implementation
|
||||||
Sort sortWithinGroup2 = new Sort(new SortField("id", SortField.Type.STRING, true));
|
Sort sortWithinGroup2 = new Sort(new SortField("id_2", SortField.Type.STRING, true));
|
||||||
allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup2);
|
allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup2);
|
||||||
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
|
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
|
||||||
assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
|
assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
|
||||||
assertTrue(openBitSetContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
|
assertTrue(openBitSetContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
|
||||||
|
|
||||||
Sort sortWithinGroup3 = new Sort(new SortField("id", SortField.Type.STRING, false));
|
Sort sortWithinGroup3 = new Sort(new SortField("id_2", SortField.Type.STRING, false));
|
||||||
allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup3);
|
allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup3);
|
||||||
indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
|
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.
|
// 7 b/c higher doc id wins, even if order of field is in not in reverse.
|
||||||
|
@ -539,9 +543,8 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
|
||||||
return collector;
|
return collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV, DocValuesType valueType) {
|
private void addGroupField(Document doc, String groupField, String value, DocValuesType valueType) {
|
||||||
doc.add(new TextField(groupField, value, Field.Store.YES));
|
doc.add(new TextField(groupField, value, Field.Store.NO));
|
||||||
if (canUseIDV) {
|
|
||||||
Field valuesField = null;
|
Field valuesField = null;
|
||||||
switch(valueType) {
|
switch(valueType) {
|
||||||
case BINARY:
|
case BINARY:
|
||||||
|
@ -555,7 +558,6 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
doc.add(valuesField);
|
doc.add(valuesField);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static class GroupDoc {
|
private static class GroupDoc {
|
||||||
final int id;
|
final int id;
|
||||||
|
|
Loading…
Reference in New Issue