Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search engine 1

Status
Not open for further replies.

achai

MIS
May 23, 2000
71
US
does anyone know how to write search engine? I wrote like <b>&quot;where name like '%#typeinname#%' &quot; </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>.
 
&gt;&gt; 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).&nbsp;&nbsp;On submit, have the form process through a CF file with the following CFQUERY:<br><br>&lt;CFQUERY DATASOURCE=&quot;YOURDSN&quot; NAME=&quot;search&quot;&gt;<br>WHERE name LIKE '#Form.Letter#%'<br>&lt;/CFQUERY&gt;<br><br>
 
doesn't work out.<br>my query is like:<br>&lt;cfquery name=&quot;searchengine&quot; datasource=&quot;content&quot;&gt;<br>select name <br>from tablename<br>where name like '%#form.nametypedin#%' or name like '%#form.nametypedin#' or name like '#form.nametypedin#%' <br>&lt;/cfquery&gt;<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.&nbsp;&nbsp;The code required to write a search engine is more complex than that.&nbsp;&nbsp;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.&nbsp;&nbsp;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.&nbsp;&nbsp;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.&nbsp;&nbsp;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?&nbsp;&nbsp;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, &quot;%' or name like '%&quot; , &quot; &quot;)#%'</font><br>(there's a space between that last two double quotes)<br>
 
it works great, but phoenix - dalla also is found out in result
 
If you want to include all the words, change the WHERE clause to:<br><br>WHERE name like '%#ListChangeDelims(form.nametypedin, &quot;%' <b>and</b> name like '%&quot; , &quot; &quot;)#%'<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>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top