/// <summary> /// This is used to determine if a search index change type should be mapped to a /// <see cref="SearchDocument.UpdateLatest"/> document. /// </summary> private bool IsUpdateLatest(SearchIndexChangeType changeType) { switch (changeType) { case SearchIndexChangeType.AddFirst: case SearchIndexChangeType.UpdateLatest: case SearchIndexChangeType.DowngradeLatest: return(true); default: return(false); } }
private IndexAction <KeyedDocument> GetSearchIndexAction( NewPackageRegistration packageRegistration, IReadOnlyDictionary <NuGetVersion, Package> versionToPackage, VersionLists versionLists, SearchFilters searchFilters, SearchIndexChangeType changeType) { if (changeType == SearchIndexChangeType.Delete) { return(IndexAction.Delete(_search.Keyed( packageRegistration.PackageId, searchFilters))); } if (changeType != SearchIndexChangeType.AddFirst) { throw new ArgumentException( $"The only change types supported are {nameof(SearchIndexChangeType.AddFirst)} and " + $"{nameof(SearchIndexChangeType.Delete)}.", nameof(changeType)); } var latestFlags = _search.LatestFlagsOrNull(versionLists, searchFilters); var package = versionToPackage[latestFlags.LatestVersionInfo.ParsedVersion]; var owners = packageRegistration .Owners .OrderBy(u => u, StringComparer.InvariantCultureIgnoreCase) .ToArray(); VerifyConsistency(packageRegistration.PackageId, package); return(IndexAction.Upload <KeyedDocument>(_search.FullFromDb( packageRegistration.PackageId, searchFilters, latestFlags.LatestVersionInfo.ListedFullVersions, latestFlags.IsLatestStable, latestFlags.IsLatest, latestFlags.LatestVersionInfo.FullVersion, package, owners, packageRegistration.TotalDownloadCount, packageRegistration.IsExcludedByDefault))); }
private IndexAction <KeyedDocument> GetSearchIndexAction( Context context, SearchFilters searchFilters, SearchIndexChangeType changeType, string[] owners) { var latestFlags = _search.LatestFlagsOrNull(context.VersionLists, searchFilters); Guard.Assert( changeType == SearchIndexChangeType.Delete || latestFlags != null, "Either the search document is being or there is a latest version."); IndexAction <KeyedDocument> indexAction; if (changeType == SearchIndexChangeType.Delete) { indexAction = IndexAction.Delete(_search.Keyed( context.PackageId, searchFilters)); } else if (changeType == SearchIndexChangeType.UpdateVersionList) { if (owners != null) { // If we have owner information already fetched on behalf of another search document, send the // latest owner information as well. This provides two benefits: // // 1. This keeps all search documents for a package ID in-sync with regards to their owners // fields. // // 2. This means if an admin is reflowing for the purposes of fixing up owner information, all // search documents get the benefit instead of having to reflow the latest version of each // search filter. // indexAction = IndexAction.Merge <KeyedDocument>(_search.UpdateVersionListAndOwnersFromCatalog( context.PackageId, searchFilters, lastCommitTimestamp: context.LastCommitTimestamp, lastCommitId: context.LastCommitId, versions: latestFlags.LatestVersionInfo.ListedFullVersions, isLatestStable: latestFlags.IsLatestStable, isLatest: latestFlags.IsLatest, owners: owners)); } else { indexAction = IndexAction.Merge <KeyedDocument>(_search.UpdateVersionListFromCatalog( context.PackageId, searchFilters, lastCommitTimestamp: context.LastCommitTimestamp, lastCommitId: context.LastCommitId, versions: latestFlags.LatestVersionInfo.ListedFullVersions, isLatestStable: latestFlags.IsLatestStable, isLatest: latestFlags.IsLatest)); } } else if (IsUpdateLatest(changeType)) { var leaf = context.GetLeaf(latestFlags.LatestVersionInfo.ParsedVersion); var normalizedVersion = VerifyConsistencyAndNormalizeVersion(context, leaf); indexAction = IndexAction.MergeOrUpload <KeyedDocument>(_search.UpdateLatestFromCatalog( searchFilters, latestFlags.LatestVersionInfo.ListedFullVersions, latestFlags.IsLatestStable, latestFlags.IsLatest, normalizedVersion, latestFlags.LatestVersionInfo.FullVersion, leaf, owners)); } else { throw new NotImplementedException($"The change type '{changeType}' is not supported."); } _logger.LogInformation( "Search index action prepared for {PackageId} {SearchFilters}: {IndexAction} with a {DocumentType} document.", context.PackageId, searchFilters, indexAction.ActionType, indexAction.Document.GetType().FullName); return(indexAction); }
public LatestIndexChanges(SearchIndexChangeType search, IReadOnlyList <HijackIndexChange> hijack) { Search = search; Hijack = hijack ?? throw new ArgumentNullException(nameof(hijack)); }