0
votes

Below is the code that does the index, and the cfsearch code that reads

The index:

<cfquery name="Qryname" datasource="dsnnane">
SELECT id, eid, title
FROM tbl1
</cfquery>

<cfindex  
    query="Qryname" 
    collection="events" 
    action="Update" 
    type="Custom" 
    title="title" 
    key="id" 
    body="eid,title">

Search Results

    <cfsearch   
    collection="events" 
    name="Qryname" 
    criteria="#Form.Criteria#"> 

    <!--- Output the record set. ---> 
    <cfoutput> 
    Your search returned #Qryname.RecordCount# result(s). 
    </cfoutput> 

    <cfoutput query="Qryname"> 
    <a href="page.cfm?eid=#eid#">#title#</a>

    </cfoutput>

The problem is that I can only output the column which I specified as the title in cfindex. If I try to output any other column other than that which I specified as the title, the system says that the var is undefined.

In this case it says that eid is undefined.

I see in the documentation that the column values can be output

Please see part 3 in "Search and display the query results", which is under "Indexing data returned by a query"

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7b35.html

Any ideas?

Thank you.

2

2 Answers

1
votes

I'd start by doing:

<cfdump var="#Qryname#" />

To see what is returned from the cfsearch.

1
votes

The solution is to use the custom fields in cfindex. If you read the ref for cfindex, you'll see that it supports up to 4 custom fields, ranging from custom1 to custom4.

Simply assign a db table column to one of the custom fields, re-index, then access that custom field in cfsearch

<cfindex  
    query="Qryname" 
    collection="events" 
    action="Update" 
    type="Custom" 
    title="title" 
    key="id" 
    body="eid,title"
    custom1="eid">

cfsearch:

<cfoutput query="Qryname"> 
<a href="page.cfm?eid=#custom1#">#title#</a>
</cfoutput>