List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory
public RAMDirectory()
From source file:com.bah.lucene.blockcache_v2.CacheIndexOutputTest.java
License:Apache License
@Test public void test1() throws IOException { Random random = new Random(seed); RAMDirectory directory = new RAMDirectory(); IndexOutput output = directory.createOutput("test", IOContext.DEFAULT); Cache cache = CacheIndexInputTest.getCache(); CacheIndexOutput indexOutput = new CacheIndexOutput(null, "test", output, cache); indexOutput.writeByte((byte) 1); indexOutput.writeByte((byte) 2); byte[] b = new byte[16000]; random.nextBytes(b);//w w w. ja v a 2 s . c o m 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:com.bah.lucene.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); IndexOutput output2 = directory2.createOutput(name, IOContext.DEFAULT); CacheIndexOutput cacheIndexOutput = new CacheIndexOutput(null, name, output2, cache); CacheIndexInputTest.writeRandomData(size, random, output, cacheIndexOutput); output.close();/*from w w w .j av a2 s . com*/ 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:com.basistech.lucene.tools.LuceneQueryToolTest.java
License:Apache License
@BeforeClass public static void oneTimeSetup() throws IOException, ParseException { LuceneQueryToolTest.showOutput = false; // for debugging tests Directory dir = new RAMDirectory(); Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); Document doc = new Document(); doc.add(new Field("longest-mention", "Bill Clinton", StringField.TYPE_STORED)); doc.add(new Field("context", "Hillary Clinton Arkansas", TextField.TYPE_NOT_STORED)); writer.addDocument(doc);/*w w w . j ava2 s . co m*/ doc = new Document(); doc.add(new Field("longest-mention", "George W. Bush", StringField.TYPE_STORED)); doc.add(new Field("context", "Texas Laura Bush", TextField.TYPE_NOT_STORED)); writer.addDocument(doc); doc = new Document(); doc.add(new Field("longest-mention", "George H. W. Bush", StringField.TYPE_STORED)); doc.add(new Field("context", "Barbara Bush Texas", TextField.TYPE_NOT_STORED)); writer.addDocument(doc); doc = new Document(); doc.add(new Field("bbb", "foo", StringField.TYPE_STORED)); doc.add(new Field("bbb", "bar", StringField.TYPE_STORED)); doc.add(new Field("aaa", "foo", StringField.TYPE_STORED)); FieldType typeUnindexed = new FieldType(StringField.TYPE_STORED); typeUnindexed.setIndexOptions(IndexOptions.NONE); doc.add(new Field("zzz", "foo", typeUnindexed)); writer.addDocument(doc); writer.close(); reader = DirectoryReader.open(dir); }
From source file:com.basistech.lucene.tools.LuceneQueryToolTest.java
License:Apache License
@Test public void testBinaryField() throws IOException, ParseException { Directory dir = new RAMDirectory(); Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); Document doc = new Document(); doc.add(new Field("id", "1", StringField.TYPE_STORED)); doc.add(new Field("binary-field", "ABC".getBytes(Charsets.UTF_8), StoredField.TYPE)); writer.addDocument(doc);//w ww. j ava 2s . c o m writer.close(); reader = DirectoryReader.open(dir); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); LuceneQueryTool lqt = new LuceneQueryTool(reader, out); lqt.run(new String[] { "id:1" }); String result = Joiner.on('\n').join(getOutput(bytes)); assertTrue(result.contains("0x414243")); // binary rep of "ABC" }
From source file:com.bizosys.hsearch.dictionary.DictionaryValues.java
License:Apache License
public int load(Set<String> wordDescription, Writer outputWriter, Analyzer analyzer) throws Exception { if (null != reader) { try {//from w ww .j ava2 s . c o m reader.close(); if (null != searcher) searcher.close(); } catch (Exception ex) { } } this.idx = new RAMDirectory(); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_35, analyzer); IndexWriter writer = new IndexWriter(this.idx, indexWriterConfig); int linesAdded = 0; for (String line : wordDescription) { writer.addDocument(createDocument(line)); linesAdded++; } if (null != outputWriter) outputWriter.append("----------\n</BR>Total Lines Loaded : ") .append(new Integer(linesAdded).toString()); writer.close(); reader = IndexReader.open(this.idx); searcher = new IndexSearcher(reader); return linesAdded; }
From source file:com.bizosys.hsearch.dictionary.DictionaryValues.java
License:Apache License
private Directory loadFile(String file, Writer outputWriter) throws Exception { RAMDirectory idx = new RAMDirectory(); IndexWriter writer = new IndexWriter(idx, new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); loadFileAndIndex(file, writer, outputWriter); writer.close();// www . j ava 2s. com return idx; }
From source file:com.browseengine.bobo.facets.attribute.AttributesFacetHandlerTest.java
License:Apache License
@Override protected void setUp() throws Exception { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); selectionProperties = new HashMap<String, String>(); IndexWriter writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop5=val1")); writer.addDocument(doc("prop1=val2", "prop3=val1", "prop7=val7")); writer.addDocument(doc("prop1=val2", "prop3=val2", "prop3=val3")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop4=val2", "prop4=val3")); writer.commit();//from ww w. jav a 2 s. c o m attributesFacetHandler = new AttributesFacetHandler(AttributeHandlerName, AttributeHandlerName, null, null, new HashMap<String, String>()); facetHandlers.add(attributesFacetHandler); IndexReader reader = IndexReader.open(directory, true); boboReader = BoboIndexReader.getInstance(reader, facetHandlers); attributesFacetHandler.loadFacetData(boboReader); browser = new BoboBrowser(boboReader); }
From source file:com.browseengine.bobo.facets.attribute.AttributesFacetHandlerTest.java
License:Apache License
private void modifiedSetup() throws CorruptIndexException, LockObtainFailedException, IOException { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); IndexWriter writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop5=val1")); writer.addDocument(doc("prop1=val2", "prop3=val1", "prop7=val7")); writer.addDocument(doc("prop1=val2", "prop3=val2", "prop3=val3")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop4=val2", "prop4=val3")); writer.commit();/*from w ww . j a v a 2s . c om*/ HashMap<String, String> facetProps = new HashMap<String, String>(); facetProps.put(AttributesFacetHandler.MAX_FACETS_PER_KEY_PROP_NAME, "1"); attributesFacetHandler = new AttributesFacetHandler(AttributeHandlerName, AttributeHandlerName, null, null, facetProps); facetHandlers.add(attributesFacetHandler); IndexReader reader = IndexReader.open(directory, true); boboReader = BoboIndexReader.getInstance(reader, facetHandlers); attributesFacetHandler.loadFacetData(boboReader); browser = new BoboBrowser(boboReader); }
From source file:com.browseengine.bobo.geosearch.impl.IGeoRecordSerializerTezt.java
License:Apache License
@Before public void setUp() { testFileName = UUID.randomUUID().toString(); directory = new RAMDirectory(); geoRecordSerializer = getGeoRecordSerializer(); }
From source file:com.browseengine.bobo.geosearch.index.impl.GeoIndexerTest.java
License:Apache License
@Test public void testIndexAndFlush_multipleThreads() throws InterruptedException, IOException { Directory ramDirectory = new RAMDirectory(); final int docsToAddPerThread = 10; final int numThreads = 10; final CountDownLatch latch = new CountDownLatch(numThreads); for (int i = 0; i < numThreads; i++) { Runnable runnable = new Runnable() { @Override/* w ww . j ava 2 s. c o m*/ public void run() { try { for (int i = 0; i < docsToAddPerThread; i++) { float lattitide = (float) Math.random(); float longitude = (float) Math.random(); String fieldName = unmappedLocation; GeoCoordinate geoCoordinate = new GeoCoordinate(lattitide, longitude); GeoCoordinateField field = new GeoCoordinateField(fieldName, geoCoordinate); geoIndexerNoMocks.index(i, field); } } finally { latch.countDown(); } } }; Thread thread = new Thread(runnable); thread.start(); } latch.await(500, TimeUnit.MILLISECONDS); assertEquals("not all threads compeleted", 0, latch.getCount()); geoIndexerNoMocks.flush(ramDirectory, segmentName); readAndVerifyGeoIndex(ramDirectory, segmentName, docsToAddPerThread * numThreads); }