Sorry I am a bit of a newbie. I have been going over the source code a little and I could not find an easy way for me to do this.
I am trying to list the tags for a given group, that I can do. But then I am trying to load all documents associated with a tag, potentially remove a tag not in use.
Being able to rename a tag would also be nice. Basically funcitonality from TagManager but a little more specific to our configuration and some of it I would want to show in the UI as well.
Now I looked for an API where I could get documents/nodes for a given tag or delete a tag. There does not seem to be anything quite like that. I could follow the road taken by TagManager and directly access the tables but before I went there I wanted to make sure there is not anything else available for me to use.
ok I have given up and using the DatabaseContext to get some information about the tags.
Here is what I am using for now in case someone comes up with a better way
public static IList<Tags> GetTags(DatabaseContext databaseContext, string[] group = null) { var sql = new StringBuilder("Select id, tag as name, [group], count(cmsTagRelationship.nodeid) as documentcount From cmsTags, cmsTagRelationship where cmsTags.id = cmsTagRelationship.tagId"); sql.Append(" group by id, tag, [group]"); sql.Append(" order by [group], tag"); var db = databaseContext.Database; var tagList = db.Fetch<Tag>(sql.ToString());
I had to come up with something, so I am using database and Petapoco.
This way I can create the equivalent of a tag cloud and getting number of documents per tag. Also created a related documents using tags, the more tgas they have in common the more related they are. Not that great but good enough.
Thanks for the help, I will see if I can use it to improve what I have already implemented.
TagQuery is the recommended way afaiu, i.e Umbraco.TagQuery.GetContentByTagGroup("default"); <- returns all IPublishedContent with tags in that group. However it does also return some with empty tags it seems. So Umbraco.TagQuery.GetContentByTagGroup("default").Where(d=>d.HasValue("myTagProperty")) is better.
Umbraco 7 Managing Tags
Hi all,
Sorry I am a bit of a newbie. I have been going over the source code a little and I could not find an easy way for me to do this.
I am trying to list the tags for a given group, that I can do. But then I am trying to load all documents associated with a tag, potentially remove a tag not in use.
Being able to rename a tag would also be nice. Basically funcitonality from TagManager but a little more specific to our configuration and some of it I would want to show in the UI as well.
Now I looked for an API where I could get documents/nodes for a given tag or delete a tag. There does not seem to be anything quite like that. I could follow the road taken by TagManager and directly access the tables but before I went there I wanted to make sure there is not anything else available for me to use.
Any help would be appreciated, thanks
ok I have given up and using the DatabaseContext to get some information about the tags.
Here is what I am using for now in case someone comes up with a better way
public static IList<Tags> GetTags(DatabaseContext databaseContext, string[] group = null)
{
var sql = new StringBuilder("Select id, tag as name, [group], count(cmsTagRelationship.nodeid) as documentcount From cmsTags, cmsTagRelationship where cmsTags.id = cmsTagRelationship.tagId");
sql.Append(" group by id, tag, [group]");
sql.Append(" order by [group], tag");
var db = databaseContext.Database;
var tagList = db.Fetch<Tag>(sql.ToString());
Thanks
Take a look at the new TagService:
https://github.com/umbraco/Umbraco-CMS/blob/7.1.5/src/Umbraco.Core/Services/TagService.cs
Maybe it can help you?
I had to come up with something, so I am using database and Petapoco.
This way I can create the equivalent of a tag cloud and getting number of documents per tag. Also created a related documents using tags, the more tgas they have in common the more related they are. Not that great but good enough.
Thanks for the help, I will see if I can use it to improve what I have already implemented.
TagQuery is the recommended way afaiu, i.e Umbraco.TagQuery.GetContentByTagGroup("default"); <- returns all IPublishedContent with tags in that group. However it does also return some with empty tags it seems. So Umbraco.TagQuery.GetContentByTagGroup("default").Where(d=>d.HasValue("myTagProperty")) is better.
is working on a reply...