does anyone know how to write search engine? I wrote like <b>"where name like '%#typeinname#%' " </b><br>if i search for <b>dallas</b>, i can find out <b>dallas - houston</b>.<br>but search for <b>dallas houston</b>, i can't find out <b>dallas - houston</b>.
>> but search for dallas houston, i can't find out dallas - houston.<br><br>This is because your code says to find the search term within a record, so a search for 'dallas houston' will overlook 'dallas - houston' because the search term is not contained within it.<br><br>Your search code looks quite simple and that is why I recommend a novice ColdFusion developer taking this approach:<br><br>Make a selection box (called Letter) containing every letter in the alphabet (or the first letter of each record). On submit, have the form process through a CF file with the following CFQUERY:<br><br><CFQUERY DATASOURCE="YOURDSN" NAME="search"><br>WHERE name LIKE '#Form.Letter#%'<br></CFQUERY><br><br>
doesn't work out.<br>my query is like:<br><cfquery name="searchengine" datasource="content"><br>select name <br>from tablename<br>where name like '%#form.nametypedin#%' or name like '%#form.nametypedin#' or name like '#form.nametypedin#%' <br></cfquery><br><br>it contains what you mentioned, but I still can't get <b>dallas - houston</b>, if searching by <b>dallas houston </b><br><br>
You missed what I said. The code required to write a search engine is more complex than that. You need to incorporate other conditions within your SQL statement in order for it to work.<br><br>That is why I suggest you have people select the first letter of the search term from a selection box. Therefore, when someone selects 'D' the result is all records beginning with the letter 'D' regarless of what comes after it.<br><br>If you insist on using your search, you would have to build something that treats each term seperately instead of as a phrase. The best way to do that is to create two input boxes (one for each search term) and create a conditional SQL statement depending on whether the second one contains text or not. If it does contain text, the SQL statement will read:<br><br>WHERE name LIKE'%#form.nametypedin1#%' AND name LIKE '%#form.nametypedin2#%'<br><br>If it doesn't, the SQL statement will read:<br><br>WHERE name LIKE'%#form.nametypedin1#%'
Why not use the verity program CF comes with and just index everything? Why write a search engine when CF comes with a perfectly good search engine built in?<br><br>If you really want to use a sql statement, you could try something like...<br><FONT FACE=monospace><br>WHERE name like '%#ListChangeDelims(form.nametypedin, "%' or name like '%" , " "#%'</font><br>(there's a space between that last two double quotes)<br>
If you want to include all the words, change the WHERE clause to:<br><br>WHERE name like '%#ListChangeDelims(form.nametypedin, "%' <b>and</b> name like '%" , " "#%'<br><br>the or in the above will give results based on matching any word you give it...<br><br>Let me know if this works for you....<br><br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.