Tagging for Developers

From Sense/Net Wiki
Jump to: navigation, search

Overview

Example title
On this page you can find informations about usage of portlets, applications and other features for tagging functionality.

Details

Portlets

Tag Admin Portlet

TagAdmin.jpg

Overview

Tag admin Portlet is intended for administrating tags in the system.

The following actions can be performed:

  • Listing tags with sorting based on any property
  • Add a new tag to content repository ()
  • Edit, delete and blacklist any tag in the content repository
  • Import new tags to content repository
  • Delete unused tags from content repository
  • Search for tags via the Tag Search Application

Creating new tags

  • Creation of new tags will use the TagManager.AddToRepository("TagToAdd", "PathToSave");
  • New Tag contents will be created in the repository. The creation path depends on the TagPath property of the portlet.
  • Reference counts of new tags will be set to zero and will be suggested to purge until they are used.

Editing and Deleting tags

Reference counts

  • Reference counts are based on the Lucene Index. TagManager.GetTagOccurrencis() is used.
  • Only the referenced tags will have results from the above function, unreferenced tags will have none.
  • If a tag's reference count is zero then it will be suggested to purge.

Search for a specific tag

Tag Cloud Portlet


Tag Cloud Portlet

The Tag cloud Portlet is a portlet for rendering the Tags in the system as a TagCloud.

The portlet lists every tag in the system and shows it in different sizes depending on occurency. The more the tag used on a content the bigger it is in the TagCloud. By clicking on a tag in the cloud you will be redirected to the search page related to that tag.

Tag Search Portlet


Tag Cloud Portlet

Overview

Tag search Portlet is intended for searching content which has given tag in the system.

  • Listing the the search result
  • Offer hints for avalaible tags in the system

Start search

  • Type into the textbox which tag you want to looking for and click search.
  • Make a link which Tag Search Application can use.

Behind the portlet The portlet view implement the ITagSearchPortlet interface

  • Get the parameter in LastSearchedTag varible
  • Get the search result in the Result varible
  • Triger the TagSearching event which basically make the query use the TagManager.GetNodeIds(queryString);

Applications

Tag Search Application

Tag Search Application based on a smart applicatiin model which uses the Tag search Portlet.

Other

Tag Manager


Overview

The Tag Manager static class is the base of tagging funcionallity. The following tag-related functions and portlets uses the Tag Manager:

  • TagAdmin portlet
    • TagManager.GetTagOccurrencies() for counting references
    • TagManager.GetAllTags() for getting information about new tags to sync
    • TagManager.ReplaceTag() when changing or deleting tag
    • TagManager.SynchronizeTags() for importing new tags, and purging tags without reference
  • TagCloud portlet
    • TagManager.GetTagClasses() for displaying all tags distributed to 10 class based on reference count
  • TagSearch portlet
    • TagManager.GetNodeIds() for getting the node id-s corresponding to the searched tag
  • TagHint (autocomplete)
    • TagManager.GetAllTags() for getting tags containing the given string fragment

TagManager examples

Displaying each tag with its reference count
var tagcounts = TagManager.GetTagOccurrencies();
foreach (var tag in tagcounts)
{
  Console.WriteLine(tag.Key + ": " + tag.Value);
}
Getting tags containing a specific string fragment
var tags = TagManager.GetAllTags("fragment");
Manually add a new tag to Content Repository
TagManager.AddToRepository("TagToAdd", "PathToSave");
Delete or replace a specific tag on every content in the repository
TagManager.ReplaceTag("TagToReplace", "NewTag"); // Use this for replacing
TagManager.ReplaceTag("TagToRemove", ""); // Use this for deleting
Checking if a tag is present in the Content Repository
bool result = TagManager.IsInRepository("TagToCheck");
Checking if a tag is blacklisted
bool result = TagManager.IsBlacklisted("TagToCheck");
Importing new tags to Content Repository and deleting unreferenced ones
TagManager.SynchronizeTags("PathToImport");


Tag Field Control


Overview

This Field Control is resposible for displaying and setting tags stored on the content, in the Content Explorer or on a page of your portal. For the Tags field, this control will be rendered automatically for every content.

  • In browse mode it only displays tags of the actual content as links for instant searching.

TagBrowseExample.jpg

  • In edit mode next to the tags (links) a TextBox is displayed as well for adding new tags to the content.

TagEditExample.jpg

  • If the viewer user has administrator privileges, the control renders without any links, as a multi-line TextBox so tags can be removed from the content this way.

TagAdminExample.jpg

Properties

The following properties can be set on Reference:

  • For properties common to all Field controls, see here.
  • SearchPath - The path of the tag search application. This app will be used for searching when a tag link is clicked. Default value: "/Root"
  • SearchFilterName - The URL parameter name for searching. It depends on the search application. Default value: "TagFilter"
  • TagSplitChars - A String paramater which represents an array of splitting characters. The value of Tags field will be splitted based on these. Also, after each save all the separator characters will be replaced by a single space (" "). Default value: { ' ' }
  • NotAllowedChars - A String parameter which represents an array of not allowed characters. These will be removed from newly added tags. Default value: { '&', '\\', '/', '?' }

Examples

Generic Example
 <sn:TagList ID="{UniqueId}" runat="server" FieldName="{FieldName}" SearchPath="{SearchPath}" 
SearchFilterName="{SearchFilterName}" TagSplitChars="{TagSplitChars}" NotAllowedChars="{NotAllowedChars}"  />
Specific short example

This example displays the tags from the "Tags" field of the content. For SearchPath, TagSplitChars, NotAllowedChars the default values will be used.

 <sn:Reference ID="TagList1" runat="server" FieldName="Tags" />
Specific long example

This example displays the tagging control for the actual content using custom search page, separator and not allowed characters.

 <sn:Reference ID="TagList1" runat="server" FieldName="Tags" SearchPath="/Root/MySearchPage.aspx"
SearchFilterName="MyParamName" TagSplitChars=";.:-+" NotAllowedChars="+,132" />

Related links

References