[C #] Tag development skills in asp. ent 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.
Copy codeThe Code is as follows:
<% @ 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>

Related Article

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.