// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

        protected override void Warm(IndexSearcher searcher)
        {
            searcher.Search(new MatchAllDocsQuery(), 1);

            // Create the tenant filters
            _filters = new Dictionary<string, Filter>();
            IEnumerable<string> tenantIds = PackageTenantId.GetDistintTenantId(searcher.IndexReader);
            foreach (string tenantId in tenantIds)
            {
                _filters.Add(tenantId, new CachingWrapperFilter(new TenantFilter(tenantId)));
            }
            _publicFilter = new CachingWrapperFilter(new PublicFilter());

            _latestVersion = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, false, false));
            _latestVersionIncludeUnlisted = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, false, true));
            _latestVersionIncludePrerelease = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, true, false));
            _latestVersionIncludePrereleaseIncludeUnlisted = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, true, true));

            // Recalculate precalculated Versions arrays 
            PackageVersions packageVersions = new PackageVersions(searcher.IndexReader);
            _versionsByDoc = packageVersions.CreateVersionsLookUp(null);
            _versionListsByDoc = packageVersions.CreateVersionListsLookUp();

            // Set metadata
            LastReopen = DateTime.UtcNow;
            NumDocs = searcher.IndexReader.NumDocs();
            CommitUserData = searcher.IndexReader.CommitUserData;
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override void Warm(IndexSearcher searcher)
        {
            searcher.Search(new MatchAllDocsQuery(), 1);

            // Create the tenant filters
            _filters = new Dictionary <string, Filter>();
            IEnumerable <string> tenantIds = PackageTenantId.GetDistintTenantId(searcher.IndexReader);

            foreach (string tenantId in tenantIds)
            {
                _filters.Add(tenantId, new CachingWrapperFilter(new TenantFilter(tenantId)));
            }
            _publicFilter = new CachingWrapperFilter(new PublicFilter());

            _latestVersion = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, false, false));
            _latestVersionIncludeUnlisted   = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, false, true));
            _latestVersionIncludePrerelease = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, true, false));
            _latestVersionIncludePrereleaseIncludeUnlisted = new CachingWrapperFilter(LatestVersionFilter.Create(searcher.IndexReader, true, true));

            // Recalculate precalculated Versions arrays
            PackageVersions packageVersions = new PackageVersions(searcher.IndexReader);

            _versionsByDoc          = new Dictionary <string, JArray[]>();
            _versionsByDoc["http"]  = packageVersions.CreateVersionsLookUp(null, RegistrationBaseAddress["http"]);
            _versionsByDoc["https"] = packageVersions.CreateVersionsLookUp(null, RegistrationBaseAddress["https"]);

            _versionListsByDoc = packageVersions.CreateVersionListsLookUp();

            LastReopen = DateTime.UtcNow;
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override void Warm(IndexSearcher searcher)
        {
            searcher.Search(new MatchAllDocsQuery(), 1);

            // Reload download counts and rankings synchronously
            _currentDownloadCounts.Reload();
            _currentRankings.Reload();
            _currentFrameworkCompatibility.Reload();

            // Recalculate all the framework compatibility filters
            _filters = Compatibility.Warm(searcher.IndexReader, _currentFrameworkCompatibility.Value);

            // Recalculate precalculated Versions arrays
            PackageVersions packageVersions = new PackageVersions(searcher.IndexReader);

            _versionsByDoc          = new Dictionary <string, JArray[]>();
            _versionsByDoc["http"]  = packageVersions.CreateVersionsLookUp(_currentDownloadCounts.Value, RegistrationBaseAddress["http"]);
            _versionsByDoc["https"] = packageVersions.CreateVersionsLookUp(_currentDownloadCounts.Value, RegistrationBaseAddress["https"]);

            _versionListsByDoc = packageVersions.CreateVersionListsLookUp();

            LastReopen = DateTime.UtcNow;
        }
        static void UpdateMatchingDocs(IDictionary <string, MatchingDocsEntry> matchingDocsLookup, SegmentReader reader, IDictionary <string, ISet <string> > frameworkCompatibility)
        {
            for (int doc = 0; doc < reader.MaxDoc; doc++)
            {
                if (reader.IsDeleted(doc))
                {
                    continue;
                }

                Document document = reader.Document(doc);

                string id = PackageVersions.GetId(document);

                if (id == null)
                {
                    continue;
                }

                NuGetVersion version = PackageVersions.GetVersion(document);

                if (version == null)
                {
                    continue;
                }

                Field[] frameworks = document.GetFields("TargetFramework");

                foreach (KeyValuePair <string, ISet <string> > frameworkKV in frameworkCompatibility)
                {
                    bool isCompatible = false;

                    if (frameworkKV.Key == "any")
                    {
                        isCompatible = true;
                    }
                    else
                    {
                        foreach (Field frameworkField in frameworks)
                        {
                            string framework = frameworkField.StringValue;
                            if (framework == "any" || framework == "agnostic" || frameworkKV.Value.Contains(framework))
                            {
                                isCompatible = true;
                            }
                        }
                    }

                    MatchingDocsEntry entry = matchingDocsLookup[frameworkKV.Key];

                    if (isCompatible)
                    {
                        if (!version.IsPrerelease)
                        {
                            if (!entry.MatchingDocs.ContainsKey(id) || entry.MatchingDocs[id].Version < version)
                            {
                                entry.MatchingDocs[id] = new MatchingDoc {
                                    Version = version, SegmentName = reader.SegmentName, Doc = doc
                                };
                            }
                        }

                        if (!entry.MatchingDocsPre.ContainsKey(id) || entry.MatchingDocsPre[id].Version < version)
                        {
                            entry.MatchingDocsPre[id] = new MatchingDoc {
                                Version = version, SegmentName = reader.SegmentName, Doc = doc
                            };
                        }
                    }
                }
            }
        }