/// <summary> /// Return a virtual album containing gallery objects that match the specified search strings and /// for which the current user has authorization to view. Guaranteed to not return null. A gallery /// object is considered a match when all search terms are found in the relevant fields. /// </summary> /// <param name="searchStrings">The strings to search for.</param> /// <param name="galleryId">The ID for the gallery containing the objects to search.</param> /// <returns> /// Returns an <see cref="IAlbum" /> containing the matching items. This may include albums and media /// objects from different albums. /// </returns> public static IAlbum GetGalleryObjectsHavingSearchString(string[] searchStrings, int galleryId) { if (searchStrings == null) { throw new ArgumentNullException(); } var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId); tmpAlbum.IsVirtualAlbum = true; tmpAlbum.VirtualAlbumType = VirtualAlbumType.Search; tmpAlbum.Title = String.Concat("Search results for ", String.Join(" AND ", searchStrings)); tmpAlbum.Caption = String.Empty; var searchOptions = new GalleryObjectSearchOptions { GalleryId = galleryId, SearchType = GalleryObjectSearchType.SearchByKeyword, SearchTerms = searchStrings, IsUserAuthenticated = Utils.IsAuthenticated, Roles = RoleController.GetGalleryServerRolesForUser() }; var searcher = new GalleryObjectSearcher(searchOptions); foreach (var galleryObject in searcher.Find()) { tmpAlbum.AddGalleryObject(galleryObject); } return(tmpAlbum); }
/// <summary> /// Gets a virtual album containing gallery objects that match the specified <paramref name="tags" /> or <paramref name="people" /> /// belonging to the specifed <paramref name="galleryId" />. Guaranteed to not return null. The returned album /// is a virtual one (<see cref="IAlbum.IsVirtualAlbum" />=<c>true</c>) containing the collection of matching /// items the current user has permission to view. Returns an empty album when no matches are found or the /// query string does not contain the search terms. /// </summary> /// <param name="tags">The tags to search for. If specified, the <paramref name="people" /> parameter must be null.</param> /// <param name="people">The people to search for. If specified, the <paramref name="tags" /> parameter must be null.</param> /// <param name="galleryId">The ID of the gallery. Only objects in this gallery are returned.</param> /// <returns>An instance of <see cref="IAlbum" />.</returns> /// <exception cref="System.ArgumentException">Throw when the tags and people parameters are both null or empty, or both /// have values.</exception> public static IAlbum GetGalleryObjectsHavingTags(string[] tags, string[] people, int galleryId) { if (((tags == null) || (tags.Length == 0)) && ((people == null) || (people.Length == 0))) { throw new ArgumentException("GalleryObjectController.GetGalleryObjectsHavingTags() requires the tags or people parameters to be specified, but they were both null or empty."); } if ((tags != null) && (tags.Length > 0) && (people != null) && (people.Length > 0)) { throw new ArgumentException("GalleryObjectController.GetGalleryObjectsHavingTags() requires EITHER the tags or people parameters to be specified, but not both. Instead, they were both populated."); } //var tags = Utils.GetQueryStringParameterStrings("tag") ?? Utils.GetQueryStringParameterStrings("people"); var searchType = (tags != null && tags.Length > 0 ? GalleryObjectSearchType.SearchByTag : GalleryObjectSearchType.SearchByPeople); var searchTags = (searchType == GalleryObjectSearchType.SearchByTag ? tags : people); var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId); tmpAlbum.IsVirtualAlbum = true; tmpAlbum.VirtualAlbumType = (searchType == GalleryObjectSearchType.SearchByTag ? VirtualAlbumType.Tag : VirtualAlbumType.People); tmpAlbum.Title = String.Concat("Items tagged with ", String.Join(" AND ", searchTags)); tmpAlbum.Caption = String.Empty; var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions { SearchType = searchType, Tags = searchTags, GalleryId = galleryId, Roles = RoleController.GetGalleryServerRolesForUser(), IsUserAuthenticated = Utils.IsAuthenticated }); foreach (var galleryObject in searcher.Find()) { tmpAlbum.AddGalleryObject(galleryObject); } return(tmpAlbum); }