Tags:
create new tag
, view all tags

Question

I am trying to create a KnowledgeBase for the TWiki at the company for which I work. Intially I created an initial page with a html form to create a new issue entry from a template. The template document contains TWikiForms fields for various bits of information. The page itself contains %FORMFIELD{}% tags to render the information of the topic in a visually appealing manor. Consequently the nonform contents of all my topics never changes, even when edited. (As an aside; I would like to suppress the table containing form data from rendering, any comments on that would be appreciated as well...)

This system was working well. I used FormattedSearchs on my main page to create a recent entries list and also created my own search feature on the main page using html forms and a formatted search that contained %URLPARAM{}% tags. I quickly noticed that there isn't a way to rank searches by relevancy. You can rank them by any form field though. This got me to thinking that I could include a FormattedSearch for the number of backlinks of each topic entry in a form field. Hits could then be ranked by how often they are referenced.

This quickly posed several problems. Firstly, there does not seem to be a variable for the number of search hits to use in the format field of the %SEARCH{}% tag (like $numhits or something). I got around this by including a FormattedSearch in each topic which rendered no results (but showed the number of hits) and commented it out. I then included another formatted search in the TWiki form field that contained a $pattern variable to extract just the number of hits (i.e. the number of backlinks) from the topic with a RegularExpression.

This worked fine when the entry topic was displayed (the form table at the bottom of the page displayed the number of backlinks) but I ran into problems when I was searching for the topic. I was using the %TOPIC% tag to restrict my searches (the ones used to extract the number of hits on the backlink search and put them in the form field) to their own topic. However when searched those topics form my main KnowlegeBase page, they were not working properly as the %TOPIC% tag in the form field resolved to the topic the results were displayed in and not the topic they were written in. I added the expandvariables="on" setting to my search in order to render the variables before the search, but when the search results were displayed, the $formfield() variable still rerendered them so that the %TOPIC% tag still came out as the search result page. I eventually got around this by automatically hard coding the topic into the search string contained in the form field using a javascript function in the main KB topic where the HTML form for creating new entry topics was. I then passed the search string directly into the form field of the new page.

This at least solved the problem %TOPIC% tags rendering improperly when displaying search results. However ranking hits by the contents of that form field did not do what I had expected. Even with expandvariables set to “on”, the results were ranked alphabetically by the literal content of the form field, which was of course a search variable and not an actual number. This also meant that the number of backlinks was being calculated each time I searched. This was not very helpful as it is makes for slow searches and improper rankings.

What I really need to make this work is a way to enter the actual number value into the form field and then update it automatically. I thought that this could be accomplished by the clients because they all have editing privileges. I could write a javascript into my page that would automatically update the field using the save script (using an onunload event). Despite the save script parameters being undocumented, I realized by looking at page sources and here on http://TWiki.org what they were. I also noticed that on each save the full text of the page must be submitted. Now my page text never changes, so I figured that I could hard code it into the hidden text input field of the form that would be used to accomplish the save.

This creates the obvious problem of self referencing; the text of the topic must contain a form field that contains the text of the topic which must contain a form field that contains the text of the topic which must contain a form field that contains the text of the topic… well you see where this was going. I need a way to generate the contents of the page on the submission, i.e. NOT by perl on the server (which I don’t have access to, so a server side solution is not an option for me). I thought I could get around this by making the actual contents of my page a custom TWikiVariable that would resolve to the page contents. The text field would then only need to contain that variable.

Anyway, so after all this back-story, (lol) the problem I’m having is that I can’t create custom TWikiVariables that resolve to multiple lines of text. When I try to simply include multiple lines the line break ends the variable definition. What I am wondering is if TWiki contains an escape character for a new line, such as \n or \r or something like that. I tried %_N_% and %_L_% (even the mighty <nop> doesn't let me keep these around) but that seems to add in the extra lines before the content is stored server side because when I look at the raw text of my preferences page it contains regular old new lines (boo).

I have tried storing the page content in a separate topic and sticking it in using an %INCLUDE{}% tag, but that’s not working because the include tag renders TWiki variables before including the page content which leads to improperly resolve variables. Also the contents are included as html and not TWiki code, which I would prefer because it’s much more readable. The irony is of course that if the search truly tag resolve variable first, I wouldn’t have this problem at all…

Any help would be appreciated, or if you have a fundamentally better way of ranking search results by number of backlinks, I’d be happy to listen. I have already had problems with my update java script because it seems that the server returns the page that was just saved after one uses the save script. This may lead to never being able to leave one of these pages… though I don’t really know for sure because my page content always breaks after saving.

In general I think that TWiki could benefit from a more complete documentation of its variables and perhaps a bit on the order of name resolution and just how TWikiVariables work. (Or maybe I’m just spoiled by MAPLE and its delicious use of ordered name resolution, typeless naming conventions and its delicious basic types. I mean who doesn’t love “function” as a basic type? Enough of this shameless plug from a University of Waterloo student though…) On the other hand I suppose if I want better documentation I should stop being so lazy and just write it myself and send it in to TWiki. If only I could understand PERL, I could probably solve my problem from just looking at the source code. Why can’t PERL be more like C# or JAVA?

Anyway, sorry for the long report and rant. If anyone has any ideas I’d love to hear from you.

As an afterthough: I have tried using <p /> and <br /> tags to fit all the code on one line but that results in an inability to render the pages all together (the server taks a long time to send anything at all to the browser). It also messes with my WebPreferences page. I will enculde the code I would like to put in a variable. I have also read that variable rendering is quite expensive server side... prehaps this is why my html tag method did not work? I would like to set KBPAGE to the following:

<!-- %SEARCH{ "%TOPIC%" format=" " header=" " notitle="on" noheader="on" nosearch="on"  }%-->
<script language="Javascript"> 
<!-- <pre> 
window.onload=function(){
if(document.referer != document.location){
document.notorietyUpdateForm.submit();
}
} 
// </pre> --> 
</script> 
<form name="notorietyUpdateForm" action="%SCRIPTURLPATH%/save%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%/%TOPIC%"}%" method="post" > 
<input type="hidden" name="text" value="%<nop>KBPAGE%" /> 
<input type="hidden" name="KBEntryNotoriety" value="%SEARCH{search="%TOPIC%" web="%WEB%" scope="topic" topic="%TOPIC%" limit="1" header="" format="$pattern(.*?Number of topics:.*?([0-9]+).*)" nosearch="on" expandvariables="on" noheader="on" nototal="on" }%" /> 
<input type="hidden" name="KBEntryIssue" value="%FORMFIELD{"KBEntryIssue"}%" /> 
<input type="hidden" name="KBEntrySolution" value="%FORMFIELD{"KBEntrySolution"}%" />
<input type="hidden" name="KBAffectedProducts" value="%FORMFIELD{"KBAffectedProducts"}%" /> 
<input type="hidden" name="cmd" value="" />
<input type="hidden" name="formtemplate" value="%WEB%.KbForm" /> 
<input type="hidden" name="topicparent" value="%WEB%.ExampleKnowledgeBase" /> 
</form> 
%TOC% 

