0
votes

I am developing a Flash Builder\ Flex Mobile application using ColdFusion. I need help to fix my search function. When I try to search for something, I must enter the exact word or it returns nothing.

enter image description here

If I type only "app", instead of "applet", it returns nothing.

Search function:

<cffunction name="getwordsSummaryByTerm" output="false" access="remote"  returntype="Query" > 
    <cfargument name="searchStr" type="string"  required="true" /> 
    <cfset var qItem=""> 
    <cfquery name="qItem" datasource="databaseyo">
        SELECT * 
       FROM words 
       WHERE term = <CFQUERYPARAM CFSQLTYPE="CF_SQL_VARCHAR" VALUE="#ARGUMENTS.searchStr#"> 
    </cfquery> 
     <cfreturn qItem> 
</cffunction> 

Flex code:

protected function doSearch(event:MouseEvent):void
{
    if(searchTerm.text!="")
    { 
        getAllwordsResult.token = wordsService.getwordsSummaryByTerm(searchTerm.text); 
    } 
    else
    { 
        getAllwordsResult.token = wordsService.getAllwords(); 
    } 
}
1
I think you mean "ColdFusion" not "cold fusion". The space was removed in version 3 to differentiate itself from "nuclear physics" in job postings. I can understand why recruiters can get it wrong; but as a programmer working in the technology you should be able to look up how it is spelled.JeffryHouser

1 Answers

5
votes

Try updating your query so it searches on a LIKE value and not a specific EQUALS value.

SELECT * 
FROM words 
WHERE term LIKE <CFQUERYPARAM CFSQLTYPE="CF_SQL_VARCHAR" VALUE="%#ARGUMENTS.searchStr#%">

Note the "%" that now wrap around the value in your query param.

If you want to set it up so what is being typed returns words that start the same way (ie typing for "app" returns "applet" and "apple", but not "dapple") then just remove the first "%" from the param value.