A request cooker can arbitrarily modify a request. For example, you can use a request cooker to add extra parameters to any query that is sent to QMS. Request cookers are flexible and allow you to use custom rules to manipulate queries. The request cooker can be an external service, or you can use a Lua script.
When you use a request cooker, QMS sends the original action to the cooker. The cooker returns the modified request, and QMS applies whitelist, then blacklist, and then query text processing to it as necessary.
The cooker must specify the whole action to use.
You can also use an expanded request cooker to modify the request after QMS has applied any rules. See Use an Expanded Request Cooker.
The Lua script must provide a globally accessible cook_request
function, which accepts a string representation of the request as its only argument. The function must return a Lua table. The keys of this table are the parameter names to use in the action (the parameter names must be in lower case). The table values are the corresponding request values.
QMS loads the Lua script for every request that it cooks. This means that any changes to the script are reflected immediately in the query behavior.
The following example request cooker Lua script sets MaxResults
to 10
for all queries:
-- load module that provides string to table request parser aci = require "autn_aci" -- Set maxresults to 10 on every query function cook_request(request_string) cooked_request = aci.parse_request_string(request_string) cooked_request["maxresults"] = 10 return cooked_request end
This example assumes that the autn_aci.lua
file is in the same directory as your script.
You can use the IDOL Lua libraries in your Lua scripts. For more information about the available functions and methods, see the QMS Reference.
The following procedure describes how to configure QMS to use a request cooker from an external service, or a Lua script.
To use a request cooker
Add a [RequestCooker]
section to the QMS configuration file.
To use a custom Lua script to manipulate requests, set Mode
to lua
, and set Script
to the path to the script that you want to use. For example:
[RequestCooker] Mode=lua Script=scripts\cookrequest-maxresults.lua
To use an external server to manipulate requests, set Mode
to legacy
, and specify the host and port of the server. For example:
[RequestCooker] Mode=legacy Host=12.3.4.56 Port=8080
Send queries to QMS with the CookRequest
parameter set to True
.
If you want to cook all requests that you send to QMS, set the CookAllRequests
configuration parameter to True
.
When you set CookAllRequests
to True
, QMS does not retrieve or process cardinal placements.
Refer to the QMS Reference for more information on how to configure request cooking.
|