protected override void Warm(NuGetIndexSearcher searcher) { _logger.LogInformation("NuGetSearcherManager.Warm"); var stopwatch = Stopwatch.StartNew(); // Warmup search (query all documents) searcher.Search(new MatchAllDocsQuery(), 1); // Warmup search (query for a specific term with rankings) var query = NuGetQuery.MakeQuery("newtonsoft.json", searcher.Owners); var boostedQuery = new DownloadsBoostedQuery(query, searcher.DocIdMapping, searcher.Downloads, searcher.Rankings, QueryBoostingContext.Default); searcher.Search(boostedQuery, 5); // Warmup search (with a sort so Lucene field caches are populated) var sort1 = new Sort(new SortField("LastEditedDate", SortField.INT, reverse: true)); var sort2 = new Sort(new SortField("PublishedDate", SortField.INT, reverse: true)); var sort3 = new Sort(new SortField("SortableTitle", SortField.STRING, reverse: false)); var sort4 = new Sort(new SortField("SortableTitle", SortField.STRING, reverse: true)); var topDocs1 = searcher.Search(boostedQuery, null, 250, sort1); var topDocs2 = searcher.Search(boostedQuery, null, 250, sort2); var topDocs3 = searcher.Search(boostedQuery, null, 250, sort3); var topDocs4 = searcher.Search(boostedQuery, null, 250, sort4); // Warmup field caches by fetching data from them using (var writer = new JsonTextWriter(new StreamWriter(new MemoryStream()))) { ResponseFormatter.WriteV2Result(writer, searcher, topDocs1, 0, 250, SemVerHelpers.SemVer2Level); ResponseFormatter.WriteSearchResult(writer, searcher, "http", topDocs1, 0, 250, false, false, SemVerHelpers.SemVer2Level, boostedQuery); ResponseFormatter.WriteV2Result(writer, searcher, topDocs2, 0, 250, SemVerHelpers.SemVer2Level); ResponseFormatter.WriteSearchResult(writer, searcher, "http", topDocs2, 0, 250, false, false, SemVerHelpers.SemVer2Level, boostedQuery); ResponseFormatter.WriteV2Result(writer, searcher, topDocs3, 0, 250, SemVerHelpers.SemVer2Level); ResponseFormatter.WriteSearchResult(writer, searcher, "http", topDocs3, 0, 250, false, false, SemVerHelpers.SemVer2Level, boostedQuery); ResponseFormatter.WriteV2Result(writer, searcher, topDocs4, 0, 250, SemVerHelpers.SemVer2Level); ResponseFormatter.WriteSearchResult(writer, searcher, "http", topDocs4, 0, 250, false, false, SemVerHelpers.SemVer2Level, boostedQuery); } // Done, we're warm. stopwatch.Stop(); _logger.LogInformation("NuGetSearcherManager.Warm: completed in {IndexSearcherWarmDuration} seconds.", stopwatch.Elapsed.TotalSeconds); }
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); }
private static Query MakeSearchQuery(string q, NuGetIndexSearcher searcher) { try { Query query = NuGetQuery.MakeQuery(q, searcher.Owners); Query boostedQuery = new DownloadsBoostedQuery(query, searcher.DocIdMapping, searcher.Downloads, searcher.Rankings, searcher.QueryBoostingContext); return(boostedQuery); } catch (ParseException) { throw new ClientException(HttpStatusCode.BadRequest, "Invalid query format"); } }
private static void ListDocumentsImpl(JsonWriter jsonWriter, NuGetIndexSearcher searcher, Query query, string sortBy, int skip, int take) { Query boostedQuery = new DownloadsBoostedQuery(query, searcher.DocIdMapping, searcher.Downloads, searcher.Rankings, searcher.QueryBoostingContext); int nDocs = skip + take; Sort sort = GetSort(sortBy); TopDocs topDocs = (sort == null) ? searcher.Search(boostedQuery, nDocs) : searcher.Search(boostedQuery, null, nDocs, sort); ResponseFormatter.WriteV2Result(jsonWriter, searcher, topDocs, skip, take); }
private static void ListDocumentsImpl(JsonWriter jsonWriter, NuGetIndexSearcher searcher, Query query, string sortBy, int skip, int take, NuGetVersion semVerLevel) { Query boostedQuery = new DownloadsBoostedQuery(query, searcher.DocIdMapping, searcher.Downloads, searcher.Rankings, searcher.QueryBoostingContext); int nDocs = skip + take; Sort sort = GetSort(sortBy); TopDocs topDocs = (sort == null) ? searcher.Search(boostedQuery, nDocs) : searcher.Search(boostedQuery, null, nDocs, sort); ResponseFormatter.WriteV2Result(jsonWriter, searcher, topDocs, skip, take, semVerLevel); }
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; }
private static Query MakeSearchQuery(string q, NuGetIndexSearcher searcher) { try { Query query = NuGetQuery.MakeQuery(q, searcher.Owners); Query boostedQuery = new DownloadsBoostedQuery(query, searcher.DocIdMapping, searcher.Downloads, searcher.Rankings, searcher.QueryBoostingContext); return boostedQuery; } catch (ParseException) { throw new ClientException(HttpStatusCode.BadRequest, "Invalid query format"); } }