private VersionResult CreateVersionResult(string id, List <RegistrationEntry> registrationEntries, DownloadsByVersion downloadsByVersion) { VersionResult result = new VersionResult(); foreach (var registrationEntry in registrationEntries.OrderBy(r => r.Version)) { string fullVersion = String.Intern(registrationEntry.Version.ToFullString()); string normalizedVersion = String.Intern(registrationEntry.Version.ToNormalizedString()); int downloads = 0; if (downloadsByVersion != null) { downloads = downloadsByVersion[normalizedVersion]; } result.AllVersionDetails.Add(new VersionDetail { NormalizedVersion = normalizedVersion, FullVersion = fullVersion, Downloads = downloads, IsStable = !registrationEntry.Version.IsPrerelease, IsListed = registrationEntry.IsListed, IsSemVer2 = registrationEntry.Version.IsSemVer2 }); } return(result); }
private static void WriteVersions(JsonWriter jsonWriter, Uri baseAddress, string id, bool includePrerelease, NuGetVersion semVerLevel, VersionResult versionResult) { var includeSemVer2 = SemVerHelpers.ShouldIncludeSemVer2Results(semVerLevel); jsonWriter.WritePropertyName("versions"); jsonWriter.WriteStartArray(); var results = includePrerelease ? (includeSemVer2 ? versionResult.SemVer2VersionDetails : versionResult.LegacyVersionDetails) : (includeSemVer2 ? versionResult.StableSemVer2VersionDetails : versionResult.StableLegacyVersionDetails); foreach (var item in results.Where(r => r.IsListed)) { var relativeAddress = UriFormatter.MakePackageRelativeAddress(id, item.NormalizedVersion); var absoluteAddress = new Uri(baseAddress, relativeAddress).AbsoluteUri; jsonWriter.WriteStartObject(); WriteProperty(jsonWriter, "version", item.FullVersion); WriteProperty(jsonWriter, "downloads", item.Downloads); WriteProperty(jsonWriter, "@id", absoluteAddress); jsonWriter.WriteEndObject(); } jsonWriter.WriteEndArray(); }
public static Tuple <int, int> DownloadCounts(VersionResult versions, string normalizedVersion) { int allVersions = TotalDownloadCounts(versions); int thisVersion = versions.AllVersionDetails .Where(v => v.NormalizedVersion.Equals(normalizedVersion, StringComparison.OrdinalIgnoreCase)) .Select(v => v.Downloads) .FirstOrDefault(); return(Tuple.Create(allVersions, thisVersion)); }
private void CreateResults() { foreach (var registration in _registrations) { var downloadsByVersion = _downloads[registration.Key]; VersionResult versionResult = CreateVersionResult(registration.Key, registration.Value, downloadsByVersion); foreach (var packageVersion in registration.Value) { Result[packageVersion.DocumentId] = versionResult; } } }
public MockSearcher(string indexName, int numDocs, Dictionary<string, string> commitUserData, VersionResult[] versions = null) : base(manager: InitNuGetSearcherManager(indexName), reader: MockObjectFactory.CreateMockIndexReader(numDocs).Object, commitUserData: commitUserData, curatedFeeds: new Dictionary<string, Filter>(), latest: null, docIdMapping: null, downloads: null, versions: versions, rankings: null, context: null, latestBitSet: Constants.LatestBitSet, latestStableBitSet: Constants.LatestStableBitSet, owners: Constants.EmptyOwnersResult) { MockObjectFactory.MockPrefix = Constants.MockBase; }
public NuGetIndexSearcher( NuGetSearcherManager manager, IndexReader reader, IDictionary<string, string> commitUserData, IDictionary<string, Filter> curatedFeeds, Filter[][] latest, IReadOnlyDictionary<string, int[]> docIdMapping, Downloads downloads, VersionResult[] versions, RankingResult rankings, QueryBoostingContext context, OpenBitSet latestBitSet, OpenBitSet latestStableBitSet, OwnersResult owners) : base(reader) { Manager = manager; CommitUserData = commitUserData; _curatedFeeds = new Dictionary<string, Filter>(curatedFeeds.Count); foreach (var curatedFeedsFilter in curatedFeeds) { _curatedFeeds.Add(curatedFeedsFilter.Key, new CachingWrapperFilter(curatedFeedsFilter.Value)); } _latest = latest; DocIdMapping = docIdMapping; Downloads = downloads; Versions = versions; Rankings = rankings; LatestBitSet = latestBitSet; LatestStableBitSet = latestStableBitSet; Owners = owners; QueryBoostingContext = context; LastReopen = DateTime.UtcNow; }
private VersionResult CreateVersionResult(string id, List<RegistrationEntry> registrationEntries, DownloadsByVersion downloadsByVersion) { VersionResult result = new VersionResult(); foreach (var registrationEntry in registrationEntries.OrderBy(r => r.Version)) { string versionStr = String.Intern(registrationEntry.Version.ToNormalizedString()); int downloads = 0; if (downloadsByVersion != null) { downloads = downloadsByVersion[versionStr]; } result.VersionDetails.Add(new VersionDetail { Version = versionStr, Downloads = downloads, IsStable = !registrationEntry.Version.IsPrerelease, IsListed = registrationEntry.IsListed }); } return result; }
public static int TotalDownloadCounts(VersionResult versions) { int allVersions = versions.AllVersionDetails.Select(v => v.Downloads).Sum(); return(allVersions); }
public static Tuple<int, int> DownloadCounts(VersionResult versions, string version) { int allVersions = TotalDownloadCounts(versions); int thisVersion = versions.VersionDetails .Where(v => v.Version.Equals(version, StringComparison.OrdinalIgnoreCase)) .Select(v => v.Downloads) .FirstOrDefault(); return Tuple.Create(allVersions, thisVersion); }
public static int TotalDownloadCounts(VersionResult versions) { int allVersions = versions.VersionDetails.Select(v => v.Downloads).Sum(); return allVersions; }