School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,117 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,005 people online right now. Registration is fast and FREE... Join Now!




Coldfusion search multiple words.

 

Coldfusion search multiple words.

pirula

22 May, 2009 - 05:53 AM
Post #1

New D.I.C Head
*

Joined: 26 Apr, 2009
Posts: 20



Thanked: 1 times
My Contributions
Hi,

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

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 DESC
</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.






User is offlineProfile CardPM
+Quote Post


cfdvlpr

RE: Coldfusion Search Multiple Words.

23 May, 2009 - 08:27 AM
Post #2

New D.I.C Head
*

Joined: 9 May, 2007
Posts: 5


My Contributions
So, one way to do this would be to loop over the words in url.name and cfoutput code like this:

CODE
<cfoutput>
WHERE
1=1  

<cfloop index = "keyword"
   list = "#url.name#"
   delimiters = " ">
OR NAME LIKE "%#keyword#%"
</cfloop>

<cfoutput>

ORDER BY DATE DESC


User is offlineProfile CardPM
+Quote Post

pirula

RE: Coldfusion Search Multiple Words.

7 Jul, 2009 - 02:27 PM
Post #3

New D.I.C Head
*

Joined: 26 Apr, 2009
Posts: 20



Thanked: 1 times
My Contributions
Your example is not quite accurate! My code is working but :
CODE

WHERE 0=0
<cfif len (URL.name) gt 0>
       <cfloop index = "keyword"
        list = "#URL.NAME#"
        delimiters = " ">
        AND NAME LIKE "%#keyword#%"
        </cfloop>
      </cfif>


problem is that your code can not work with OR and my code works perfectly but again.
If for example you insert 1-2-3 or whatever words and if some field contains all that words or part of them everithing is ok, but if you insert two words and field in database does not contain one of them result will be empty.

How to modify this code to get 100% accurate result.

This post has been edited by pirula: 7 Jul, 2009 - 02:34 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:28PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month