Store Content in IDOL Server > Process Data before you Index > Use Lua Script Index Tasks > Example Script

Example Script
For each document, this Lua script adds a COUNT field, a total sections count to the title, and replaces the content of each section with the section number.
NOTE The COUNT is 1 for the first document and increases as long as the indextasks process is running.
doc_count = 0
function handler(document)
doc_count = doc_count + 1
local section_count = 0
local section = document
while section do
section_count = section_count + 1
local field = section:findField("DRECONTENT")
if field then
    section:fieldSetValue(field, "Section "..section_count);
section = section:getNextSection()
local field = document:findField("DRETITLE")
if field then
document:fieldSetValue(field, document:fieldGetValue(field).." Total Sections "..section_count)