Example usage for org.apache.lucene.store RAMDirectory RAMDirectory

List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory

Introduction

In this page you can find the example usage for org.apache.lucene.store RAMDirectory RAMDirectory.

Prototype

public RAMDirectory() 

Source Link

Document

Constructs an empty Directory .

Usage

From source file:org.apache.blur.manager.writer.MutatableActionTest.java

License:Apache License

@Test
public void testDeleteRow() throws IOException {
    RAMDirectory directory = new RAMDirectory();
    DirectoryReader reader = getIndexReader(directory);
    IndexWriter writer = new IndexWriter(directory, _conf.clone());
    assertEquals(0, reader.numDocs());//  w w  w.java  2  s.c om

    Row row = genRow();
    _action.replaceRow(row);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(1, reader.numDocs());

    _action.deleteRow(row.getId());
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(0, reader.numDocs());
}

From source file:org.apache.blur.manager.writer.MutatableActionTest.java

License:Apache License

@Test
public void testReplaceRecord() throws IOException {
    RAMDirectory directory = new RAMDirectory();
    DirectoryReader reader = getIndexReader(directory);
    IndexWriter writer = new IndexWriter(directory, _conf.clone());
    assertEquals(0, reader.numDocs());/*from  w  w w.  j  av  a2s.com*/

    Row row = genRow();
    List<Column> cols = new ArrayList<Column>();
    cols.add(new Column("n", "v"));
    row.addToRecords(new Record("1", "fam", cols));

    _action.replaceRow(row);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(2, reader.numDocs());

    cols.add(new Column("n2", "v2"));
    Record record = new Record("1", "fam", cols);
    _action.replaceRecord(row.getId(), record);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(2, reader.numDocs());

    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term(BlurConstants.ROW_ID, row.getId())), 10);
    Document doc2 = searcher.doc(topDocs.scoreDocs[1].doc);
    List<IndexableField> fields = doc2.getFields();
    assertEquals(fields.size(), 5);
    String value = doc2.get("fam.n2");
    assertEquals("v2", value);
}

From source file:org.apache.blur.manager.writer.MutatableActionTest.java

License:Apache License

@Test
public void testAppendColumns() throws IOException {
    RAMDirectory directory = new RAMDirectory();
    DirectoryReader reader = getIndexReader(directory);
    IndexWriter writer = new IndexWriter(directory, _conf.clone());
    assertEquals(0, reader.numDocs());//from   w w  w.j ava  2 s.  c om

    Row row = genRow();
    List<Column> cols = new ArrayList<Column>();
    cols.add(new Column("n", "v"));
    row.addToRecords(new Record("1", "fam", cols));

    _action.replaceRow(row);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(2, reader.numDocs());

    cols.clear();
    cols.add(new Column("n2", "v2"));
    Record record = new Record("1", "fam", cols);
    _action.appendColumns(row.getId(), record);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(2, reader.numDocs());

    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term(BlurConstants.ROW_ID, row.getId())), 10);
    Document doc2 = searcher.doc(topDocs.scoreDocs[1].doc);
    List<IndexableField> fields = doc2.getFields();
    assertEquals(fields.size(), 5);
    String value = doc2.get("fam.n2");
    assertEquals("v2", value);
}

From source file:org.apache.blur.manager.writer.MutatableActionTest.java

License:Apache License

@Test
public void testReplaceColumns() throws IOException {
    RAMDirectory directory = new RAMDirectory();
    DirectoryReader reader = getIndexReader(directory);
    IndexWriter writer = new IndexWriter(directory, _conf.clone());
    assertEquals(0, reader.numDocs());/*  w  ww  . j a va  2 s .c o m*/

    Row row = genRow();
    List<Column> cols = new ArrayList<Column>();
    cols.add(new Column("n", "v"));
    cols.add(new Column("n1", "v1"));
    row.addToRecords(new Record("1", "fam", cols));

    _action.replaceRow(row);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(2, reader.numDocs());

    cols.clear();
    cols.add(new Column("n1", "v2"));
    Record record = new Record("1", "fam", cols);
    _action.replaceColumns(row.getId(), record);
    _action.performMutate(getSearcher(reader, directory), writer);
    reader = commitAndReopen(reader, writer);
    assertEquals(2, reader.numDocs());

    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term(BlurConstants.ROW_ID, row.getId())), 10);
    Document doc2 = searcher.doc(topDocs.scoreDocs[1].doc);
    List<IndexableField> fields = doc2.getFields();
    assertEquals(5, fields.size());
    String value = doc2.get("fam.n1");
    assertEquals("v2", value);
}

