/// <summary> /// Queries CosmosDB for each of the token types /// sorts results based on location (if provided) and date /// </summary> public static IEnumerable <NoteModel> QueryNotes(string userId, string queryContents, string city, Point userLocation = null) { List <string> uniqueTokens = IndexerBase.GetDistinctTokens(queryContents).ToList(); if (uniqueTokens.Count == 0) { return(new List <NoteModel>()); } IQueryable <NoteModel> notes = CosmosDBClient.Query <NoteModel>().Where(n => n.UserId == userId); foreach (string token in uniqueTokens) { if (string.IsNullOrWhiteSpace(token)) { continue; } // Check each Indexer for membership if (new HashTagIndexer().IsMember(token)) { new HashTagIndexer().FilterNoteKeys(ref notes, token); TransactionModel.AddTransaction(userId, TransactionModel.TransactionType.Search, token, city, userLocation); continue; // index membership is disjoint } // Check each Indexer for membership if (new LocationIndexer().IsMember(token)) { new LocationIndexer().FilterNoteKeys(ref notes, token); continue; // index membership is disjoint } else if (new DateIndexer().IsMember(token)) { new DateIndexer().FilterNoteKeys(ref notes, token); continue; // index membership is disjoint } else if (new DateRangeIndexer().IsMember(token)) { // Date range is an exception where it's not stored as an actual index // but instead a range of indices new DateRangeIndexer().FilterNoteKeys(ref notes, token); continue; // index membership is disjoint } else { // Allow user to forget to add '#' when querying hashtags //new HashTagIndexer().FilterNoteKeys(ref notes, "#" + token); // Word is always the default token new WordIndexer().FilterNoteKeys(ref notes, token); } } return(notes); //// Build the query based on the tokens //if (userLocation != null) //{ // return notes.OrderByDescending(n => n.Location.Distance(userLocation)) // .ThenBy(n => n.LastUpdatedTime); //} //return notes.OrderByDescending(n => n.LastUpdatedTime); }
public void SetNoteContents(string content, out IEnumerable <string> removedTags, out IEnumerable <string> newTags) { EncodedNote = HttpUtility.UrlEncode(content); // keep track of which tags we've seen to remove the deleted ones from the Transactions HashSet <string> leftoverTags = new HashSet <string>(); if (this.Hashtags != null) { leftoverTags = new HashSet <string>(this.Hashtags); } // keep track of new tags to add to Transactions newTags = new List <string>(); this.Hashtags = new List <string>(); this.Words = new List <string>(); IEnumerable <string> uniqueTokens = IndexerBase.GetDistinctTokens(content); foreach (string token in uniqueTokens) { if (string.IsNullOrWhiteSpace(token)) { continue; } if (new HashTagIndexer().IsMember(token)) { this.Hashtags.Add(token); if (!leftoverTags.Contains(token)) { ((List <string>)newTags).Add(token); } else { leftoverTags.Remove(token); } } else // default is a word { this.Words.Add(token); } } removedTags = leftoverTags.AsEnumerable(); }
public virtual void InitializeIndexers(IList <IndexerBase> indexers) { Logger.Debug("Initializing indexers. Count {0}", indexers.Count); _indexers = indexers; var currentIndexers = All(); foreach (var feedProvider in indexers) { IndexerBase indexerLocal = feedProvider; if (!currentIndexers.Exists(c => c.IndexProviderType == indexerLocal.GetType().ToString())) { var settings = new IndexerDefinition { Enable = indexerLocal.EnabledByDefault, IndexProviderType = indexerLocal.GetType().ToString(), Name = indexerLocal.Name }; SaveSettings(settings); } } }