Search code examples
solrfull-text-searchsolrcloud

Can solr cache requests in advance?


In my system I have pool of complicated requests that i would to offer to user. User could use my variants or type own requests. Can solr cache my variants of requests in advance, when it build index?


Solution

  • There is no warm cache during building indices in Solr, however, there is a functionality called query related listeners, with this you could warm the Index Searchers while they are starting.

    There are two types of events - firstSearcher (this is usually happening on Solr startup) and newSearcher, which is triggered when a new searcher is being prepared (hard commit could be one of the example of such event)

    The part in the solrconfig.xml could look like this:

    <listener event="newSearcher" class="solr.QuerySenderListener">
      <arr name="queries">
      <!-- 
        <lst><str name="q">solr</str><str name="sort">price asc</str></lst>
    
       -->
      </arr>
    </listener>
    
    <listener event="firstSearcher" class="solr.QuerySenderListener">
      <arr name="queries">
        <lst><str name="q">static firstSearcher warming in solrconfig.xml</str></lst>
      </arr>
    </listener>
    

    What you need to do - is to list your heavy queries so they will be warmed up before serving search requests. This should make your searches faster later on.

    Don’t forget the usual rules about using filter properly, so that FilterCache will be populated properly as well.