[C #] Tag development skills in Web Development

Source: Internet
Author: User
Commonly used keywords (TAGS) for website development generally require the most popular tags.
The general idea is to save the keyword tag to a separate table, and then identify multiple keywords in other tables based on a group of IDs. Because one article can select multiple tags, it is quite troublesome to query.
So I used this method in development. Of course it's not much clever :). Share your experiences.

Store tags directly in the document table, such as the tag field. The tags are "C #" and ". the tag field value is "C #/. net "is to split the tag by/symbol, so that the database stores strings. When a single article is displayed, it can be directly divided into Arrays for display, reducing table Association and improving efficiency.
When you need to display recent buzzwords.
Query all tags
Select tag from table
Use datareader to add the output results. Then convert the string based on the delimiter. The rest is to sort the string based on the tag weight. And return the number of duplicates, see the code. For ease of viewing, I wrote them on An ASPX page.

Program code <% @ page Language = "C #" %>
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "XXXX. BLL" %>
<% @ Import namespace = "XXXX. Model" %>
<% @ Import namespace = "XXXX. dbutility" %>

<SCRIPT runat = "server">

Protected string stext;
Protected void page_load (Object sender, eventargs E)
{
Stringbuilder sb = new stringbuilder ();
Using (system. data. sqlclient. sqldatareader RD = XXXX. dbutility. sqlhelper. executereader (sqlhelper. connectionstring, system. data. commandtype. text, "select kinds + '/' from XXX", null ))
{
While (RD. Read ())
{
SB. append (RD. getstring (0 ));
}
}
Stext = sb. tostring ();

Toarraybysort (toarray (stext ,'/'));

}

/// <Summary>
/// Convert the string into an Array Based on the delimiter
/// </Summary>
/// <Param name = "sourcestring"> string to be converted </param>
/// <Param name = "compart"> delimiter </param>
/// <Returns> </returns>
Public arraylist toarray (string sourcestring, char split)
{
Charenumerator Ce = sourcestring. getenumerator ();
Stringbuilder sb = new stringbuilder ();
Arraylist slist = new arraylist ();

While (Ce. movenext ())
{
If (Ce. Current! = Split)
{
SB. append (Ce. Current );
}
Else
{
If (string. Empty = sb. tostring () continue;
Slist. Add (sb. tostring ());
SB. Remove (0, SB. tostring (). Length );
}
}
Return slist;
}

Public class mycomparer: icomparer
{
Int icomparer. Compare (Object X, object y)
{
Return (New caseinsensitivecomparer (). Compare (sortitem) Y). Count, (sortitem) x). Count ));
}
}

Public class sortitem
{
Private string itemname;
Private int count;
Public sortitem ()
{
}
Public String itemname
{
Get {return itemname ;}
Set {itemname = value ;}
}
Public int count
{
Get {return count ;}
Set {COUNT = value ;}
}
}

Public System. Collections. Generic. ilist <sortitem> toarraybysort (arraylist slist)
{
Slist. Sort ();
Arraylist sortlist = new arraylist ();
Foreach (Object OBJ in slist)
{
Sortitem sitem = new sortitem ();
Sitem. itemname = obj. tostring ();
Sitem. Count = 1;
If (sortlist. Count = 0) {sortlist. Add (sitem); continue ;}
If (obj. tostring () = (sortitem) sortlist [sortlist. Count-1]). itemname)
{
Sitem. Count = (sortitem) sortlist [sortlist. Count-1]). Count + 1;
Sortlist. removeat (sortlist. Count-1 );
}
Sortlist. Add (sitem );
}
Mycomparer mycm = new mycomparer ();
Sortlist. Sort (mycm );

System. Collections. Generic. ilist <sortitem> ilist = new system. Collections. Generic. List <sortitem> ();
Foreach (Object OBJ in sortlist)
{
Ilist. Add (sortitem) OBJ );
// Response. Write (sortitem) OBJ). itemname + "-" + (sortitem) OBJ). Count. tostring () + "<br/> ");
}
Return ilist;

}
</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.