Customize the Output
The CategorySuggestFromText
Lua script creates the following document fields by default:
Field name | Value |
---|---|
category_title
|
The name of the category. |
category_id
|
The ID of the category in IDOL Server. |
category_reference
|
The DREREFERENCE of the category, stored as a document in the Agentstore. |
The script adds one value to each field for each category that matches the document. For example:
#DREFIELD category_id="200" #DREFIELD category_id="100" #DREFIELD category_reference="200" #DREFIELD category_reference="100" #DREFIELD category_title="Science" #DREFIELD category_title="BusinessNews"
To modify how the information is added to the document, customize the Lua script. For example, to change the names of the fields, modify the first argument of the addField
method on lines 211 to 213:
document:addField("category_name", category["title"]) document:addField("category_ref", category["reference"]) document:addField("category_id", category["id"])
To add only the category names, remove lines 212 and 213:
document:addField("category_title", category["title"]) -- document:addField("category_reference", category["reference"]) -- document:addField("category_id", category["id"])
To add all of the category information to a single field, using subfields, you could modify the script as follows (replacing lines 207-219):
if(suggestWasSuccessful) then local suggestedCategories = parseCategories(output) document:addField("category", "category information") local field = document:getField("category") for i, category in ipairs(suggestedCategories) do field:addField("title",category["title"]) field:addField("reference",category["reference"]) field:addField("id",category["id"]) end document:setFieldValue("result", output) return true end
To add all of the category names to a single field as a comma-separated list, you could modify the script as follows (replacing lines 207-219):
if(suggestWasSuccessful) then local suggestedCategories = parseCategories(output) local names="" for i, category in ipairs(suggestedCategories) do if i==1 then names = category["title"] else names = names .. "," .. category["title"] end end if names~="" then document:addField("category_names_CSV", names) end document:setFieldValue("result", output) return true end