public void testRun() throws Exception { String wsName = "test"; DefaultCacheManager dcm = new DefaultCacheManager(); Cache<String, Metadata> metaCache = dcm.getCache("meta"); Cache<String, byte[]> dataCache = dcm.getCache("data"); GridFilesystem gfs = new GridFilesystem(dataCache, metaCache); BuildContext bcontext = DirectoryBuilder.newDirectoryInstance(metaCache, dataCache, metaCache, wsName); bcontext.chunkSize(1024 * 1024); Directory directory = bcontext.create(); Central central = CentralConfig.oldFromDir(directory).build(); central.newIndexer().index(IndexJobs.create("/bleujin", 10)); central.newSearcher().createRequest("").find().debugPrint(); OutputStream output = gfs.getOutput("/test.data"); IOUtil.copyNClose(new StringInputStream("hello bleujin"), output); Debug.line(IOUtil.toStringWithClose(gfs.getInput("/test.data"))); central.newSearcher().createRequest("").find().debugPrint(); File root = gfs.getFile("/"); viewFile(root); dcm.stop(); }
public void testIndex() throws Exception { writeDocument(config, analyzer); long start = System.currentTimeMillis(); Central c = config.build(); Searcher searcher = c.newSearcher(); SearchResponse response = searcher.search("bleujin"); Debug.line(response.size(), System.currentTimeMillis() - start, response.getDocument()); }
public void testApply() throws Exception { Central c = writeDocument(config, analyzer); Central newC = SimpleCentralConfig.createCentral( StorageFac.createToMongo("61.250.201.78", "search", "storageTest")); newC.newSearcher().search("bleujin").debugPrint(); Debug.line('@', config.buildDir().getLockID(), newC.dir().getLockID()); Indexer writer = c.newIndexer(); writer.index( analyzer, new IndexJob<Void>() { public Void handle(IndexSession session) throws Exception { session.insertDocument(MyDocument.testDocument().keyword("name", "bleujin")); return null; } }); newC.newSearcher().search("bleujin").debugPrint(); Debug.line(); }
@Override public void start() { try { String name = ctx.getCache().getName(); EmbeddedCacheManager cacheManager = ctx.getCache().getCacheManager(); Cache<?, ?> metaCache = cacheManager.getCache(name + "-meta"); Cache<?, ?> dataCache = cacheManager.getCache(name + "-chunk"); BuildContext bcontext = DirectoryBuilder.newDirectoryInstance(metaCache, dataCache, metaCache, name); bcontext.chunkSize(1024 * 1024); Directory directory = bcontext.create(); this.central = CentralConfig.oldFromDir(directory) .indexConfigBuilder() .executorService(new WithinThreadExecutor()) .build(); this.configuration.store(this); } catch (Exception e) { throw new PersistenceException(e); } }