public IList<ResultItem> Search(Query query) { var results = new List<ResultItem>(); SearchResult searchResult; do { try { string url = this.urlBuilder.WithQuery(query); string content = this.spider.DownloadContent(url); searchResult = this.parser.Parse(content); results.AddRange(searchResult.Items); if (searchResult.HasParameters) { query.Parameters = searchResult.Parameters; } } catch { break; } finally { query.Page++; } } while (searchResult.HasNextPage && results.Count < query.MaxResults); return results.Take(query.MaxResults).ToList(); }
public void Search_InvokeParserInNextPage() { // Arrange: var query = new Query { Term = "cultura", MaxResults = 20 }; this.urlBuilder.Setup(u => u.WithQuery(It.IsAny<Query>())).Returns(string.Empty); this.spider.Setup(s => s.DownloadContent(It.IsAny<string>())).Returns(string.Empty); this.parser.Setup(p => p.Parse(It.IsAny<string>())).Returns(new SearchResult { HasNextPage = true, Items = new List<ResultItem> { new ResultItem(), new ResultItem(), new ResultItem(), new ResultItem(), new ResultItem() } }); // Act: this.engine.Search(query); // Assert: this.parser.Verify(u => u.Parse(It.IsAny<string>()), Times.Exactly(4)); }
public void Search_GetUrlFromUrlBuilder() { // Arrange: var query = new Query { Term = "cultura", MaxResults = 10 }; // Act: this.engine.Search(query); // Assert: this.urlBuilder.Verify(u => u.WithQuery(It.IsAny<Query>()), Times.Once()); }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var url = this.builder.WithQuery(query); // Assert: }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var url = this.builder.WithQuery(query); // Assert: url.Should().Be.EqualTo("http://news.search.yahoo.com/search?ei=UTF-8&n=100&p=cultura&vc=&btf=d&b=1"); }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var url = this.builder.WithQuery(query); // Assert: url.Should().Be.EqualTo(string.Format("http://www.google.com/search?&safe=images&tbm=nws&num=100&q=cultura&tbs=cdr:1,cd_min:{0},cd_max:{1}&start=0", period.Begin.ToString("yyyy-MM-dd"), period.End.ToString("yyyy-MM-dd"))); }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var url = this.builder.WithQuery(query); // Assert: url.Should().Be.EqualTo(string.Format("https://graph.facebook.com/search?type=post&metadata=1&callback=display&limit=50&q=cultura&since={0}&offset=0", period.Begin.ToString("yyyyMMdd"))); }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var url = this.builder.WithQuery(query); // Assert: url.Should().Be.EqualTo(string.Format("http://search.twitter.com/search.json?rpp=100&result_type=recent&q=cultura&since={0}&page=1", period.Begin.ToString("yyyy-MM-dd"))); }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var url = this.builder.WithQuery(query); // Assert: url.Should().Be.EqualTo("http://www.bing.com/search?q=cultura"); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("https://www.googleapis.com/plus/v1/activities?fields=items(actor%2FdisplayName%2Cobject(attachments(content%2CobjectType)%2Ccontent%2CobjectType)%2Cpublished)%2CnextLink%2Ctitle%2Cupdated&pp=1"); this.builder.AppendFormat("&orderBy=recent&maxResults=20&key={0}&query={1}", this.apiKey, query.Term); this.AppendLanguage(query.Language); this.AppendPage(query.Parameters); return this.builder.ToString(); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("http://services.digg.com/2.0/search.search?count=100&media=news"); this.builder.AppendFormat("&query={0}", query.Term); this.AppendPeriod(query.Period); this.AppendPage(query.Page); return this.builder.ToString(); }
public void WithQuery_IncludePeriodInQuery() { // Arrange: var period = Period.Today; var query = new Query { Term = "cultura", Period = period }; // Act: var resultUrl = this.builder.WithQuery(query); // Assert: var beginUnixTime = DateParser.ToUnixTimestamp(period.Begin); var endUnixTime = DateParser.ToUnixTimestamp(period.End); var comparableUrl = string.Format("http://services.digg.com/2.0/search.search?count=100&media=news&query=cultura&min_date={0}&max_date={1}&offset=1", beginUnixTime, endUnixTime); resultUrl.Should().Be.EqualTo(comparableUrl); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("http://www.bing.com/search?"); this.builder.AppendFormat("q={0}", query.Term); this.AppendLanguage(query.Language); this.AppendCountry(query.Country); this.AppendPage(query.Page); return this.builder.ToString(); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("https://graph.facebook.com/search?type=post&metadata=1&callback=display&limit=50"); this.builder.AppendFormat("&q={0}", query.Term); this.AppendRegion(query.Language, query.Country); this.AppendPeriod(query.Period); this.AppendPage(query.Page); return this.builder.ToString(); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("https://www.googleapis.com/customsearch/v1?"); this.builder.AppendFormat("key={0}&q={1}", this.apiKey, query.Term); this.AppendLanguage(query.Language); this.AppendCountry(query.Country); this.AppendPeriod(query.Period); this.AppendPage(query.Page); return this.builder.ToString(); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("http://news.search.yahoo.com/search?ei=UTF-8&n=100"); this.builder.AppendFormat("&p={0}", query.Term); this.AppendCountry(query.Country); this.AppendLanguage(query.Language); this.AppendPeriod(query.Period); this.AppendPage(query.Page); return this.builder.ToString(); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("http://www.google.com/search?&safe=images"); this.builder.AppendFormat("{0}&num=100&q={1}", this.TabSource, query.Term); this.AppendLanguage(query.Language); this.AppendCountry(query.Country); this.AppendPeriod(query.Period); this.AppendPage(query.Page); return this.builder.ToString(); }
public string WithQuery(Query query) { if (string.IsNullOrEmpty(query.Term)) { throw new ArgumentException("term not be null -or- term not be empty"); } this.builder = new StringBuilder("https://api.twitter.com/1.1/search/tweets.json?rpp=100&result_type=recent"); this.builder.AppendFormat("&q={0}", HttpUtility.UrlEncode(query.Term)); this.AppendLanguage(query.Language); this.AppendCountry(query.Country); this.AppendPeriod(query.Period); this.AppendPage(query.Page); return this.builder.ToString(); }
public void Search_ReturnCorrectNumberOfResults() { // Arrange: var query = new Query { Term = "cultura", MaxResults = 7 }; this.urlBuilder.Setup(u => u.WithQuery(It.IsAny<Query>())).Returns(string.Empty); this.spider.Setup(s => s.DownloadContent(It.IsAny<string>())).Returns(string.Empty); this.parser.Setup(p => p.Parse(It.IsAny<string>())).Returns(new SearchResult { HasNextPage = true, Items = new List<ResultItem> { new ResultItem(), new ResultItem(), new ResultItem(), new ResultItem(), new ResultItem() } }); // Act: var results = this.engine.Search(query); // Assert: results.Count.Should().Be.EqualTo(7); }