Coldfusion search multiple words.

Reply

Join Date: Apr 2009
Posts: 7
Reputation: pirula is an unknown quantity at this point 
Solved Threads: 0
pirula pirula is offline Offline
Newbie Poster

Coldfusion search multiple words.

 
0
  #1
May 22nd, 2009
Hi,

I would like to search one field in database with multiple words. Also i will allow searches for example : a or cs....(one,two characters).
My code:

  1. <cfparam name="URL.NAME" default="1" type="Any">
  2. <cfquery name="search" datasource="datasource">
  3. SELECT *
  4. FROM search
  5. WHERE NAME LIKE ="%#URL.NAME#%"
  6. ORDER BY DATE DESC
  7. </cfquery>

this code works fine but only with one word or if there is exact match with multiple words.
Example:
database rows:
1.adobe photohop
2.adobe photoshop cs4

search string adobe(my code) will display both results,but
search string adobe cs4 will not display results. I want if user type one,two, three words to match any of these words and to display all results like google.
What am I doing wrong? I also tried to replace characters and add + but no results.
Any idea or example i would appreciate.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 3
Reputation: gdmprog1 is an unknown quantity at this point 
Solved Threads: 0
gdmprog1 gdmprog1 is offline Offline
Newbie Poster

Re: Coldfusion search multiple words.

 
0
  #2
May 27th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: pirula is an unknown quantity at this point 
Solved Threads: 0
pirula pirula is offline Offline
Newbie Poster

Re: Coldfusion search multiple words.

 
0
  #3
May 27th, 2009
i was tired to think when i posted question. You can use and i am using cfif and cfloop tags in cfqueries. Just loop url.name, that is simple explanation and for advanced one you will need a couple of cfif,cfset and cfloop's in cfqueries.
Last edited by pirula; May 27th, 2009 at 11:23 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 8
Reputation: kg_ally is an unknown quantity at this point 
Solved Threads: 0
kg_ally kg_ally is offline Offline
Newbie Poster
 
0
  #4
Oct 30th, 2009
you have to break your input into 2 elements separated by a delimiter(I did it with a space) and put them into an array

  1. <cfparam name="strSearch" default="">
  2. <cfparam name="myArrayList" default="">
  3. <cfset myArrayList=ArrayNew(1)>
  4.  
  5. <cfif isdefined("form.searchMeals") AND form.searchMeals neq "">
  6. <cfset strSearch = #trim(form.searchMeals)#>
  7. <cfset strSearch = #lcase(strSearch)#>
  8. <cfif strSearch contains "">
  9. <cfset strSearch = Replace(strSearch," ",",")>
  10. <cfset myArrayList = ListToArray(strSearch)>
  11. <cfif myArrayList[1] neq "">
  12. <cfset element1 = #myArrayList[1]#>
  13. </cfif>
  14. <cfif strSearch contains ",">
  15. <cfset element2 = #myArrayList[2]#>
  16. </cfif>
  17. </cfif>
  18. </cfif>

now you can easily pass both or either one into your query.
Hope this helps.
Last edited by peter_budo; Oct 30th, 2009 at 7:17 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for ColdFusion
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC