Java Code Examples for org.apache.lucene.store.RAMDirectory#openInput()
The following examples show how to use
org.apache.lucene.store.RAMDirectory#openInput() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComplexVectorTest.java From semanticvectors with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testReadWrite() { Vector v1 = new ComplexVector(new short[] { -1, 8000, 16000 }); RAMDirectory directory = new RAMDirectory(); try { IndexOutput indexOutput = directory.createOutput("complexvectors.bin", IOContext.DEFAULT); v1.writeToLuceneStream(indexOutput); indexOutput.close(); IndexInput indexInput = directory.openInput("complexvectors.bin", IOContext.DEFAULT); ComplexVector cv2 = new ComplexVector(3, Mode.POLAR_SPARSE); cv2.readFromLuceneStream(indexInput); assertFloatArrayEquals( new float[] {0, 0, -0.997290f, 0.073564f, 0.989176f, -0.1467304f}, cv2.getCoordinates(), TOL); } catch (IOException e) { e.printStackTrace(); fail(); } directory.close(); }
Example 2
Source File: BinaryVectorTest.java From semanticvectors with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testGenerateRandomVectorWriteAndRead() { Random random = new Random(0); Vector vector = VectorFactory.generateRandomVector(VectorType.BINARY, 64, 2, random); // The exact string depends on fail Java's implementation of Random, so we only check for length. String vectorString = vector.writeToString(); assertEquals(64, vectorString.length()); RAMDirectory directory = new RAMDirectory(); try { IndexOutput indexOutput = directory.createOutput("binaryvectors.bin", IOContext.DEFAULT); vector.writeToLuceneStream(indexOutput); indexOutput.close(); IndexInput indexInput = directory.openInput("binaryvectors.bin", IOContext.DEFAULT); Vector vector2 = VectorFactory.createZeroVector(VectorType.BINARY, 64); assertEquals("0000000000000000000000000000000000000000000000000000000000000000", vector2.writeToString()); vector2.readFromLuceneStream(indexInput); assertEquals(vectorString, vector2.writeToString()); } catch (IOException e) { e.printStackTrace(); fail(); } directory.close(); }
Example 3
Source File: CacheIndexInputTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void test1() throws IOException { RAMDirectory directory = new RAMDirectory(); String name = "test"; IndexOutput output = directory.createOutput(name, IOContext.DEFAULT); byte[] bs = "hello world".getBytes(); output.writeBytes(bs, bs.length); output.close(); IndexInput input = directory.openInput(name, IOContext.DEFAULT); Cache cache = getCache(); CacheIndexInput cacheInput = new CacheIndexInput(null, name, input, cache); byte[] buf = new byte[bs.length]; cacheInput.readBytes(buf, 0, buf.length); cacheInput.close(); assertArrayEquals(bs, buf); directory.close(); }
Example 4
Source File: CacheIndexInputTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void test2() throws IOException { Cache cache = getCache(); RAMDirectory directory = new RAMDirectory(); Random random = new Random(seed); String name = "test2"; long size = (10 * 1024 * 1024) + 13; IndexOutput output = directory.createOutput(name, IOContext.DEFAULT); writeRandomData(size, random, output); output.close(); IndexInput input = directory.openInput(name, IOContext.DEFAULT); IndexInput testInput = new CacheIndexInput(null, name, input.clone(), cache); readRandomData(input, testInput, random, sampleSize, maxBufSize, maxOffset); readRandomDataShort(input, testInput, random, sampleSize); readRandomDataInt(input, testInput, random, sampleSize); readRandomDataLong(input, testInput, random, sampleSize); testInput.close(); input.close(); directory.close(); }
Example 5
Source File: CacheIndexOutputTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@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); 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(); }
Example 6
Source File: CacheIndexOutputTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@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(); 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(); }