Search code examples
solrrequesthandler

How to get IndexReader from custom request handler?


This is extension of my earlier question.

I'm going to create custom request handler to provide terms association mining over existing index. In order to do this I need access to Solr's IndexReader opened on default index directory.

The only way to do this I can think of is to get IndexReaderFactory by invoking SolrQueryRequest.getCore().getIndexReaderFactory(). This factory has method newReader() which seems to be what I need. But this method requires index directory as its first argument.

Here's my question: is it correct way to get IndexReader? If so, how can I get Solr's index directory? Can I access Solr configuration to find it from my code or should I go with something else?


Solution

  • I found an answer myself while reading LukeRequestHandler source:

    SolrIndexSearcher searcher = req.getSearcher();
    IndexReader reader = searcher.getReader();
    

    So they first get searcher, and only then reader.