Site Tree

Automate Lucene Search Store Indexing

Here is a script that can be added to ColdFusion scheduled tasks to automate indexing of a few or all Lucene search stores.

<!--- This script is called from Scheduled Task and can be used for indexing a Lucene store --->
<!--- Make sure that url and form scopes are available in attributes scope --->
<cf_shado_urlform2attributes>

<!--- Make sure the script doesn't timeout --->
<cfsetting requesttimeout="5000">
<cfflush interval="10">

<!--- Get the search object --->
<cfset oStore = application.shado_obj_factory.get("shadomx.apps.search.store")>

<!--- Set a list of stores. Set the value of to "all"
if you want to index all stores. --->
<cfparam name="attributes.storenames" default="sitetree_en,fms_default">

<!--- If the store name equals "all" then get a list of stores--->
<cfif attributes.storenames eq "all">
<cfset qStoreNames = oStore.get()>
<cfset lStoreNames = valuelist(qStoreNames.name)>
<cfelse>
<cfset lStoreNames = attributes.storenames>
</cfif>

<!--- Do the good work and index --->
<cfloop list="#lStoreNames#" index="sStore">
<cfoutput>
<p>
Starting indexing #sStore# - #now()#
<cfset iStartTime = getTickCount()>

<cfset oStore.Index(storename=#trim(sStore)#)>

done... Time taken: #getTickCount()-iStartTime# ms.
</p>
</cfoutput>
</cfloop>

<!--- An empty div put in to avoid JS errors that might be caused.
the Index method looks for a div called indexMessage --->
<div id="indexMessage" class="indexMessage">
</div>

A couple of points:

  • The script should be saved in a folder inside the site folder.
  • Recommended path is /yoursite/app_templates/services/scheduled/indexLuceneStores.cfm

Comments

There are no comments for this page as yet.

Add a comment