Search in sources :

Example 1 with LastModFrom

use of org.apache.solr.core.SolrConfig.HttpCachingConfig.LastModFrom in project lucene-solr by apache.

the class HttpCacheHeaderUtil method calcLastModified.

/**
   * Calculate the appropriate last-modified time for Solr relative the current request.
   * 
   * @return the timestamp to use as a last modified time.
   */
public static long calcLastModified(final SolrQueryRequest solrReq) {
    final SolrCore core = solrReq.getCore();
    final SolrIndexSearcher searcher = solrReq.getSearcher();
    final LastModFrom lastModFrom = core.getSolrConfig().getHttpCachingConfig().getLastModFrom();
    long lastMod;
    try {
        // assume default, change if needed (getOpenTime() should be fast)
        lastMod = LastModFrom.DIRLASTMOD == lastModFrom ? IndexDeletionPolicyWrapper.getCommitTimestamp(searcher.getIndexReader().getIndexCommit()) : searcher.getOpenTimeStamp().getTime();
    } catch (IOException e) {
        // we're pretty freaking screwed if this happens
        throw new SolrException(ErrorCode.SERVER_ERROR, e);
    }
    // second granularity
    return lastMod - (lastMod % 1000L);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IOException(java.io.IOException) LastModFrom(org.apache.solr.core.SolrConfig.HttpCachingConfig.LastModFrom) SolrException(org.apache.solr.common.SolrException)

Aggregations

IOException (java.io.IOException)1 SolrException (org.apache.solr.common.SolrException)1 LastModFrom (org.apache.solr.core.SolrConfig.HttpCachingConfig.LastModFrom)1 SolrCore (org.apache.solr.core.SolrCore)1 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)1