Aaron Johnson Now with 50% less caffeine!

Posted
24 April 2003 @ 1am

Tagged
ColdFusion, Lucene

CFX_LUCENE

I mentioned Lindex (described as a “… high performance, full-featured text search engine that allows developers to create document collections for easy indexing and quick searching” two days ago. After inspecting it a bit further, it looks like it offers an interface for developers to create and maintain Lucene indexes using ColdFusion (and I’m guessing allows them to search indexes as well), which is a nice feature.. I’d love to see it.

Anyway, inspired by Lindex, tonight I hacked together a Java CFX tag that closely mimics the the <cfsearch> tag using Lucene as the search engine. You can download the Java source here [ update 11/04/2003: Nick Burch from torchbox.com sent me an updated version that "behaves better under error conditions and ... the command line debug now works", thanks Nick!, clicking on the 'lucene.java' link above will download the updated version ].

To compile it, you’ll have to add both the cfx.jar file (usually in \CFusionMX\lib\cfx.jar) and the lucene.jar (get yours here) file to your classpath manually or specify them at compile time. If you’re compiling from the command line, it might look something like this:

$ javac -classpath c:\cfusionmx\lib\cfx.jar;c:\lucene\lucene.jar lucene.java

After you compile the class, you’ll need to

a) copy it to a directory that ColdFusion is aware of (ie: /cfide/administrator/ –> Java and JVM –> Class Path)

b) add the lucene.jar to the Class Path mentioned in ‘a’

c) register the CFX in the ColdFusion Administrator (/cfide/administrator/ –> Extensions –> CFX Tags. Click on ‘Register Java CFX’. The tag name should be ‘cfx_lucene’, the class name should be ‘lucene’.

d) restart CFMX.

e) and finally, create a .cfm page and add this script:

<cfx_lucene
  query=”r_query”
  indexName=”C:\hosts\cephas.net\wwwroot\blog\index”
  startIndex=”1″
  maxPage=”10″
  queryString=”java”>

The above script presumes that you have a Lucene index already created in the directory ‘C:\hosts\cephas.net\wwwroot\blog\index’, is looking for the keyword ‘java’, and will return a ColdFusion query object to the template with the columns ‘title’, ‘url’, and ’summary’.

To see the results, you can dump the CFDUMP tag:

<cfdump var=”#r_query#”>

Caveat: It’s 1:42amEST so I’ve done no testing on it and it has no interface (like I’m sure Lindex does). Use at your own risk. If you do use it, please keep my name/email in the source somewhere and remember to thank Joe for the idea. Enjoy!


3 Comments

Posted by
Joe Cheng
24 April 2003 @ 4pm

Sweet!!

Any plans for a custom tag for indexing? If you don’t, I will. :)


Posted by
Christian Cantrell
20 May 2003 @ 8pm

You might want to take a look at the Lindex (Lucene + index) project on the Macromedia DRK 3:

http://www.macromedia.com/software/drk/productinfo/product_overview/volume3/

It’s a ColdFusion wrapper around the Apache Jakarta Lindex project. Very cool.

Christian


Posted by
vishnu
31 May 2005 @ 7am

i followed the steops u mentiond , but i am getting this error

500 com/allaire/cfx/CustomTag
com/allaire/cfx/CustomTag


Leave a Comment

Biological Computing How Java Web Servers Work