Question
I'm trying to find a way to determine the number of child topics for a specific parent topic. So far, what I've found through Google is how to display them. This idea stemmed from a very simple forum page I'm currently developing. What I've done is after a user replies to a posted subject/topic, that subject/topic becomes the parent of the user's reply message. The following table should help illustrate what I'm trying to do.
Basically, I'm concerned right now on how to count the number of replies for a specific topic. The first row on the table means that there are 3 child topics for ParentTopic1.
Any help would be very much appreciated.
Environment
--
FredanLangam - 13 Oct 2007
Answer
If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.
I created a discussion forum (not released yet) with a nested SEARCH. The inner SEARCH has a CALC in the
format="" to count the number of topics. The inner SEARCH looks for a particular TWiki form, not for the parent.
Screenshot:
SEARCH:
| *Forum* | *Topics* | *Last post* |
%SEARCH{ "META:FORM.*[D]iscussionForumForm" type="regex" excludetopic="%TOPIC%, DiscussionForumTemplate" nonoise="on" format="| %ICONURL{persons}% [[$topic][$formfield(Name)]]%BR% $formfield(Description) $percntCALC{$SET(num, 0)}$percnt $percntSEARCH{ \"META:FORM.*[D]iscussionTopicForm;META:FIELD.*Forum.*value=.$topic\" type=\"regex\" topic=\"$topic*\" excludetopic=\"DiscussionTopicTemplate\" order=\"modified\" nonoise=\"on\" format=\"$dollarpercntCALC{$SET(user, $dollarwikiusername)$SET(date, $dollardate)$SETM(num, +1)}$dollarpercnt\" separator=\"<nop>\" }$percnt | $percntCALC{$GET(num)}$percnt | $percntCALC{$GET(date) by $GET(user)}$percnt |" }%
--
PeterThoeny - 14 Oct 2007
Actually, the forum page I'm developing also contains a form which will hold the following information: subject, message and the
WikiName of the person who started the forum. This form is filled in when a forum is created and the same form is also filled in when someone replies to a posted forum. I don't exactly know if it's the best way to do this thing but I thought I wanted to keep it that simple for the mean time (or so I think). But then, the problem of segregating between the original message and the reply messages came in. Since I know the idea of parent-child topic relationship in TWiki, I thought perhaps I can take advantage of that by adopting it in the forum page. Anyway, I'll watch out the release of your discussion forum. I'm looking forward to get some idea from there that I can use in refactoring my forum page.
Going back to the question, just this afternoon I was able to figure out just how to count the child topics of the parent topic. I used a CALC then a SEARCH and then another CALC, executed one after the other. The first CALC is used to initialize a variable to zero. The SEARCH is used to look for child topics given the parent topic. Just like what you suggested, I also placed a CALC in SEARCH's
format="" portion. The purpose of this is that every search hit should return 1 which is then added to the variable defined in the first CALC. Finally, the last CALC will return the value of the variable.
The search string is as follows. Since the replies count is nested in a primary search (for posted forum), special characters have to be escaped for this to work.
Screenshot:
| *Subject* | *Replies* |
%SEARCH{"ParentTopic[0-9]$" web="%WEB%" type="regex" scope="topic" nosearch="on" nototal="on" format="| $topic | $percntCALC{$dollarSET(my_replies, 0)}$percnt$percntSEARCH{\"$topic\" web=\"$percntWEB$percnt\" excludetopic=\"$topic$dollar\" type=\"regex\" scope=\"topic\" nosearch=\"on\" nototal=\"on\" format=\"$dollarpercntCALC{$dollardollarSETM(my_replies, + 1)}$dollarnop$percnt\" separator=\" \"}$nop$percnt$percntCALC{$dollarGET(my_replies)}$percnt |" separator="$n"}%
The next thing I'll be working on is how to get the timestamp of the last post. I guess this will now be easy basing from the progress I've done with the replies column.
Thank you very much for the assistance.
--
FredanLangam - 14 Oct 2007
Hi, maybe you can use also the
$count parameter of formatted search "format" parameter, see:
FormattedSearch
PS: Having a forum TWiki application would be quite cool!
--
ColasNahaboo - 15 Oct 2007
I just posted the forum app:
TWikiDotNetForumAppAddOn
--
PeterThoeny - 16 Oct 2007
This is indeed very useful! I'm already done doing my forum page but I think I will switch to this one.
--
FredanLangam - 17 Oct 2007
I am glad you find it useful. Thanks for using it!
--
PeterThoeny - 18 Oct 2007