/// <summary> /// Initializes a new instance of the <see cref="TagSearcher" /> class. /// </summary> /// <param name="searchOptions">The search options.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="searchOptions" /> is null.</exception> /// <exception cref="System.ArgumentException">Thrown when one or more properties of the <paramref name="searchOptions" /> parameter is invalid.</exception> public TagSearcher(TagSearchOptions searchOptions) { Validate(searchOptions); SearchOptions = searchOptions; if (SearchOptions.Roles == null) { SearchOptions.Roles = new GalleryServerRoleCollection(); } }
/// <summary> /// Validates the specified search options. Throws an exception if not valid. /// </summary> /// <param name="searchOptions">The search options.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="searchOptions" /> is null.</exception> /// <exception cref="System.ArgumentException">Thrown when one or more properties of the <paramref name="searchOptions" /> parameter is invalid.</exception> private static void Validate(TagSearchOptions searchOptions) { if (searchOptions == null) { throw new ArgumentNullException("searchOptions"); } if (searchOptions.SearchType == TagSearchType.NotSpecified) { throw new ArgumentException("The SearchType property of the searchOptions parameter must be set to a valid search type."); } if (searchOptions.IsUserAuthenticated && searchOptions.Roles == null) { throw new ArgumentException("The Roles property of the searchOptions parameter must be specified when IsUserAuthenticated is true."); } if (searchOptions.GalleryId < 0) // v3+ galleries start at 1, but galleries from earlier versions begin at 0 { throw new ArgumentException("Invalid gallery ID. The GalleryId property of the searchOptions parameter must refer to a valid gallery."); } }
/// <summary> /// Gets a tree representing the tags used in a gallery. The tree has a root node that serves as the tag container. /// It contains a flat list of child nodes for the tags. /// </summary> /// <param name="tagSearchOptions">The options that specify what kind of tags to return and how they should be /// calculated and displayed.</param> /// <returns>Returns an instance of <see cref="Entity.TreeView" />. Guaranteed to not return null.</returns> private static Entity.TreeView GetTagTree(TagSearchOptions tagSearchOptions) { var tags = GetTags(tagSearchOptions); var id = 0; var tv = new Entity.TreeView(); var baseUrl = Utils.GetCurrentPageUrl(); var qsParm = GetTagTreeNavUrlQsParm(tagSearchOptions.SearchType); var rootNode = new Entity.TreeNode { Text = GetTagTreeRootNodeText(tagSearchOptions.SearchType), //ToolTip = "Tags in gallery", Id = String.Concat("tv_tags_", id++), DataId = "root", Expanded = tagSearchOptions.TagTreeIsExpanded, }; rootNode.AddCssClass("jstree-root-node"); tv.Nodes.Add(rootNode); foreach (var tag in tags) { rootNode.Nodes.Add(new Entity.TreeNode { Text = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", tag.Value, tag.Count), ToolTip = String.Format(CultureInfo.InvariantCulture, Resources.GalleryServerPro.Site_Tag_Tree_Node_Tt, tag.Value), Id = String.Concat("tv_tags_", id++), DataId = tag.Value, NavigateUrl = Utils.AddQueryStringParameter(baseUrl, String.Concat(qsParm, "=", Utils.UrlEncode(tag.Value))) }); } return tv; }
private static TagSearchOptions GetTagSearchOptions(TagSearchType searchType, string searchTerm, int galleryId, int numTagsToRetrieve = int.MaxValue, TagSearchOptions.TagProperty sortProperty = TagSearchOptions.TagProperty.NotSpecified, bool sortAscending = true, bool expanded = false) { return new TagSearchOptions { GalleryId = galleryId, SearchType = searchType, SearchTerm = searchTerm, IsUserAuthenticated = Utils.IsAuthenticated, Roles = RoleController.GetGalleryServerRolesForUser(), NumTagsToRetrieve = numTagsToRetrieve, SortProperty = sortProperty, SortAscending = sortAscending, TagTreeIsExpanded = expanded }; }
/// <summary> /// Gets a list of tags or people corresponding to the specified <paramref name="searchOptions" />. /// Guaranteed to not return null. /// </summary> /// <param name="searchOptions">The search options.</param> /// <returns>IEnumerable{Tag}.</returns> private static IEnumerable<Business.Entity.Tag> GetTags(TagSearchOptions searchOptions) { var searcher = new TagSearcher(searchOptions); return searcher.Find(); }
/// <summary> /// Gets a JSON string representing the tags used in the specified gallery. The JSON can be used as the /// data source for the jsTree jQuery widget. Only tags the current user has permission to view are /// included. The tag tree has a root node containing a single level of tags. /// </summary> /// <param name="tagSearchType">Type of search.</param> /// <param name="galleryId">The gallery ID.</param> /// <param name="top">The number of tags to return. Values less than zero are treated the same as zero, /// meaning no tags will be returned. Specify <see cref="int.MaxValue" /> to return all tags.</param> /// <param name="sortBy">The property to sort the tags by. Specify <see cref="TagSearchOptions.TagProperty.Count" /> /// to sort by tag frequency or <see cref="TagSearchOptions.TagProperty.Value" /> to sort by tag name. /// When not specified, defaults to <see cref="TagSearchOptions.TagProperty.Count" />.</param> /// <param name="sortAscending">Specifies whether to sort the tags in ascending order. Specify <c>true</c> /// for ascending order or <c>false</c> for descending order. When not specified, defaults to <c>false</c>.</param> /// <param name="expanded">if set to <c>true</c> the tree is configured to display in an expanded form.</param> /// <returns>System.String.</returns> public static string GetTagTreeAsJson(TagSearchType tagSearchType, int galleryId, int top = int.MaxValue, TagSearchOptions.TagProperty sortBy = TagSearchOptions.TagProperty.Count, bool sortAscending = false, bool expanded = false) { var tagSearchOptions = GetTagSearchOptions(tagSearchType, null, galleryId, top, sortBy, sortAscending, expanded); return GetTagTree(tagSearchOptions).ToJson(); }
/// <summary> /// Gets a list of tags or people corresponding to the specified parameters. /// Guaranteed to not return null. /// </summary> /// <param name="tagSearchType">Type of the search.</param> /// <param name="searchTerm">The search term. Only tags that begin with this string are returned. /// Specify null or an empty string to return all tags.</param> /// <param name="galleryId">The gallery ID.</param> /// <param name="top">The number of tags to return. Values less than zero are treated the same as zero, /// meaning no tags will be returned. Specify <see cref="int.MaxValue" /> to return all tags.</param> /// <param name="sortBy">The property to sort the tags by. Specify <see cref="TagSearchOptions.TagProperty.Count" /> /// to sort by tag frequency or <see cref="TagSearchOptions.TagProperty.Value" /> to sort by tag name. /// When not specified, defaults to <see cref="TagSearchOptions.TagProperty.NotSpecified" />.</param> /// <param name="sortAscending">Specifies whether to sort the tags in ascending order. Specify <c>true</c> /// for ascending order or <c>false</c> for descending order. When not specified, defaults to <c>false</c>.</param> /// <returns>IEnumerable{Business.Entity.Tag}.</returns> public static IEnumerable<Business.Entity.Tag> GetTags(TagSearchType tagSearchType, string searchTerm, int galleryId, int top = int.MaxValue, TagSearchOptions.TagProperty sortBy = TagSearchOptions.TagProperty.NotSpecified, bool sortAscending = false) { return GetTags(GetTagSearchOptions(tagSearchType, searchTerm, galleryId, top, sortBy, sortAscending)); }
/// <summary> /// Validates the specified search options. Throws an exception if not valid. /// </summary> /// <param name="searchOptions">The search options.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="searchOptions" /> is null.</exception> /// <exception cref="System.ArgumentException">Thrown when one or more properties of the <paramref name="searchOptions" /> parameter is invalid.</exception> private static void Validate(TagSearchOptions searchOptions) { if (searchOptions == null) throw new ArgumentNullException("searchOptions"); if (searchOptions.SearchType == TagSearchType.NotSpecified) throw new ArgumentException("The SearchType property of the searchOptions parameter must be set to a valid search type."); if (searchOptions.IsUserAuthenticated && searchOptions.Roles == null) throw new ArgumentException("The Roles property of the searchOptions parameter must be specified when IsUserAuthenticated is true."); if (searchOptions.GalleryId < 0) // v3+ galleries start at 1, but galleries from earlier versions begin at 0 throw new ArgumentException("Invalid gallery ID. The GalleryId property of the searchOptions parameter must refer to a valid gallery."); }