List of usage examples for org.apache.solr.core SolrCore getNewestSearcher
public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
From source file:com.billiger.solr.handler.component.QLTBComponent.java
License:Apache License
/** * Inform component of core reload./*from w w w . ja v a 2s. c o m*/ * * This will both set the analyzer according to the configured * queryFieldType, and load the QLTB data. Data source can be (in this * order) ZooKeeper, the conf/ directory or the data/ directory. */ @Override public final void inform(final SolrCore core) { // load analyzer String queryFieldType = initArgs.get(FIELD_TYPE); if (queryFieldType != null) { FieldType ft = core.getLatestSchema().getFieldTypes().get(queryFieldType); if (ft == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "unknown FieldType \"" + queryFieldType + "\" used in QLTBComponent"); } analyzer = ft.getQueryAnalyzer(); } else { analyzer = null; } synchronized (qltbCache) { qltbCache.clear(); try { // retrieve QLTB data filename String qltbFile = initArgs.get(QLTB_FILE); if (qltbFile == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QLTBComponent must specify argument: \"" + QLTB_FILE + "\" - path to QLTB data"); } boolean exists = false; // check ZooKeeper ZkController zkController = core.getCoreDescriptor().getCoreContainer().getZkController(); if (zkController != null) { exists = zkController.configFileExists(zkController.readConfigName( core.getCoreDescriptor().getCloudDescriptor().getCollectionName()), qltbFile); } else { // no ZooKeeper, check conf/ and data/ directories File fConf = new File(core.getResourceLoader().getConfigDir(), qltbFile); File fData = new File(core.getDataDir(), qltbFile); if (fConf.exists() == fData.exists()) { // both or neither exist throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QLTBComponent missing config file: \"" + qltbFile + "\": either " + fConf.getAbsolutePath() + " or " + fData.getAbsolutePath() + " must exist, but not both"); } if (fConf.exists()) { // conf/ found, load it exists = true; log.info("QLTB source conf/: " + fConf.getAbsolutePath()); Config cfg = new Config(core.getResourceLoader(), qltbFile); qltbCache.put(null, loadQLTBMap(cfg, core)); } } if (!exists) { // Neither ZooKeeper nor conf/, so must be in data/ // We need an IndexReader and the normal RefCounted<SolrIndexSearcher> searcher = null; try { searcher = core.getNewestSearcher(false); IndexReader reader = searcher.get().getIndexReader(); getQLTBMap(reader, core); } finally { if (searcher != null) { searcher.decref(); } } } } catch (Exception ex) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error initializing QltbComponent.", ex); } } }
From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java
License:Apache License
DirectoryReader newReaderInternal(Directory indexDir, IndexWriter writer, SolrCore core) throws IOException { DirectoryReader main = null;/*from w w w. j a va2 s. co m*/ if (writer != null) { main = standardFactory.newReader(writer, core); } else { main = standardFactory.newReader(indexDir, core); } if (!enabled) { LOG.info("Sidecar index not enabled"); return main; } currentCore = core; CoreContainer container = core.getCoreDescriptor().getCoreContainer(); SolrCore source = container.getCore(sourceCollection); if (source == null) { LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled."); try { return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main), sourceCollection, null); } catch (Exception e1) { LOG.warn("Unexpected exception, returning single main index", e1); return main; } } if (source.isClosed()) { LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled."); try { return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main), sourceCollection, null); } catch (Exception e1) { LOG.warn("Unexpected exception, returning single main index", e1); return main; } } DirectoryReader parallel = null; SolrIndexSearcher searcher = null; try { searcher = source.getNewestSearcher(true).get(); parallel = buildParallelReader(main, searcher, true); } finally { if (searcher != null) { LOG.info("-- closing " + searcher); searcher.close(); } source.close(); } return parallel; }
From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java
License:Apache License
DirectoryReader reopen(DirectoryReader newMain, boolean rebuild) throws IOException { CoreContainer container = currentCore.getCoreDescriptor().getCoreContainer(); SolrCore source = container.getCore(sourceCollection); if (source == null) { LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled."); try {/* w ww . ja v a 2 s.c o m*/ return new SidecarIndexReader(this, newMain, null, SidecarIndexReader.getSequentialSubReaders(newMain), sourceCollection, null); } catch (Exception e1) { LOG.warn("Unexpected exception, returning single main index", e1); return newMain; } } if (source.isClosed()) { LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled."); try { return new SidecarIndexReader(this, newMain, null, SidecarIndexReader.getSequentialSubReaders(newMain), sourceCollection, null); } catch (Exception e1) { LOG.warn("Unexpected exception, returning single main index", e1); return newMain; } } DirectoryReader parallel = null; SolrIndexSearcher searcher = null; try { searcher = source.getNewestSearcher(true).get(); parallel = buildParallelReader(newMain, searcher, rebuild); } finally { if (searcher != null && searcher.getIndexReader().getRefCount() > 0) { LOG.info("-- closing " + searcher); searcher.close(); } if (source != null) { source.close(); } } return parallel; }