Sorting queries in the DRE

To sort a search result list, you must include an xoptions parameter in a query. Table C-3 describes the values you can use to sort the results.

Table C-3: xoptions parameters

Parameter

Description

sortdate

Sorts results by the date and time at which the document was added to the DRE.

sortboth

Sorts results by date and relevance (preferred method for sorting by date).

absweight

Sorts results by the sum of weights of the terms present in the document, rather than by a percentage score.

For example, you can sort by date using this HTTP request string:

http://HOST:QUERYPORT/qmethod=q&querytext=
     sybase&qnum=10&xoption=sortdate

Before submitting the query to the search bean’s doQuery method, you must modify the query to include the xoptions parameter. This example shows one method of controlling the sort order of search results:

public static final int SORT_DATE = 0;
public static final int SORT_BOTH = 1;
public static final int SORT_WEIGHT = 2;
public int numOfResults = 15;
public int minRelevance = 75;

&xoptions=<sort_option> is appended to the query. The ampersand (&) is required, and the syntax must be exactly as illustrated in this example:

/**
* Application's search method -- the decision of the
* order in which to sort the search results* is made here.*/

public void doSearch (Search searchBean,
                      String query,
                      int sortOrder)
{
    switch(sortOrder)
    {
        case SORT_DATE:
           query = query + "&xoptions=sortdate";
           break;
        case SORT_BOTH:
           query = query + "&xoptions=sortboth";
           break;
        case SORT_WEIGHT:
           query = query + "&xoptions=absweight";
           break;
     default:
          // unrecognized sort order
     }

     searchBean.doQuery(query, "", "", numOfResults, minRelevance);
}