List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory
public RAMDirectory()
From source file:lux.functions.InsertDocumentTest.java
License:Mozilla Public License
@BeforeClass public static void setup() throws Exception { RAMDirectory dir = new RAMDirectory(); indexTestSupport = new IndexTestSupport( new XmlIndexer(INDEX_PATHS | INDEX_FULLTEXT | STORE_DOCUMENT | STORE_TINY_BINARY), dir); evaluator = indexTestSupport.makeEvaluator(); }
From source file:lux.functions.KeyTest.java
License:Mozilla Public License
@BeforeClass public static void setup() throws Exception { XmlIndexer indexer = new XmlIndexer(); index = new IndexTestSupport(indexer, new RAMDirectory()); indexer.getConfiguration().addField(new XPathField("doctype_s", "name(/*)", null, Store.YES, Type.STRING)); indexer.getConfiguration().addField(new XPathField("timestamp", "xs:integer((current-dateTime() - xs:dateTime('1970-01-01T00:00:00-00:00')) div xs:dayTimeDuration('PT1S'))", null, Store.YES, Type.INT)); index.indexAllElements("lux/reader-test.xml"); //index= new IndexTestSupport ("lux/reader-test.xml", indexer, new RAMDirectory()); }
From source file:lux.functions.TransformTest.java
License:Mozilla Public License
@Test public void testOutputURIResolution() throws Exception { // test a transform that writes a document using result-document assertXQueryFile(null, "transform-result-document.xqy", "Attempted to write document /doc/1 to a read-only Evaluator"); RAMDirectory dir = new RAMDirectory(); Evaluator writable = Evaluator.createEvaluator(dir); String query = IOUtils.toString(TransformTest.class.getResourceAsStream("transform-result-document.xqy")); writable.evaluate(query);//from www . j a v a 2 s . co m // TODO: make this more convenient. Have an auto-commit at the end of each evaluation // (only when there have been any writes?) and re-open the reader so we can see the results // in subsequent queries writable.getDocWriter().commit(writable); // re-open so that we see the results here writable.reopenSearcher(); XdmResultSet result = writable.evaluate("collection()[1]"); assertEquals("1", result.getXdmValue().itemAt(0).getStringValue()); result = writable.evaluate("doc('/doc/1')"); assertEquals("1", result.getXdmValue().itemAt(0).getStringValue()); }
From source file:lux.IndexTest.java
License:Mozilla Public License
private void reset() { dir.close(); dir = new RAMDirectory(); }
From source file:lux.IndexTest.java
License:Mozilla Public License
@Before public void setup() { dir = new RAMDirectory(); }
From source file:lux.IndexTestSupport.java
License:Mozilla Public License
public IndexTestSupport(String... xmlFiles) throws XMLStreamException, IOException, SaxonApiException { this(xmlFiles, new XmlIndexer(INDEX_QNAMES | INDEX_PATHS | STORE_DOCUMENT | INDEX_FULLTEXT), new RAMDirectory()); }
From source file:net.bible.service.sword.PdaLuceneIndexCreator.java
License:Open Source License
/** * @param book/*from www .j ava2 s . co m*/ * @param job * @param analyzer * @param errors * @param tempPath * @throws CorruptIndexException * @throws LockObtainFailedException * @throws IOException * @throws BookException */ private void createIndex(Book book, Progress job, Analyzer analyzer, List errors, File tempPath) throws CorruptIndexException, LockObtainFailedException, IOException, BookException { Log.d(TAG, "Getting global key list for " + book.getName()); Key allKeys = book.getGlobalKeyList(); Log.d(TAG, "Got global key list"); int numKeys = allKeys.getCardinality(); Log.d(TAG, "Total keys:" + numKeys); int tenthCount = numKeys / 10; Directory[] tempIndexFiles = new Directory[10]; for (int tenth = 0; tenth < 2; tenth++) { int startKey = tenth * tenthCount; int endKey = (tenth + 1) * tenthCount; Key currentKeys = book.createEmptyKeyList(); for (int i = startKey; i < endKey; i++) { Key key = allKeys.get(i); Log.d(TAG, "Adding key:" + key.getName()); currentKeys.addAll(key); } Log.d(TAG, "1"); // Create the index in core. final RAMDirectory ramDir = new RAMDirectory(); Log.d(TAG, "2"); IndexWriter writer = new IndexWriter(ramDir, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); Log.d(TAG, "3"); generateSearchIndexImpl(job, errors, writer, currentKeys, 0); Log.d(TAG, "4"); job.setSectionName(UserMsg.OPTIMIZING.toString()); // job.setWork(95); // Consolidate the index into the minimum number of files. // writer.optimize(); /* Optimize is done by addIndexes */ writer.close(); Log.d(TAG, "5"); // Write the core index to disk. String tempFilePath = tempPath.getCanonicalPath() + tenth; Log.d(TAG, "temp index path:" + tempFilePath); final Directory destination = FSDirectory.open(new File(tempFilePath)); Log.d(TAG, "6"); IndexWriter fsWriter = new IndexWriter(destination, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); Log.d(TAG, "7"); fsWriter.addIndexesNoOptimize(new Directory[] { ramDir }); Log.d(TAG, "8"); fsWriter.optimize(); Log.d(TAG, "9"); fsWriter.close(); Log.d(TAG, "10"); // Free up the space used by the ram directory ramDir.close(); Log.d(TAG, "11"); tempIndexFiles[tenth] = destination; Log.d(TAG, "12"); } Log.d(TAG, "13"); final Directory destination = FSDirectory.open(new File(tempPath.getCanonicalPath())); Log.d(TAG, "14"); IndexWriter fsWriter = new IndexWriter(destination, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); Log.d(TAG, "15"); fsWriter.addIndexesNoOptimize(tempIndexFiles); Log.d(TAG, "16"); fsWriter.optimize(); Log.d(TAG, "17"); fsWriter.close(); }
From source file:net.chwise.index.FakeDirectoryInitializer.java
License:Open Source License
@Override public Directory getDirectory() { Directory directory = null;//from w w w. j a v a 2 s.c om IndexWriter indexWriter = null; try { directory = new RAMDirectory(); Analyzer analyzer = DocDefinitions.getAnalyzer(); Document[] fakeDocs = getFakeDocuments(); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer); indexWriter = new IndexWriter(directory, config); for (Document doc : fakeDocs) { indexWriter.addDocument(doc); } } catch (IOException e) { throw new RuntimeException("Exception during creatingi fake index.", e); } finally { if (indexWriter != null) try { indexWriter.close(); } catch (IOException e) { throw new RuntimeException("Exception during closing index.", e); } } return directory; }
From source file:net.conquiris.index.AbstractDirectoryIndexerServiceTest.java
License:Apache License
final void create(Indexer indexer) { directory = new RAMDirectory(); searcher = Searchers.service(ReaderSuppliers.directory(directory)); service = new DirectoryIndexerService(indexer, directory, Conquiris.writerConfigSupplier()); service.setDelays(Delays.constant(50)); }
From source file:net.conquiris.jersey.itest.TestIndexerServiceProvider.java
License:Apache License
public static synchronized LocalIndexerService get() { if (service == null) { RAMDirectory d = new RAMDirectory(); service = new DirectoryIndexerService(new TestIndexer(), d, Conquiris.writerConfigSupplier()); }//from w w w. j a v a2 s . c om return service; }