---+ Notes On Editing 

To edit this document, use the relevant form fields. Do _not_ edit the contents of the last form field or the main text page. It is used for searching purposes. If you need to rename or move this file, you MUST change the name references in the KBEntryNotoriety form field. 

---+ Issue 

%FORMFIELD{"KBEntryIssue"}% 

---+ Solution

%FORMFIELD{"KBEntrySolution"}%

---+ Affected Products

%FORMFIELD{"KBAffectedProducts"}% 

----- 

Return to the ExampleKnowledgeBase.

Environment

TWiki version: TWikiRelease01Sep2004
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Client OS: Windows 2000 Pro
Web Browser: MS IE 6
Categories: Topic revisions, Forms, Search, Javascript

-- NicholasEngelking - 28 Jan 2005

Answer

It seems that I have solved my own problem. Rather than using a TWikiVariable I placed my page content into a textfile that references itself with an include statement. Special chars in the files are used to prevent rendering in the submit form. My code is as follows (I have wordwraped it to fit on this page, but there are no line breaks in the original file):

<!-- %<nop>SEARCH{ "%TOPIC%" format=" " header=" " notitle="on" noheader="on" nosearch="on"  }%-->
<script language="Javascript"> 
<!-- <pre><noautolinks> 
window.onload=function(){
if(document.referrer !<nop>= document.location){
document.notorietyUpdateForm.submit();
}
} 
// --> 
</script> 
<form name="notorietyUpdateForm" %NOP{action= }% "http://torsbdev8.bns/twiki/bin/save/%<nop>WEB%/%<nop>TOPIC%" method="post" > 
<input type="hidden" name="text" value="%<nop>INCLUDE{"http://torsbdev8.bns/twiki/pub/TWiki/ExampleKnowledgeBaseTemplate/pagetext.txt"}%" /> 
<input type="hidden" name="KBEntryNotoriety" value="%<nop>SEARCH{search="%<nop>TOPIC%" web="%<nop>WEB%" scope="topic" topic="%<nop>TOPIC%" limit="1" header="" format="$pattern(.*?Number of topics:.*?([0-9]+).*)" nosearch="on" expandvariables="on" noheader="on" nototal="on" }%" /> 
<input type="hidden" name="KBEntryIssue" value="%<nop>SEARCH{search="%<nop>TOPIC%" topic="%<nop>TOPIC%" scope="topic" limit="1" nosearch="on" noheader="on" nototal="on" format="$formfield(KBEntryIssue)"}%" /> 
<input type="hidden" name="KBEntrySolution" value="%<nop>SEARCH{search="%<nop>TOPIC%" topic="%<nop>TOPIC%" scope="topic" limit="1" nosearch="on" noheader="on" nototal="on" format="$formfield(KBEntrySolution)"}%" />
<input type="hidden" name="KBAffectedProducts" value="%<nop>SEARCH{search="%<nop>TOPIC%" topic="%<nop>TOPIC%" scope="topic" limit="1" nosearch="on" noheader="on" nototal="on" format="$formfield(KBAffectedProducts)"}%" /> 
<input type="hidden" name="formtemplate" value="%<nop>WEB%.KbForm" /> 
<input type="hidden" name="topicparent" value="%<nop>WEB%.ExampleKnowledgeBase" /> 
</form> 
</noautolinks>
</pre>
%<nop>TOC% 

---+ Notes On Editing 

To edit this document, use the relevant form fields. Do _not_ edit the contents of the last form field or the main text page. It is used for searching purposes. If you need to rename or move this file, you MUST change the name references in the KBEntryNotoriety form field. 

---+ Issue 

%<nop>FORMFIELD{"KBEntryIssue"}% 

---+ Solution

%<nop>FORMFIELD{"KBEntrySolution"}%

---+ Affected Products

%<nop>FORMFIELD{"KBAffectedProducts"}% 

----- 

Return to the ExampleKnowledgeBase.


This code will update the KBEntryNotoriety meta tag with the hardcoded number of back links whenever someone visits the page (and has javascript enabled). This way I can search and sort entries by the number of backlinks without having to calculate backlinks for each hit.

-- NicholasEngelking - 31 Jan 2005

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2005-02-20 - CrawfordCurrie
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.