Funnelback logo

Documentation

Sorting Results

Funnelback offers a variety of different sorting options for ordering results. This can be done by setting a query processor option or CGI parameter. The query processor option is:

-sort=<sort_type>

while the equivalent CGI parameter is "sort" e.g. "sort=date".

Sort Type Sort results by
date document date
adate ascending date
title document title
dtitle descending title
size file size
dsize descending file size
url url
durl descending url
coll collection name
dcoll descending collection name
metaX metadata class X
dmetaX descending metadata class X
shuffle random

Random sort (shuffle)

When -sort=shuffle is set, an additional parameter also needs to be set to ensure that the random sort that is chosen is maintained across search result pages.

This is done by setting the -rseed query processor option, which sets a random seed to use for the search. This parameter must be passed between search pages.

For truly randomised search, the rseed value should be set dynamically for each search (so not as a query processor option) otherwise you'll always get the same random sort for all queries.

The rseed value isn't set automatically - if you set sort=shuffle you'll need a hook script to set this value, and you'll need to ensure your forms and all search UI links pass through the rseed value.

Modern UI - pre process hook script

The following code can be set up as a hook_pre_process.groovy script and sets a random seed for a search if an rseed value is not set.

def q = transaction.question

// Set random seed (only if in shuffle mode, and if not already set)
if (q.inputParameterMap["sort"] != null) {
  if (q.inputParameterMap["sort"] == "shuffle") {
    if (q.inputParameterMap["rseed"] == null || q.inputParameterMap["rseed"] == "") {
      q.inputParameterMap["rseed"] = Math.abs(new Random().nextInt() % 9999 + 1).toString();
    }
  }
}

Classic UI - pre perform query script

The following code can be set up as a pre_perform_query.pl hook script and sets a random seed for a search if an rseed value is not set.

#Hook script to add a random seed if required
if ($qp_api->{'QUERY_STRING'}=~/(?i)sort=shuffle/) {
    if ($qp_api->{'QUERY_STRING'}!~/(?i)rseed=\d+/) {
        my $rs=int(rand(9999));
        $qp_api->{'QUERY_STRING'}.="&rseed=$rs";
        $orig_query_string.="&rseed=$rs";
    }
}

top ⇑