TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Search text in database using Coldfusion (http://forums.techarena.in/software-development/1267359.htm)

ABDUL KAREEM 05-11-2009 12:22 PM

Search text in database using Coldfusion
 
I am developing a program that will search for multiple words in the database. My code should search for one word or if there is a perfect match of multiple words. i mean if i have database rows as
1. Flash Player
2. Adobe Flash Player
then the code displays both for the search "flash Player", but when i search for "Adobe Player" then too it should display the same result, which my program code does not do. Anyone help me please.

Zecho 05-11-2009 12:32 PM

Re: Search text in database using Coldfusion
 
Would like to see what actually your code looks like, and what data is it that yo are going to use and the result you are trying to get. Also did you try breaking the url.name into small pieces and then use LIKE to search for each piece.?


You don't explain enough about what the data looks like and the result you are trying to get. But couldn't you break the url.name into pieces based on spaces and then select LIKE for each piece?

ABDUL KAREEM 05-11-2009 12:38 PM

Re: Search text in database using Coldfusion
 
Here's what i did.
Code:

<cfparam name="URL.NAME" default="1" type="Any">
<cfquery name="search" datasource="datasource">
SELECT * FROM search WHERE NAME LIKE ="%#URL.NAME#%"ORDER BY DATE
</cfquery>

Still i am trying what you said, will post what i get.

kelfro 05-11-2009 12:53 PM

Re: Search text in database using Coldfusion
 
Code:


<cfparam name="searchStr" default=" ">
<cfparam name="newArrayList" default=" ">
<cfset newArrayList=ArrayNew(1)>
<cfif isdefined("form.searchItems") AND form.searchItems neq "">
        <cfset searchStr = #trim(form.searchItems)#>
        <cfset searchstr = #lcase(searchStr)#>
        <cfif searchstr contains " ">
                <cfset searchStr = Replace(searchStr," ",",")>
                <cfset newArrayList = ListToArray(searchstr)>
                <cfif newArrayList[1] neq "">
                        <cfset item1 = #newArrayList[1]#>
                </cfif>
                <cfif searchstr contains ",">
                        <cfset item2 = #newArrayList[2]#>
                </cfif>
        </cfif>
</cfif>

Try using this code, where i have broken it into two elements and then put them into an array. In case of any further assistance , please do post here.


All times are GMT +5.5. The time now is 06:47 PM.