public ManualResetEvent SetIndexSearcher(IndexSearcher searcher, bool wait) { var old = current; current = new IndexSearcherHoldingState(searcher); if (old == null) { return(null); } // here we try to make sure that the actual facet cache is up to do when we update the index searcher. // we use this to ensure that any facets that has been recently queried is warmed up and in the cache if (searcher != null && context.Configuration.PrewarmFacetsOnIndexingMaxAge != TimeSpan.Zero) { var usedFacets = old.GetUsedFacets(context.Configuration.PrewarmFacetsOnIndexingMaxAge).ToArray(); if (usedFacets.Length > 0) { var preFillCache = Task.Factory.StartNew(() => { var sp = Stopwatch.StartNew(); try { IndexedTerms.PreFillCache(current, usedFacets, searcher.IndexReader); } catch (Exception e) { Log.WarnException( string.Format("Failed to properly pre-warm the facets cache ({1}) for index {0}", indexId, string.Join(",", usedFacets)), e); } finally { Log.Debug("Pre-warming the facet cache for {0} took {2}. Facets: {1}", indexId, string.Join(",", usedFacets), sp.Elapsed); } }); preFillCache.Wait(context.Configuration.PrewarmFacetsSyncronousWaitTime); } } Interlocked.Increment(ref old.Usage); using (old) { if (wait) { return(old.MarkForDisposalWithWait()); } old.MarkForDisposal(); return(null); } }
public RavenJObject[] GetOrCreateTerms() { if (readEntriesFromIndex != null) { return(readEntriesFromIndex); } var indexReader = IndexSearcher.IndexReader; readEntriesFromIndex = IndexedTerms.ReadAllEntriesFromIndex(indexReader); return(readEntriesFromIndex); }