Package org.apache.lucene.analysis

Examples of org.apache.lucene.analysis.WhitespaceAnalyzer


   * Tests creating a segment, then check to insure the segment can be seen via
   * IW.getReader
   */
  public void doTestIndexWriterReopenSegment(boolean optimize) throws Exception {
    Directory dir1 = new MockRAMDirectory();
    IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
        IndexWriter.MaxFieldLength.LIMITED);
    writer.setInfoStream(infoStream);
    IndexReader r1 = writer.getReader();
    assertEquals(0, r1.maxDoc());
    createIndexNoClose(false, "index1", writer);
    writer.flush(!optimize, true, true);

    IndexReader iwr1 = writer.getReader();
    assertEquals(100, iwr1.maxDoc());

    IndexReader r2 = writer.getReader();
    assertEquals(r2.maxDoc(), 100);
    // add 100 documents
    for (int x = 10000; x < 10000 + 100; x++) {
      Document d = createDocument(x, "index1", 5);
      writer.addDocument(d);
    }
    writer.flush(false, true, true);
    // verify the reader was reopened internally
    IndexReader iwr2 = writer.getReader();
    assertTrue(iwr2 != r1);
    assertEquals(200, iwr2.maxDoc());
    // should have flushed out a segment
    IndexReader r3 = writer.getReader();
    assertTrue(r2 != r3);
    assertEquals(200, r3.maxDoc());

    // dec ref the readers rather than close them because
    // closing flushes changes to the writer
    r1.close();
    iwr1.close();
    r2.close();
    r3.close();
    iwr2.close();
    writer.close();

    // test whether the changes made it to the directory
    writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
        IndexWriter.MaxFieldLength.LIMITED);
    IndexReader w2r1 = writer.getReader();
    // insure the deletes were actually flushed to the directory
    assertEquals(200, w2r1.maxDoc());
    w2r1.close();
View Full Code Here


   * reader.termDocs(term); int doc = -1; //if (td.next()) { // doc = td.doc();
   * //} //writer.deleteDocuments(term); td.close(); return doc; }
   */
  public static void createIndex(Directory dir1, String indexName,
      boolean multiSegment) throws IOException {
    IndexWriter w = new IndexWriter(dir1, new WhitespaceAnalyzer(),
        IndexWriter.MaxFieldLength.LIMITED);
    w.setMergePolicy(new LogDocMergePolicy(w));
    for (int i = 0; i < 100; i++) {
      w.addDocument(createDocument(i, indexName, 4));
      if (multiSegment && (i % 10) == 0) {
View Full Code Here

  }

  public void testMergeWarmer() throws Exception {

    Directory dir1 = new MockRAMDirectory();
    IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
                                         IndexWriter.MaxFieldLength.LIMITED);
    writer.setInfoStream(infoStream);

    // create the index
    createIndexNoClose(false, "test", writer);
View Full Code Here

    dir1.close();
  }

  public void testAfterCommit() throws Exception {
    Directory dir1 = new MockRAMDirectory();
    IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
                                         IndexWriter.MaxFieldLength.LIMITED);
    writer.setInfoStream(infoStream);

    // create the index
    createIndexNoClose(false, "test", writer);
View Full Code Here

  }

  // Make sure reader remains usable even if IndexWriter closes
  public void testAfterClose() throws Exception {
    Directory dir1 = new MockRAMDirectory();
    IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
                                         IndexWriter.MaxFieldLength.LIMITED);
    writer.setInfoStream(infoStream);

    // create the index
    createIndexNoClose(false, "test", writer);
View Full Code Here

  }

  // Stress test reopen during addIndexes
  public void testDuringAddIndexes() throws Exception {
    Directory dir1 = new MockRAMDirectory();
    final IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
                                               IndexWriter.MaxFieldLength.LIMITED);
    writer.setInfoStream(infoStream);
    writer.setMergeFactor(2);

    // create the index
View Full Code Here

  }

  // Stress test reopen during add/delete
  public void testDuringAddDelete() throws Exception {
    Directory dir1 = new MockRAMDirectory();
    final IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),
                                               IndexWriter.MaxFieldLength.LIMITED);
    writer.setInfoStream(infoStream);
    writer.setMergeFactor(2);

    // create the index
View Full Code Here

    dir1.close();
  }

  public void testExpungeDeletes() throws Throwable {
    Directory dir = new MockRAMDirectory();
    final IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(),
                                               IndexWriter.MaxFieldLength.LIMITED);
    Document doc = new Document();
    doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));
    Field id = new Field("id", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
    doc.add(id);
View Full Code Here

    dir.close();
  }

  public void testDeletesNumDocs() throws Throwable {
    Directory dir = new MockRAMDirectory();
    final IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(),
                                               IndexWriter.MaxFieldLength.LIMITED);
    Document doc = new Document();
    doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));
    Field id = new Field("id", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
    doc.add(id);
View Full Code Here

    dir.close();
  }

  public void testSegmentWarmer() throws Exception {
    Directory dir = new MockRAMDirectory();
    IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
    w.setMaxBufferedDocs(2);
    w.getReader().close();

    w.setMergedSegmentWarmer(new IndexWriter.IndexReaderWarmer() {
        public void warm(IndexReader r) throws IOException {
View Full Code Here

TOP

Related Classes of org.apache.lucene.analysis.WhitespaceAnalyzer

Copyright © 2018 www.massapicom. 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.