public IEnumerable <Bookmarks.Common.TagCount> GetAssociatedTerms
            (Bookmarks.Common.TagBundle tagBundle, int bufferSize)
        {
            var bookmarks = _database.GetCollection <BsonDocument>(BookmarksCollection);

            var filteredBookmarks = GetBookmarksByTagBundle(tagBundle, (int?)0, (int?)bufferSize);

            IEnumerable <string> excludedTags = CompileExcludeTags(tagBundle.ExcludeTagBundles);

            var tagCounts = filteredBookmarks.SelectMany(b => b.Tags)
                            .Where(t => !tagBundle.Tags.Contains(t) &&
                                   !tagBundle.ExcludeTags.Contains(t) &&
                                   !excludedTags.Contains(t))
                            .Select(t => new Bookmarks.Common.TagCount {
                Tag = t, Count = 1
            });

            return(tagCounts.GroupBy(tc => tc.Tag)
                   .Select(tagGrp
                           => new Bookmarks.Common.TagCount
            {
                Tag = tagGrp.Key, Count = tagGrp.Count()
            })
                   .OrderByDescending(tc => tc.Count));
        }
예제 #2
0
        public static TagBundle Create(string name, string[] bookmarkCollectionIds)
        {
            var bundle = new TagBundle {
                Name = name, BookmarksCollections = bookmarkCollectionIds
            };

            bundle.Id = Utils.ComputeHash(name + bookmarkCollectionIds, MD5.Create());
            return(bundle);
        }
예제 #3
0
        public IEnumerable <string> ExtractExcludeTags(string[] excludeTagBundles, Bookmarks.Common.TagBundle tagBundle)
        {
            var exclTags = excludeTagBundles.SelectMany(ext => GetTagBundles(ext))
                           .SelectMany(b => b.Tags).ToArray();

            string[] excludeTags = tagBundle == null ? new string[0] : tagBundle.ExcludeTags;
            string[] tags        = tagBundle == null ? new string[0] : tagBundle.Tags;

            return(exclTags.Union(excludeTags)
                   .Union(tags));
        }
        public void UpdateTagBundle(Bookmarks.Common.TagBundle tagBundle)
        {
            var tagBundles = _database.GetCollection <Bookmarks.Mongo.Data.TagBundle>(TAG_BUNDLES_COLLECTION);
            var builder    = Builders <Bookmarks.Mongo.Data.TagBundle> .Filter;
            var filter     = builder.Eq(t => t.Name, tagBundle.Name);
            var update     = Builders <Bookmarks.Mongo.Data.TagBundle> .Update
                             .Set(t => t.Tags, tagBundle.Tags)
                             .Set(t => t.ExcludeTags, tagBundle.ExcludeTags)
                             .CurrentDate("lastModified");

            tagBundles.UpdateOne(filter, update);
        }
        public IEnumerable <Bookmarks.Common.Bookmark> GetBookmarksByTagBundle
            (Bookmarks.Common.TagBundle tagBundle, int?skip, int?take)
        {
            if (tagBundle == null)
            {
                throw new ApplicationException("tagBundle not found");
            }
            //should be in tagBundle.Tags
            //HACK!
            var filterDef = string.Format("{{ 'Tags': {{$elemMatch: {{$in: ['{0}'] }} }} }}"
                                          , string.Join("','", tagBundle.Tags));

            return(FilterBookmarks(filterDef, skip, take).ToList()
                   .Select(bm => MapperObj.Map <Bookmarks.Common.Bookmark>(bm)));
        }
        public void CreateTagBundle(Bookmarks.Common.TagBundle tagBundle)
        {
            if (tagBundle == null)
            {
                throw new ArgumentNullException("tagBundle");
            }

            var tagBundles = _database.GetCollection
                             <Bookmarks.Mongo.Data.TagBundle>(TAG_BUNDLES_COLLECTION);

            if (tagBundles == null)
            {
                throw new ArgumentNullException("tagBundleS collection");
            }

            tagBundles.InsertOne(MapperObj.Map <Bookmarks.Mongo.Data.TagBundle>(tagBundle));
        }