use of org.apache.solr.search.SolrIndexSearcher in project stanbol by apache.
the class CorpusCreationTask method call.
@Override
public TaggerFstCorpus call() {
if (!indexConfig.isActive()) {
String msg = "Index Configuration already deactivated";
fstInfo.setError(msg);
throw new IllegalStateException(msg);
}
SolrCore core = indexConfig.getIndex();
if (core.isClosed()) {
String msg = "Unable to build " + fstInfo + " becuase SolrCore " + core.getName() + " is closed!";
fstInfo.setError(msg);
throw new IllegalStateException(msg);
}
final TaggerFstCorpus corpus;
RefCounted<SolrIndexSearcher> searcherRef = core.getSearcher();
try {
//STANBOL-1177: create FST models in AccessController.doPrivileged(..)
final SolrIndexSearcher searcher = searcherRef.get();
//we do get the AtomicReader, because TaggerFstCorpus will need it
//anyways. This prevents to create another SlowCompositeReaderWrapper.
final IndexReader reader = searcher.getAtomicReader();
log.info(" ... build FST corpus for {}", fstInfo);
corpus = AccessController.doPrivileged(new PrivilegedExceptionAction<TaggerFstCorpus>() {
public TaggerFstCorpus run() throws IOException {
return new TaggerFstCorpus(reader, searcher.getIndexReader().getVersion(), null, fstInfo.indexedField, fstInfo.storedField, fstInfo.analyzer, fstInfo.partialMatches, 1, 100);
}
});
if (indexConfig.isActive()) {
//set the created corpus to the FST Info
fstInfo.setCorpus(corpus);
} else {
//index configuration no longer active ... ignore the built FST
log.warn("Index Config for " + fstInfo + "was deactivated while building FST. " + "Built FST will be ignored.");
}
return corpus;
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof IOException) {
//IO Exception while loading the file
throw new IllegalStateException("Unable to read Information to build " + fstInfo + " from SolrIndex '" + core.getName() + "'!", e);
} else {
//Runtime exception
throw RuntimeException.class.cast(e);
}
} finally {
//ensure that we dereference the searcher
searcherRef.decref();
}
}
use of org.apache.solr.search.SolrIndexSearcher in project stanbol by apache.
the class CorpusCreationTask method run.
@Override
public void run() {
TaggerFstCorpus corpus = null;
RefCounted<SolrIndexSearcher> searcherRef = core.getSearcher();
try {
SolrIndexSearcher searcher = searcherRef.get();
//we do get the AtomicReader, because TaggerFstCorpus will need it
//anyways. This prevents to create another SlowCompositeReaderWrapper.
IndexReader reader = searcher.getAtomicReader();
log.info(" ... build {}", corpusInfo);
corpus = new TaggerFstCorpus(reader, searcher.getIndexReader().getVersion(), null, corpusInfo.indexedField, corpusInfo.storedField, corpusInfo.analyzer, corpusInfo.partialMatches, 1, 200);
} catch (IOException e) {
throw new IllegalStateException("Unable to read Information to build " + corpusInfo + " from SolrIndex '" + core.getName() + "'!", e);
} finally {
//ensure that we dereference the searcher
searcherRef.decref();
}
if (corpusInfo.fst.exists()) {
if (!FileUtils.deleteQuietly(corpusInfo.fst)) {
log.warn("Unable to delete existing FST fiel for {}", corpusInfo);
}
}
if (corpus.getPhrases() != null) {
//the FST is not empty
try {
//NOTE saving an empty corpus results in a NPE
corpus.save(corpusInfo.fst);
} catch (IOException e) {
log.warn("Unable to store FST corpus " + corpusInfo + " to " + corpusInfo.fst.getAbsolutePath() + "!", e);
}
} else {
log.info("FST for {} is empty ... no FST will be stored", corpusInfo);
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestNRTOpen method getCoreCacheKeys.
private Set<Object> getCoreCacheKeys() {
RefCounted<SolrIndexSearcher> searcher = h.getCore().getSearcher();
Set<Object> set = Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>());
try {
DirectoryReader ir = searcher.get().getRawReader();
for (LeafReaderContext context : ir.leaves()) {
set.add(context.reader().getCoreCacheHelper().getKey());
}
} finally {
searcher.decref();
}
return set;
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestNRTOpen method assertNRT.
static void assertNRT(int maxDoc) {
RefCounted<SolrIndexSearcher> searcher = h.getCore().getSearcher();
try {
DirectoryReader ir = searcher.get().getRawReader();
assertEquals(maxDoc, ir.maxDoc());
assertTrue("expected NRT reader, got: " + ir, ir.toString().contains(":nrt"));
} finally {
searcher.decref();
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestQuerySenderListener method testSearcherEvents.
@Test
public void testSearcherEvents() throws Exception {
SolrCore core = h.getCore();
SolrEventListener newSearcherListener = core.newSearcherListeners.get(0);
assertTrue("Not an instance of QuerySenderListener", newSearcherListener instanceof QuerySenderListener);
QuerySenderListener qsl = (QuerySenderListener) newSearcherListener;
RefCounted<SolrIndexSearcher> currentSearcherRef = core.getSearcher();
SolrIndexSearcher currentSearcher = currentSearcherRef.get();
//test new Searcher
qsl.newSearcher(currentSearcher, null);
MockQuerySenderListenerReqHandler mock = (MockQuerySenderListenerReqHandler) core.getRequestHandler("mock");
assertNotNull("Mock is null", mock);
String evt = mock.req.getParams().get(EventParams.EVENT);
assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
assertU(adoc("id", "1"));
assertU(commit());
RefCounted<SolrIndexSearcher> newSearcherRef = core.getSearcher();
evt = mock.req.getParams().get(EventParams.EVENT);
assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER) == true);
newSearcherRef.decref();
currentSearcherRef.decref();
}
Aggregations