public void Begin(IndexReader indexReader) { _rankingBySegmentReaderName = new RankingBySegment(); if (indexReader.GetSequentialSubReaders() != null) { foreach (SegmentReader segmentReader in indexReader.GetSequentialSubReaders()) { _rankingBySegmentReaderName[segmentReader.SegmentName] = new Ranking[segmentReader.MaxDoc]; } } else { _rankingBySegmentReaderName[string.Empty] = new Ranking[indexReader.MaxDoc]; } }
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()); } }