ORDERBY TagCount?

Jon White asked on October 20, 2014 12:31

Hi me again!

I've got a repeater with a where condition as below:

DocumentID IN ( SELECT DocumentID FROM CMS_DocumentTag WHERE TagID IN ( SELECT TagID FROM CMS_DocumentTag WHERE DocumentID = {%DocumentID%} )) AND DocumentID != {% CurrentDocument.ID #%}

I'm using a repeater to show related articles based on keywords, but is there a way to re-order the transformation list of pages based on amount of relevent keywords (i.e. if a related document has 3 matching keywords place it at the top of the list), I was hoping for an 'Orderby Tag Count' condition?

Is this possible?

Thanks Jon

Recent Answers


Virgil Carroll answered on October 21, 2014 23:53

Yeah others can chime in here, but I do not know a way you would accomplish this easily. You really want to do some kind of weighted ranking of items which is not something that is very straight forward to do. Below I shared a couple of alternative directions you could possibly look down.

First, you could write a function in SQL to grab the count of relevant keywords and return as a value in the query so you can sort on that. (probably easier to use a stored procedure to do the query and call the function). The big caveat on this is doing too much at the Kentico database level, you would just want to document well so you don't lose changes during subsequent version upgrades.

The second option would be to do this through code and count the relevant tags from there. You could look at the code behind the Tag Cloud webpart and back track from there as the tags show at different sizes based on how many items are 'tagged' with it. This could at least give you a code direction.

Wish I could of given you an easy answer but you have a tough one there.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 22, 2014 05:48

If you look in the Tag Cloud webpart there are examples of getting the tags for a document. The returned dataset from TagInfoProvider.GetTags()has the TagCount property available for you to order by. You should be able to create your own macro/method/transformation method that accepts the group name or id and returns back the counts for each tag ordered by count datatable.

In fact, the whole webpart has everything you need to accomplish your task.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.