Tags:
create new tag
view all tags

Question

I have been asked to create a search that returns a list of topics but randomizes their order each time the list is rendered. Does anyone have any ideas how this could be done?

I've looked at RandomTopicPlugin and RandomReplacePlugin but these don't quite do what I need. Perhaps one could utilize the $RAND attribute in SpreadSheetPlugin in some way...?

Any suggestions appreciated!

Environment

TWiki version: TWikiRelease04x00x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Search, Plugins

-- LynnwoodBrown - 06 Jun 2006

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

As you mention, the SpreadSheetPlugin already has a $RAND(). However, I do not think that it helps since you need to randomize a list. The Plugin has already many list functions, what you need is a new $LISTRAND() function that randomizes a list.

-- PeterThoeny - 06 Jun 2006

I did something similar to work recently, though it wasn't pretty. Check it out if you like: link

  1. Make sure that whatever you are searching has a
    %CALC{"$RAND()"}%
    somewhere identifiable.
  2. When generating your table of results, make sure each result has the random number as one of its columns (you'll probably have to use $pattern in a formatted search).
  3. Make sure the TablePlugin is installed. Precede your search results with
    %TABLE{sort="on" initsort="1"}%
    where 1 is the column with the random number.

The main problem with this method is that it doesn't look pretty, as you have a column with some huge random number. Also, in your case, it might be a problem to put a random number in your selected pages.

I would be very grateful if there were a $LISTRAND() function or something similar.

-- ChadBoulay - 07 Jun 2006

The $LISTRAND() option for SpreadSheetPlugin sounds interesting, but how would one apply this to a list generated by a search (particularly a FormattedSearch)? What about a new order="random" option for VarSEARCH?

-- LynnwoodBrown - 07 Jun 2006

On TWikiIRC, MartinCleaver pointed me to this perl program to randomize lists. Looking at the order functions in search.pm , it appears to me that something like this would be pretty easy to incorporate. Any comments from someone that actually knows perl?

-- LynnwoodBrown - 07 Jun 2006

CPAN:Algorithm::Numerical::Shuffle

-- WillNorris - 07 Jun 2006

A search result returned in a random order is a border case, I believe it is better not to take this into the core search, and to enhance CALC with a $LISTRAND(). With this it is easy to display a list of topics in random order: In the SEARCH add the topic name to a list, saved by $SET(). After the SEARCH use a $LISTRAND() to shuffle the list.

-- PeterThoeny - 07 Jun 2006

Could that approach be (easily) used to shuffle a highly formatted result from a search?

-- LynnwoodBrown - 07 Jun 2006

No, for this you'd need a hash variable feature in the SpreadSheetPlugin. Or, alternatively a SEARCH enhancement with a order="random" option. Thinking this over, it would be OK to enhance the SEARCH even though it is an esoteric case. This is because it is a small change, and because it is out of the way from normal use.

-- PeterThoeny - 08 Jun 2006

I've submitted a FeatureRequest to get further feedback: RandomSearchOrder.

-- LynnwoodBrown - 08 Jun 2006

Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2006-06-08 - LynnwoodBrown
 
  • 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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.