Sunday, August 23, 2009

Dynamic Power Point presentation using ColdFusion

The below code snippets will show you how you can generate a dynamic power point using ColdFusion 9.
This is the start of the code:

<cfpresentation format="ppt" destination="f:\test\a.ppt" title="" overwrite="yes">
The code for the first slide:

<cfpresentationslide>
<html>
<body background="file:///f:/temp/bg1.jpg">
<h1 style="color:YELLOW"> This is pure HTML page </h1>
<h2 style="color:RED"> Sub title </h2>
<ul>
<li> test 1 </li>
<li> test 2 </li>
<li> test 3 </li>
</ul>
</body>
</html>
</cfpresentationslide>
The code for the second slide. This is a dynamic slide having a chart generated from a database:

<cfpresentationslide>
<cfquery name="GetSalaries" datasource="cfdocexamples">
SELECT Departmt.Dept_Name,
Employee.Dept_ID,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID = Employee.Dept_ID
</cfquery>

<cfquery dbtype = "query" name = "DataTable">
SELECT
Dept_Name,
AVG(Salary) AS avgSal,
SUM(Salary) AS sumSal
FROM GetSalaries
GROUP BY Dept_Name
</cfquery>

<!--- Reformat the generated numbers to show only thousands. --->
<cfloop index = "i" from = "1" to = "##DataTable.RecordCount##">
<cfset DataTable.sumSal[i] = Round(DataTable.sumSal[i]/1000)*1000>
<cfset DataTable.avgSal[i] = Round(DataTable.avgSal[i]/1000)*1000>
</cfloop>

<!--- Bar graph, from Query of Queries --->
<cfchart format="jpg"
xaxistitle="Department"
yaxistitle="Salary Average">

<cfchartseries type="bar"
query="DataTable"
itemcolumn="Dept_Name"
valuecolumn="avgSal">

<cfchartdata item="Facilities" value="35000">

</cfchartseries>
</cfchart>
</cfpresentationslide>
The code for the third slide. This shows an example of text formatting using HTML:

<cfpresentationslide >
<html>
<body style="color:GREEN" >

<h4 style="color:BLUE"> Some examples of HTML text formatting</h4>
<p><b>This text is bold</b></p>
<p><strong>This text is strong</strong></p>
<p><big>This text is big</big></p>
<p><em>This text is emphasized</em></p>
<p><i>This text is italic</i></p>
<p><small>This text is small</small></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
</body>
</html>
</cfpresentationslide>
Close the slides:

</cfpresentation>
The generated first slide:
The generated second slide:

The generated third slide:

Friday, August 21, 2009

Tuning ColdFusion Solr: Part 2

Don't forget to tune Solr Server for increased performance. First thing to do is to increase the Xmx value for Solr Server. To do so:

1) In windows -
* Shutdown Solr service
* Open solr.lax under Solr installation directory and modify the default setting -Xmx256m to -Xmx1024m.
* Start service
2) In Unix -
* Stop solr by going to solr installation directory and say:
./cfsolr stop
* Open cfsolr script and modify modify the default setting -Xmx256m to -Xmx1024m.
* Start by running the command:
./cfsolr start.

Tuning ColdFusion Solr: Part 1

In ColdFusion administrator, under "Solr Server", click on "Show Advanced Settings" and you will see a text box labled "Solr Buffer Limit". This is set to 40. This means when indexing documents, documents will be committed after every 40 KB of data. If you have allocated enough memory for ColdFusion say 1024m, increase this value to 80 and you can see increase in performance when indexing huge amount of data (especially text files).

Thursday, August 20, 2009

Searching for synonyms..

Solr supports searching synonym words. This means that if you have word called "computer" in your index, you can search using its synonyms like CPU, PC etc. To achieve this you will need to do the following :
(This example is for configuring Solr distributed through ColdFusion)

Under your collections directory (Lets say C:\ColdFusion\Collections\solrcollection), there will be a conf directory, under which you will have a synonyms.txt. Shutdown Solr and open the file.

Add your synonyms list in that.
Ex:
computer,PC,CPU,calculator
Save, exit and restart Solr service or process.

There are many synonym list available online. One such can be found here:

http://www.gutenberg.org/etext/3202

Loading the complete list is not a good idea because you will run out of memory. Add only what is relevant and have a small list. Try to convert to small cases wherever applicable and remove spaces.

To have the synonyms applicable to all collections, do the following:
Goto the Solr installation directory and browse to multicore\template\conf direcory.
Ex: C:\ColdFusion9\solr\multicore\template\conf

Update the synonyms.txt. This should be done before creating a collection.
The synonyms are mostly specific to your application. Say you are indexing books, you might want to have synonyms like rowling,potter,hogwarts etc (something similar to the labels).

Monday, August 17, 2009

Installing ColdFusion 9

If you want to install ColdFusion silently, follow these steps:

coldfusioninstaller.exe -i silent -f <property file>

The silent property file example is as below:

INSTALLER_UI=SILENT
SILENT_LICENSE_MODE=full
SILENT_SERIAL_NUMBER=
SILENT_INSTALLER_TYPE=standalone
SILENT_INSTALL_ODBC=true/false
SILENT_INSTALL_VERITY=true/false
SILENT_INSTALL_SAMPLES=true/false
SILENT_INSTALL_JNBRIDGE=true/false
SILENT_INSTALL_FOLDER=F:\\ColdFusion9
SILENT_WEBROOT_FOLDER=F:\\ColdFusion9\\wwwroot
SILENT_ADMIN_PASSWORD=password
SILENT_FLEX_ENABLED=true
SILENT_ENABLE_RDS=false
Note the two "\" as path separator. Without "\\" it will not uninstall.
Once installation is complete, Adobe_ColdFusion_9_InstallLog.log will be available under the directory you specified.
You can control the temp directory by setting temp to another directory:
set tmp=f:\temp
Incase of unix,
export IATMPDIR=somedirectory

Friday, August 7, 2009

Adding dynamic charts in spreadsheets using ColdFusion 9

Using spreadsheets is a new feature in ColdFusion 9. Do you know how to add dynamic charts in the spreadsheets?
The following code shows how to do it:


<cfchart format="png" scalefrom="-100"
scaleTo="100" gridlines="5"
name="test">
<cfchartseries type="line">
<cfchartdata item="Point1" value="-50">
<cfchartdata item="Point2" value="-25">
<cfchartdata item="Point3" value="1">
</cfchartseries>
</cfchart>

<cfset xlObj = SpreadSheetNew(true)>
<cfset spreadsheetAddImage(xlObj,test,"png","5,5,15,15")>
<cfspreadsheet action="write" name="xlObj" filename="/home/user1/spreadsheet/report1.xlsx">
The following figure shows the output of your effort: