Back to mnoGoSearch site

mnoGoSearch 3.3.12 reference manual: Full-featured search engine software



UserOrder -- specifies an SQL query for user defined ordering



UserOrder {name} {sql-query}


The UserOrder command allows to configure a user defined ordering of the documents.

The default way of sorting by a user defined section is possible with help of s=S&su=secname search parameters, however it can be slow in case of a big database. UserOrder allows to improve performance of ordering by a user defined section by preliminary caching the data required for sorting in a quickly accessible format.

The sorting data is cached in the database whenever indexer -Eblob or indexer -Erewritelimits is run.

When processing the s=S&su=secname search parameters, search.cgi checks if cached sorting data for fast ordering presents in the database and uses the cached data on success. Otherwise, it switches to the slow method of ordering by direct query to the urlinfo table.

The first parameter name stands for the user order name.

The second parameter sql-query represents an SQL query which returns a result set consisting of a single column with values corresponding to IDs of the documents. The IDs must be returned in the desired order by using the ORDER BY clause in the SQL query. The SQL query should typically fetch data from the table url (using the column rec_id) or the table urlinfo (using the column url_id).

Note: The IDs of the documents are stored in the rec_id column of the url table of mnoGoSearch database. To know an ID of a certain document you can run this SQL query:

SELECT rec_id FROM url WHERE url='http://hostname/page1.html';

It is possible to configure multiple UserOrder commands in the same indexer.conf. The name argument must be unique in every UserOrder command.

search.cgi detects which UserOrder command to use by taking its name from the su=secname search parameter. If no su parameter is given, or the su value is empty, then non of the UserOrder commands are applied for ordering.


# Prepare data for fast ordering by Title
UserOrder title "SELECT url_id FROM urlinfo WHERE sname='title' ORDER BY sval"

# Prepare data for fast ordering by document size
UserOrder title "SELECT rec_id FROM url ORDER BY docsize"

See also

Limit, UserScoreFactor, UserSiteScore, the Section called Search parameters in Chapter 10.