Beispiel #1
0
  // Tests whether merging of docs that have different
  // omitTermFreqAndPositions for the same field works
  public void testMixedMerge() throws Exception {
    Directory ram = newDirectory();
    Analyzer analyzer = new MockAnalyzer(random());
    IndexWriter writer =
        new IndexWriter(
            ram,
            newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)
                .setMaxBufferedDocs(3)
                .setMergePolicy(newLogMergePolicy(2)));
    Document d = new Document();

    // this field will have Tf
    Field f1 = newField("f1", "This field has term freqs", normalType);
    d.add(f1);

    // this field will NOT have Tf
    Field f2 = newField("f2", "This field has NO Tf in all docs", omitType);
    d.add(f2);

    for (int i = 0; i < 30; i++) writer.addDocument(d);

    // now we add another document which has term freq for field f2 and not for f1 and verify if the
    // SegmentMerger
    // keep things constant
    d = new Document();

    // Reverese
    f1 = newField("f1", "This field has term freqs", omitType);
    d.add(f1);

    f2 = newField("f2", "This field has NO Tf in all docs", normalType);
    d.add(f2);

    for (int i = 0; i < 30; i++) writer.addDocument(d);

    // force merge
    writer.forceMerge(1);
    // flush
    writer.close();

    SegmentReader reader = getOnlySegmentReader(DirectoryReader.open(ram));
    FieldInfos fi = reader.getFieldInfos();
    assertEquals(
        "OmitTermFreqAndPositions field bit should be set.",
        IndexOptions.DOCS_ONLY,
        fi.fieldInfo("f1").getIndexOptions());
    assertEquals(
        "OmitTermFreqAndPositions field bit should be set.",
        IndexOptions.DOCS_ONLY,
        fi.fieldInfo("f2").getIndexOptions());

    reader.close();
    ram.close();
  }
 public void testFieldNames() throws Exception {
   Directory dir1 = getDir1(random());
   Directory dir2 = getDir2(random());
   ParallelLeafReader pr =
       new ParallelLeafReader(
           SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1)),
           SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir2)));
   FieldInfos fieldInfos = pr.getFieldInfos();
   assertEquals(4, fieldInfos.size());
   assertNotNull(fieldInfos.fieldInfo("f1"));
   assertNotNull(fieldInfos.fieldInfo("f2"));
   assertNotNull(fieldInfos.fieldInfo("f3"));
   assertNotNull(fieldInfos.fieldInfo("f4"));
   pr.close();
   dir1.close();
   dir2.close();
 }