Lucene troubles...

122 views
Skip to first unread message

flashbry

unread,
Jan 21, 2010, 10:04:10 AM1/21/10
to Railo
Is anyone having any luck accessing the Lucene API from Railo?

I'm trying to create a Lucene index via Railo (cfindex doesn't seem
flexible enough for what I need - or perhaps I just don't know how to
use it correctly) and am getting a 'no matching constructor' error.

My code is as follows (and was working fine in a JSP page but doesn't
seem to want to play under Railo):

[code above this to query database into qData, create
StandardAnalyzer, IndexWriter - all working fine]

<cfset vField=CreateObject("java","org.apache.lucene.document.Field")>

<cfloop query="qData">

<!--- create the document [works OK] --->

<cfset vDoc=CreateObject
("java","org.apache.lucene.document.Document")>

<!--- add fields to document [fails with 'No matching
constructor' no matter what I use] --- >

<cfset vDoc.add(vField.Text("id", qData.id))>


Where qData is a database query returning the id column from a
database table (it is returning other columns too but as it won't even
insert one field I haven't shown the others in the code above).

I have also tried

<cfset vDoc.add(vField.Text("id", "test"))>

<cfset vDoc.add(vField("id", qData.id, vField.Store.YES,
vField.Index.NO)> [this is the one that works in JSP]

Has anyone else come across this problem?

Any ideas?

Cheers
Bry

AJ Mercer

unread,
Jan 21, 2010, 10:20:52 AM1/21/10
to ra...@googlegroups.com
With CFML there are two tags to handle the search collections - cfindex and cfsearch

check out
   http://wiki.getrailo.org/wiki/3-1-Tags:CFIndex



2010/1/21 flashbry <lewist...@googlemail.com>



--
AJ Mercer
http://webonix.net
http://twitter.com/webonix

Hendrik Kramer

unread,
Jan 21, 2010, 11:43:44 AM1/21/10
to Railo
CFML handles the static subclasses a bit differently. This idea is
borrowed from Raymond Camden, but gives you an idea. Please note that
this is an part of our search component and things like
variables.storeConfig.getProperty and searchField.getName() are not
documented here.

<cfset analyzer = createObject("java",
variables.storeConfig.getProperty("analyzerClass")).init()/>
<cfset iwriter = createObject("java",
"org.apache.lucene.index.IndexWriter").init
(variables.storeConfig.getProperty("indexStore"), analyzer, javaCast
("boolean", arguments.replaceIndex))/>

<cfset FieldStore = createObject("java",
"org.apache.lucene.document.Field$Store")>
<cfset FieldIndex = createObject("java",
"org.apache.lucene.document.Field$Index")>

<cfloop from="1" to="#arguments.data.recordCount#" index="i">
<cfset doc = createObject("java",
"org.apache.lucene.document.Document").init()/>
<cfset field = createObject("java",
"org.apache.lucene.document.Field")>

<cfif searchField.getIndexMethod() eq "keyword">
<cfset field.init(searchField.getName(), javaCast
(searchField.getJavaType(), searchData), FieldStore.YES,
FieldIndex.UN_TOKENIZED )>
<cfelseif searchField.getIndexMethod() eq "unindexed">
<cfset field.init(searchField.getName(), javaCast
(searchField.getJavaType(), searchData), FieldStore.YES,
FieldIndex.NO )>
<cfelseif searchField.getIndexMethod() eq "unstored">
<cfset field.init(searchField.getName(), javaCast
(searchField.getJavaType(), searchData), FieldStore.NO,
FieldIndex.TOKENIZED )>
<cfelseif searchField.getIndexMethod() eq "text">
<cfset field.init(searchField.getName(), javaCast
(searchField.getJavaType(), searchData), FieldStore.YES,
FieldIndex.TOKENIZED )>
</cfif>

<cfset doc.add(field)>

</cfloop>
<cfset iwriter.addDocument(doc)/>
<cfset documentsAdded = documentsAdded + 1/>
</cfloop>
<cfset iwriter.optimize()>
<cfset iwriter.close()/>

On 21 Jan., 16:20, AJ Mercer <ajmer...@gmail.com> wrote:
> With CFML there are two tags to handle the search collections - cfindex and
> cfsearch
>
> check out
>    http://wiki.getrailo.org/wiki/3-1-Tags:CFIndex
>

> 2010/1/21 flashbry <lewisthebo...@googlemail.com>

flashbry

unread,
Jan 21, 2010, 10:43:07 AM1/21/10
to Railo
Thanks.

I've had a go with cfindex and cfsearch and while they are great for
simple search collections (a la verity), they do not seem to offer
enough flexibility for the kinds of indexes I am required to build.

Each of the indexes I need to build may need to have upto 10 fields
and searches will need to be performed on any of those fields
(preferably with the field name specified in the search criteria e.g
'ID:1 and NAME:Bryan') which is why I was trying to access the Lucene
API directly.

Looks like I may just have to go back to JSP for it unless anyone has
any other ideas?
Using a database instead of creating a large index is not an option,
sadly.

Cheers
Bry.


On Jan 21, 3:20 pm, AJ Mercer <ajmer...@gmail.com> wrote:
> With CFML there are two tags to handle the search collections - cfindex and
> cfsearch
>
> check out
>    http://wiki.getrailo.org/wiki/3-1-Tags:CFIndex
>

> 2010/1/21 flashbry <lewisthebo...@googlemail.com>

flashbry

unread,
Jan 21, 2010, 12:16:53 PM1/21/10
to Railo
Hi Hendrik,

That works perfectly.

Thank you so much, you've saved me ripping all my hair out :0)

Cheers
Bry.

Reply all
Reply to author
Forward
0 new messages