Now you'll need an index directory. Just make the directory; call it "myindex". Verity will fill it when the time comes.
The first time through, the form variables don't exist; so, give them values with the cfparam tag. Notice that the submit buttons provide useful values but the cfparam tag defines the variables for these submit buttons as empty strings. That's so you can tell which button was pressed. The submit button that was pressed will have a value whose length is greater than zero. The other button will have a value whose length is zero.
As mentioned above, this form has two submit buttons. If you've added documents to the "dictionary", you'll want a way to reindex. If you just want to spellcheck using the current index, you'll want a button for that also. Put all of this tip's code into spell.cfm.
<cfparam name="form.myinput" default="enter text here"> <cfparam name="form.doit" default=""> <cfparam name="form.redo" default=""> <form action="spell.cfm" name="myspeller" method="post"> <textarea name="myinput" wrap="physical" rows="4" cols="30" value=""> <cfoutput>#form.myinput#</cfoutput></textarea> <input name="doit" type="submit" value="Spellcheck"> <input name="redo" type="submit" value="Reindex"> </form>
<cfset mypath="c:\PathOnYourBox\spell\"> <cfset myindex=#mypath#&"myindex"> <cfset mydocs=#mypath#&"mydocs">
You'll want to tell Verity where to put the initial index. If you ever move or get rid of it, you'll want to tell Verity to forget where it put the index. These fragments of code won't hurt the original pages; they only affect the index directory.
Leave the comments around the fragment to delete a collection. You won't need to run this code until you want to get rid of the collection someday.
<!--- Delete a Collection <cfcollection action="delete" collection="stuff" path="#myindex#"> --->
You will run the following code once to create the collection. It's shown surrounded by comments. REMOVE THE COMMENTS. Run the code once. THEN REPLACE THE COMMENTS.
<!--- Make a Collection <cfcollection action="create" collection="stuff" path="#myindex#"> --->
<cfif len(form.redo)> <!--- Purge a Collection's Index ---> <cflock name="purgemystuff" timeout="20"> <cfindex action="purge" collection="stuff" key="#mydocs#" type="path" extensions=".txt"> </cflock> <!--- Index a Collection; extension is necessary ---> <cflock name="indexmystuff" timeout="20"> <cfindex action="update" collection="stuff" key="#mydocs#" type="path" extensions=".txt"> </cflock> </cfif>
<cfset badcount=0> <cfset outstring=""> <cfset outsep=""> <cfset form.myinput=replace(form.myinput,chr(42),"")> <cfset mynulls=" 0123456789.;!=+-,$%^&()*?">
When you use Verity for other tasks, you want to bring back a summary of what was found. However, in this context, you just want to know if you got at least one hit: recordcount is greater than zero. If the word was NOT found, add the output separator - it starts off empty - in front of the bad word. Then, make the output separator into a comma followed by a space so that the new combination will precede each bad word from now on. Increment the badcount so you'll know at least one word was NOT found. Then, loop to do more searches until spellchecking is complete.
<cfloop index="word" list="#form.myinput#" delimiters="#mynulls#">
<cfif not findNoCase(word,".and.or.not")>
<cfsearch collection="stuff" name="mysearch" type="simple" criteria=#word#>
<cfif not mysearch.recordcount>
<cfset outstring=outstring&outsep&word>
<cfset outsep=", ">
<cfset badcount=badcount+1>
</cfif>
</cfif>
</cfloop>
<cfif badcount> <cfoutput>#outstring# ...should be checked</cfoutput> </cfif>
Now run spell.cfm, type in some text if you wish, and click on "Reindex" to get Verity to build an index for your "dictionary". Reindexing may take a minute or so. If you typed in text that contains a misspelled or uncommon word, you should find it in a list of words for you to check. If you think the word should be in your dictionary, put it in one of the text documents in mydocs or add another document that has that word, then reindex again.
Now that you have an index, type some more text and press "Spellcheck". This time, the search will take only a few seconds to run.
To add spellchecking to an existing form, you can add a "Spellcheck" submit button and have your current action page spellcheck if it sees the value for this button. Better yet, it may be possible to do something less intrusive. Imagine opening a separate window for the spellcheck, leaving your original form ready to proceed. Imagine opening an alert box with the incorrectly spelled words. Then do these things and tell us how. =Marty=