Search in sources :

Example 51 with SolrIndexSearcher

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();
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) SolrCore(org.apache.solr.core.SolrCore) IndexReader(org.apache.lucene.index.IndexReader) TaggerFstCorpus(org.opensextant.solrtexttagger.TaggerFstCorpus) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Example 52 with SolrIndexSearcher

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);
    }
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) TaggerFstCorpus(org.opensextant.solrtexttagger.TaggerFstCorpus) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IOException(java.io.IOException)

Example 53 with SolrIndexSearcher

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;
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 54 with SolrIndexSearcher

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();
    }
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 55 with SolrIndexSearcher

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();
}
Also used : SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Test(org.junit.Test)

Aggregations

SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)97 SolrException (org.apache.solr.common.SolrException)29 NamedList (org.apache.solr.common.util.NamedList)29 SolrCore (org.apache.solr.core.SolrCore)28 IOException (java.io.IOException)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)20 SolrParams (org.apache.solr.common.params.SolrParams)19 SchemaField (org.apache.solr.schema.SchemaField)18 IndexReader (org.apache.lucene.index.IndexReader)13 DocList (org.apache.solr.search.DocList)13 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)12 Map (java.util.Map)11 Document (org.apache.lucene.document.Document)11 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)11 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)11 IndexSchema (org.apache.solr.schema.IndexSchema)11 LeafReader (org.apache.lucene.index.LeafReader)10 Query (org.apache.lucene.search.Query)10 HashMap (java.util.HashMap)9