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 dates (newest first)
adate Document dates, ascending (oldest first)
title Document title (0,9 - A-Z)
dtitle Descending document title (Z-A)
metaX Metadata class X (0..9, A-Z), then score
dmetaX Descending metadata class X (Z-A, 9-0), then score
prox Geospatial proximity (nearest first)
dprox Descending geospatial proximity (furthest first)
size File size (largest first)
dsize Descending file size (smallest first)
url URL (0-9, A-Z)
durl Descending URL (Z-A, 9-0)
coll Collection name (0-9, A-Z), then score
dcoll Descending collection name (Z-A, 9-0), then score
shuffle Random

Date sort (date, adate)

By default, future dates are ignored during sorting. Allowing future dates will require a modification to the collection's Indexer Options.

Geospatial Proximity sort (prox, dprox)

A user's location will be inferred from their IP address unless overridden with an explicit origin=lat,long CGI value. Results that do not have a geospatial component will be regarded as being an 'unknown' distance away, and will always appear after the results that do have a geospatial component.

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();
    }
  }
}