public void AddToUrlTable(UrlEntity url) { urlTable.Execute(TableOperation.InsertOrReplace(url)); recentUrls.AddUrl(UrlEntity.DecodeFromTableKey(url.PartitionKey) + ": " + UrlEntity.DecodeFromTableKey(url.RowKey)); statsTable.Execute(TableOperation.InsertOrReplace(recentUrls)); IncrementUrlTableLength(); }
public DisplayUrl[] SearchForPhrase(string phrase) { if (phrase == null || phrase == string.Empty) { return(null); } // remove non-alphanumeric and split before using linq (get us a collection) string[] words = UrlEntity.CleanFullTitle(phrase).ToLower().Split(' '); if (words.Length <= 0) { return(null); } // query the db. This should be in multiple parts due to the maximum limit on filter params for azure tables // also since we're using different partition keys it doesn't really speed anything up List <UrlEntity> allEntites = new List <UrlEntity>(); foreach (string param in words) { var results = urlTable.ExecuteQuery <UrlEntity>(new TableQuery <UrlEntity>().Where( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, param) )); allEntites.AddRange(results); } // group by full title, then order by the number of matches for that title // ending with a date sort and making new display URLs for the items var res = allEntites .GroupBy(x => x.Title) .OrderByDescending(x => x.Count()) .ThenByDescending(x => x.First().Date) .Select(x => new DisplayUrl(x.First().URL, x.First().Title, x.First().Date)) .Take(20); ; return(res.ToArray()); }
public string GetPageTitle(string url) { TableQuery <UrlEntity> query = new TableQuery <UrlEntity>().Where( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, UrlEntity.EncodeToTableKey(url)) ); var result = urlTable.ExecuteQuery(query); if (result.Count() == 0) { return("No results found"); } else { return(result.First().Title); } }