public DownloadsScoreProvider(IndexReader reader, IReadOnlyDictionary<string, int[]> idMapping, Downloads downloads, RankingResult ranking, QueryBoostingContext context, double baseBoost) : base(reader) { _idMapping = idMapping; _downloads = downloads; _baseBoost = baseBoost; _ranking = ranking; _context = context; // We need the reader name: Lucene *may* have multiple segments (which are smaller indices) // and RankingsHandler provides us with the per-segment document numbers. // // If no segments are present (small index) we use an empty string, which is what // Lucene also uses internally. var segmentReader = reader as SegmentReader; _readerName = segmentReader != null ? segmentReader.SegmentName : string.Empty; }
public DownloadsScoreProvider(IndexReader reader, IReadOnlyDictionary <string, int[]> idMapping, Downloads downloads, RankingResult ranking, QueryBoostingContext context, double baseBoost) : base(reader) { _idMapping = idMapping; _downloads = downloads; _baseBoost = baseBoost; _ranking = ranking; _context = context; // We need the reader name: Lucene *may* have multiple segments (which are smaller indices) // and RankingsHandler provides us with the per-segment document numbers. // // If no segments are present (small index) we use an empty string, which is what // Lucene also uses internally. var segmentReader = reader as SegmentReader; _readerName = segmentReader != null ? segmentReader.SegmentName : string.Empty; }
public DownloadsBoostedQuery(Query query, IReadOnlyDictionary <string, int[]> docIdMapping, Downloads downloads, RankingResult ranking, QueryBoostingContext context, double baseBoost = BaseBoostConstant) : base(query) { _docIdMapping = docIdMapping; _downloads = downloads; _baseBoost = baseBoost; _ranking = ranking; _context = context; Query = query; }
public DownloadsBoostedQuery(Query query, IReadOnlyDictionary<string, int[]> docIdMapping, Downloads downloads, RankingResult ranking, QueryBoostingContext context, double baseBoost = BaseBoostConstant) : base(query) { _docIdMapping = docIdMapping; _downloads = downloads; _baseBoost = baseBoost; _ranking = ranking; _context = context; Query = query; }
private static Query MakeAutoCompleteQuery(string q, IReadOnlyDictionary <string, int[]> docIdMapping, Downloads downloads, RankingResult rankings, QueryBoostingContext context) { var query = NuGetQuery.MakeAutoCompleteQuery(q); var boostedQuery = new DownloadsBoostedQuery(query, docIdMapping, downloads, rankings, context, 2.0); return(boostedQuery); }
public NuGetIndexSearcher( NuGetSearcherManager manager, IndexReader reader, IDictionary <string, string> commitUserData, IDictionary <string, Filter> curatedFeeds, Dictionary <LatestListedMask, Filter> latest, IReadOnlyDictionary <string, int[]> docIdMapping, Downloads downloads, VersionResult[] versions, RankingResult rankings, QueryBoostingContext context, OpenBitSet latestBitSet, OpenBitSet latestStableBitSet, OpenBitSet latestSemVer2BitSet, OpenBitSet latestStableSemVer2BitSet, OwnersResult owners, HashSet <string> verifiedPackages) : 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; LatestSemVer2BitSet = latestSemVer2BitSet; LatestStableSemVer2BitSet = latestStableSemVer2BitSet; Owners = owners; VerifiedPackages = verifiedPackages; QueryBoostingContext = context; LastReopen = DateTime.UtcNow; }
private static float RankingScore(string readerName, RankingResult rankings, int doc, double baseBoost) { // Override is based on the rankings JSON we generate, containing the top downloaded packages. // RankingsHandler has created a mapping for us which has [documentId] = rank, // so that we can do a quick lookup based on the document number in the current segment. if (rankings.DocumentRankings[readerName].Length < doc) { return(1.0f); } var ranking = rankings.DocumentRankings[readerName][doc]; if (ranking == null) { return(1.0f); } var scoreAdjuser = Math.Pow(baseBoost, (1.2 - ((double)ranking.Rank / ((double)rankings.Count + 1.0)))) * 10; return((float)scoreAdjuser); }
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 static float RankingScore(string readerName, RankingResult rankings, int doc, double baseBoost) { // Override is based on the rankings JSON we generate, containing the top downloaded packages. // RankingsHandler has created a mapping for us which has [documentId] = rank, // so that we can do a quick lookup based on the document number in the current segment. if (rankings.DocumentRankings[readerName].Length < doc) { return 1.0f; } var ranking = rankings.DocumentRankings[readerName][doc]; if (ranking == null) { return 1.0f; } var scoreAdjuser = Math.Pow(baseBoost, (1.2 - ((double)ranking.Rank / ((double)rankings.Count + 1.0)))) * 10; return (float)scoreAdjuser; }
private static Query MakeAutoCompleteQuery(string q, IReadOnlyDictionary<string, int[]> docIdMapping, Downloads downloads, RankingResult rankings, QueryBoostingContext context) { var query = NuGetQuery.MakeAutoCompleteQuery(q); var boostedQuery = new DownloadsBoostedQuery(query, docIdMapping, downloads, rankings, context, 2.0); return boostedQuery; }
public void WriteRankingsResultNoRankingsTest() { var emptyRankings = new RankingBySegment(); var rankingResult = new RankingResult(3, emptyRankings); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteRankingsResult(writer, rankingResult); Assert.Equal("{\"rankings\":[]}", sb.ToString()); } }
public void WriteRankingsResultTest() { var rankingsSegment = new RankingBySegment(); rankingsSegment[Constants.RankingsSegmentName] = GenerateRankings(numRankings: 5, idPrefix: Constants.RankingsIdPrefix); var rankingResult = new RankingResult(3, rankingsSegment); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteRankingsResult(writer, rankingResult); Assert.Equal(string.Format("{{\"rankings\":[{{\"id\":\"{0}0\",\"Rank\":0}},{{\"id\":\"{0}1\",\"Rank\":1}},{{\"id\":\"{0}2\",\"Rank\":2}},{{\"id\":\"{0}3\",\"Rank\":3}},{{\"id\":\"{0}4\",\"Rank\":4}}]}}", Constants.RankingsIdPrefix), sb.ToString()); } }
public void End(IndexReader indexReader) { Result = new RankingResult(_rankings.Count, _rankingBySegmentReaderName); }