Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexWriter.commit()


      rev1.release();
      assertTrue(dir.fileExists(IndexFileNames.SEGMENTS + "_1"));
     
      rev1 = new IndexRevision(writer); // create revision again, so the files are snapshotted
      writer.addDocument(new Document());
      writer.commit();
      assertNotNull(new IndexRevision(writer));
      rev1.release(); // this release should trigger the delete of segments_1
      assertFalse(dir.fileExists(IndexFileNames.SEGMENTS + "_1"));
    } finally {
      IOUtils.close(writer, dir);
View Full Code Here


    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter writer = new IndexWriter(dir, conf);
    try {
      writer.addDocument(new Document());
      writer.commit();
      Revision rev = new IndexRevision(writer);
      @SuppressWarnings("unchecked")
      Map<String, List<RevisionFile>> sourceFiles = rev.getSourceFiles();
      assertEquals(1, sourceFiles.size());
      List<RevisionFile> files = sourceFiles.values().iterator().next();
View Full Code Here

    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter writer = new IndexWriter(dir, conf);
    try {
      writer.addDocument(new Document());
      writer.commit();
      Revision rev = new IndexRevision(writer);
      @SuppressWarnings("unchecked")
      Map<String, List<RevisionFile>> sourceFiles = rev.getSourceFiles();
      String source = sourceFiles.keySet().iterator().next();
      for (RevisionFile file : sourceFiles.values().iterator().next()) {
View Full Code Here

                        TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    Document doc = new Document();
    doc.add(newStringField("f", "", Field.Store.NO));
    doc.add(newStringField("t", "1", Field.Store.NO));
    w.addDocument(doc);
    w.commit();
    doc = new Document();
    doc.add(newStringField("t", "1", Field.Store.NO));
    w.addDocument(doc);

    IndexReader r = DirectoryReader.open(w, true);
View Full Code Here

        }
        doc.add(newTextField("body", sb.toString(), Field.Store.NO));
        w.addDocument(doc);
        id++;
      }
      w.commit();
    }

    IndexReader r = DirectoryReader.open(w, true);
    w.close();
    Query q = new TermQuery(new Term("body", "text"));
View Full Code Here

            setMergePolicy(newLogMergePolicy(false)).setCodec(Codec.forName("Lucene40")).setUseCompoundFile(false)
    );
    TestIndexWriterReader.createIndexNoClose(true, "ram", writer);
    IndexReader reader = DirectoryReader.open(writer, true);
    assertEquals(100, reader.maxDoc());
    writer.commit();
    // we should see only fdx,fdt files here
    String[] files = primaryDir.listAll();
    assertTrue(files.length > 0);
    for (int x=0; x < files.length; x++) {
      String ext = FileSwitchDirectory.getExtension(files[x]);
View Full Code Here

    MockAnalyzer analyzer = new MockAnalyzer(random());
    // TODO: something about lock timeouts and leftover locks.
    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
        TEST_VERSION_CURRENT, analyzer)
        .setOpenMode(OpenMode.CREATE));
    writer.commit();
    IndexReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = newSearcher(reader);
   
    int num = atLeast(1000);
    for(int dx = 0; dx < num; dx ++) {
View Full Code Here

        dir.setWrapLockFactory(false); // we are gonna explicitly test we get this back
        assertTrue("RAMDirectory.setLockFactory did not take",
                   NoLockFactory.class.isInstance(dir.getLockFactory()));

        IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
        writer.commit(); // required so the second open succeed
        // Create a 2nd IndexWriter.  This is normally not allowed but it should run through since we're not
        // using any locks:
        IndexWriter writer2 = null;
        try {
            writer2 = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
View Full Code Here

public class TestHighFrequencyDictionary extends LuceneTestCase {
  public void testEmpty() throws Exception {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    writer.commit();
    writer.close();
    IndexReader ir = DirectoryReader.open(dir);
    Dictionary dictionary = new HighFrequencyDictionary(ir, "bogus", 0.1f);
    BytesRefIterator tf = dictionary.getWordsIterator();
    assertNull(tf.getComparator());
View Full Code Here

      finally {
        reader.close();
      }
    }
    finally {
      writer.commit();
      writer.close();
      ramDir.close();
    }
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.