From source file:org.apache.blur.server.BlurSecureIndexSearcherTest.java

License:Apache License

private IndexReader getIndexReader() throws IOException {
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer());
    Directory dir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(dir, conf);
    writer.close();//from w  w w .ja  v  a  2  s  .  co m
    return DirectoryReader.open(dir);
}

From source file:org.apache.blur.store.blockcache_v2.CacheIndexOutputTest.java

License:Apache License

@Test
public void test1() throws IOException {
    Random random = new Random(seed);
    RAMDirectory directory = new RAMDirectory();

    Cache cache = CacheIndexInputTest.getCache();
    CacheIndexOutput indexOutput = new CacheIndexOutput(null, "test", cache, directory, IOContext.DEFAULT);
    indexOutput.writeByte((byte) 1);
    indexOutput.writeByte((byte) 2);
    byte[] b = new byte[16000];
    random.nextBytes(b);//  www  .jav  a2 s .  c  om
    indexOutput.writeBytes(b, 16000);
    indexOutput.close();

    IndexInput input = directory.openInput("test", IOContext.DEFAULT);
    assertEquals(16002, input.length());
    assertEquals(1, input.readByte());
    assertEquals(2, input.readByte());

    byte[] buf = new byte[16000];
    input.readBytes(buf, 0, 16000);
    input.close();
    assertArrayEquals(b, buf);
    directory.close();
}

From source file:org.apache.blur.store.blockcache_v2.CacheIndexOutputTest.java

License:Apache License

@Test
public void test2() throws IOException {
    Cache cache = CacheIndexInputTest.getCache();
    RAMDirectory directory = new RAMDirectory();
    RAMDirectory directory2 = new RAMDirectory();

    Random random = new Random(seed);

    String name = "test2";
    long size = (10 * 1024 * 1024) + 13;

    IndexOutput output = directory.createOutput(name, IOContext.DEFAULT);
    CacheIndexOutput cacheIndexOutput = new CacheIndexOutput(null, name, cache, directory2, IOContext.DEFAULT);
    CacheIndexInputTest.writeRandomData(size, random, output, cacheIndexOutput);
    output.close();/*  www . j  a v a 2s .  co m*/
    cacheIndexOutput.close();

    IndexInput input = directory.openInput(name, IOContext.DEFAULT);
    IndexInput testInput = directory2.openInput(name, IOContext.DEFAULT);
    CacheIndexInputTest.readRandomData(input, testInput, random, sampleSize, maxBufSize, maxOffset);
    testInput.close();
    input.close();
    directory.close();
    directory2.close();
}

From source file:org.apache.blur.utils.BlurUtilsTest.java

License:Apache License

private IndexReader getReader() throws CorruptIndexException, LockObtainFailedException, IOException {
    RAMDirectory directory = new RAMDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer());
    IndexWriter writer = new IndexWriter(directory, conf);
    Document doc = new Document();
    doc.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO));
    doc.add(new StringField("a", "b", Store.YES));
    doc.add(new StringField("family", "f1", Store.YES));

    Document doc1 = new Document();
    doc.add(new StringField("a", "b", Store.YES));
    writer.addDocument(doc);/*ww  w.jav  a 2s .  c  o m*/
    writer.addDocument(doc1);
    writer.close();
    return DirectoryReader.open(directory);
}

From source file:org.apache.blur.utils.BlurUtilsTest.java

License:Apache License

private IndexReader getReaderWithDocsHavingFamily()
        throws CorruptIndexException, LockObtainFailedException, IOException {
    RAMDirectory directory = new RAMDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer());
    IndexWriter writer = new IndexWriter(directory, conf);
    Document doc = new Document();
    doc.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO));
    doc.add(new StringField("a", "b", Store.YES));
    doc.add(new StringField("family", "f2", Store.YES));

    Document doc1 = new Document();
    doc1.add(new StringField("a", "b", Store.YES));
    doc1.add(new StringField("family", "f1", Store.YES));
    writer.addDocument(doc);//w  w  w.  j  a v  a2  s  . c  o m
    writer.addDocument(doc1);
    writer.close();
    return DirectoryReader.open(directory);
}

From source file:org.apache.blur.utils.TermDocIterableTest.java

License:Apache License

private AtomicReader createIndexReader() throws IOException {
    RAMDirectory directory = new RAMDirectory();
    IndexWriter writer = new IndexWriter(directory,
            new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
    for (int i = 0; i < BLOCKS; i++) {
        addDocumentBlock(i, COUNT_PER_BLOCK, writer);
    }// w w w. j a  va2 s  . c  om
    writer.close();
    return SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory));
}