"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/test/org/apache/lucene/index/TestFieldInfos.java" between
lucene-7.6.0-src.tgz and lucene-7.7.0-src.tgz

About: Lucene is a Java full-text search engine (not a complete application, but rather a code library and API; java source code).

TestFieldInfos.java  (lucene-7.6.0-src.tgz):TestFieldInfos.java  (lucene-7.7.0-src.tgz)
skipping to change at line 19 skipping to change at line 19
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.lucene.index; package org.apache.lucene.index;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.StringField; import org.apache.lucene.document.StringField;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
public class TestFieldInfos extends LuceneTestCase { public class TestFieldInfos extends LuceneTestCase {
public void testFieldInfos() throws Exception{ public void testFieldInfos() throws Exception{
Directory dir = newDirectory(); Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnaly zer(random())) IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnaly zer(random()))
.setMergePolicy(NoMergePolicy.INSTANCE)); .setMergePolicy(NoMergePolicy.INSTANCE));
Document d1 = new Document(); Document d1 = new Document();
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
d1.add(new StringField("f" + i, "v" + i, Field.Store.YES)); d1.add(new StringField("f" + i, "v" + i, Field.Store.YES));
skipping to change at line 91 skipping to change at line 96
// testing empty FieldInfos // testing empty FieldInfos
assertNull(fis3.fieldInfo(0)); //lookup by number assertNull(fis3.fieldInfo(0)); //lookup by number
assertNull(fis3.fieldInfo("f0")); //lookup by name assertNull(fis3.fieldInfo("f0")); //lookup by name
assertEquals(0, fis3.size()); assertEquals(0, fis3.size());
Iterator<FieldInfo> it3 = fis3.iterator(); Iterator<FieldInfo> it3 = fis3.iterator();
assertFalse(it3.hasNext()); assertFalse(it3.hasNext());
dir.close(); dir.close();
} }
public void testFieldAttributes() throws Exception{
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnaly
zer(random()))
.setMergePolicy(NoMergePolicy.INSTANCE));
FieldType type1 = new FieldType();
type1.setStored(true);
type1.putAttribute("testKey1", "testValue1");
Document d1 = new Document();
d1.add(new Field("f1", "v1", type1));
FieldType type2 = new FieldType(type1);
//changing the value after copying shouldn't impact the original type1
type2.putAttribute("testKey1", "testValue2");
writer.addDocument(d1);
writer.commit();
Document d2 = new Document();
type1.putAttribute("testKey1", "testValueX");
type1.putAttribute("testKey2", "testValue2");
d2.add(new Field("f1", "v2", type1));
d2.add(new Field("f2", "v2", type2));
writer.addDocument(d2);
writer.commit();
writer.forceMerge(1);
IndexReader reader = writer.getReader();
FieldInfos fis = MultiFields.getMergedFieldInfos(reader);
assertEquals(fis.size(), 2);
Iterator<FieldInfo> it = fis.iterator();
while(it.hasNext()) {
FieldInfo fi = it.next();
switch (fi.name) {
case "f1":
// testKey1 can point to either testValue1 or testValueX based on the
order
// of merge, but we see textValueX winning here since segment_2 is mer
ged on segment_1.
assertEquals("testValueX", fi.getAttribute("testKey1"));
assertEquals("testValue2", fi.getAttribute("testKey2"));
break;
case "f2":
assertEquals("testValue2", fi.getAttribute("testKey1"));
break;
default:
assertFalse("Unknown field", true);
}
}
reader.close();
writer.close();
dir.close();
}
public void testMergedFieldInfos_empty() throws IOException {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnaly
zer(random())));
IndexReader reader = writer.getReader();
FieldInfos actual = MultiFields.getMergedFieldInfos(reader);
FieldInfos expected = FieldInfos.EMPTY;
assertThat(actual, sameInstance(expected));
reader.close();
writer.close();
dir.close();
}
public void testMergedFieldInfos_singleLeaf() throws IOException {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnaly
zer(random())));
Document d1 = new Document();
d1.add(new StringField("f1", "v1", Field.Store.YES));
writer.addDocument(d1);
writer.commit();
Document d2 = new Document();
d2.add(new StringField("f2", "v2", Field.Store.YES));
writer.addDocument(d2);
writer.commit();
writer.forceMerge(1);
IndexReader reader = writer.getReader();
FieldInfos actual = MultiFields.getMergedFieldInfos(reader);
FieldInfos expected = reader.leaves().get(0).reader().getFieldInfos();
assertThat(reader.leaves().size(), equalTo(1));
assertThat(actual, sameInstance(expected));
reader.close();
writer.close();
dir.close();
}
} }
 End of changes. 4 change blocks. 
0 lines changed or deleted 103 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)