Name: neonwill Date: February 27, 2008 at 06:42:54 Pacific Subject: very strange search box OS: xp CPU/Ram: 1GB Model/Manufacturer: Dell
Comment:
hi everybody, here is the problem with my search box.(for example i have a product online name "lamp, hanging style, black" for me to search it i have to type in order to search it i can't type "black lamp" because its not gonna find it, but if i type "lamp, hang" then i can find it... any body know why? here is the code for that box
<script Language = "Javascript"> function submitMainsearch() {
/* if (document.Mainsearch.edtSearchWords.value.indexOf(" ") == 0) { alert("Search string should not start with spaces."); document.Mainsearch.edtSearchWords.focus(); return false; } if (document.Mainsearch.edtSearchWords.value.indexOf("\"") > -1 ) { alert("Please enter a valid Search String."); document.Mainsearch.edtSearchWords.focus(); return false; } if (document.Mainsearch.edtSearchWords.value == "") { alert("Please enter a Search String."); document.Mainsearch.edtSearchWords.focus(); return false; }
document.Mainsearch.submit(); return true; */
var strValue; strValue = new String(document.Mainsearch.edtSearchWords.value); var strLen = strValue.length;
if ((strValue == "")||(strValue==" ")) { alert("Please enter a Search String."); document.Mainsearch.edtSearchWords.focus(); return false; } if (document.Mainsearch.edtSearchWords.value.indexOf("\"") > -1 ) { alert("Please do not enter \" inside Search String."); document.Mainsearch.edtSearchWords.focus(); return false; } if(strValue.charAt(strLen-1)=="\\") { alert("Please do not end Search String with \\."); document.Mainsearch.edtSearchWords.focus(); return false; }
//*** Checking for all spaces - Starts here var AllSpaces = true; for (i = 0; i < strValue.length; i++) { if (strValue.charAt(i) != " " ) { AllSpaces = false; break; } } if (AllSpaces) { alert("Please enter a Search String."); document.Mainsearch.edtSearchWords.focus(); return false; } //*** Checking for all spaces - Ends here
Well, I'm not going to read through all of that code (please only post the relevant code), but the problem is pretty simple.
The EXACT string "black lamp" does not exist within "lamp, hanging style, black". But, "lamp, hang" does: "lamp, hanging style, black".
What you are after is called Full text searching where the search input is parsed into individual words and all the words are used for the search. This requires a database implementation. You'll have to find out the specifics for your environment.
how do i implementate a better searching option like other website, as i know of i am the only website having that problem. it make search more complicate for others
it not that i don't want to post the relevant code..but i have limited knowlege on these codes...that's why i post what i konw that might be the one which cost the problem on here..sorry for the trouble
Well, the code you posted doesn't do any of the actual searching and reading code that is not related to the problem is a waste of time. If you are not sure what code to post, just state you can post code as requested.
As to your problem I can not offer any definitive solution. I typically use PHP & MySQL. It looks like you are using VBScript? and I have no clue to the database you are using. But, full text searching (which is what you are asking for and which I have already stated) is mostly dependant on the database. You should do a google search for "Full Text Searching [DB_Name]" Where DB_Name is the name of the type of database you are using.
but i want them not to be in full text search, i want my customer search my whole website by entering either model number or part of the name(doesn't have to be in order)....not full text search
You are not understanding what Full Text Searching is.
Fine. On the page "searchresult.asp", or perhaps an included page, find the code that queries the database. Should be something along the lines of SELECT * FROM table name (just do a text search for the word select).
sorry for all the trouble but i really want it to work..here is the what i found in searchresult.asp i can not find what you are asking me to look for... and once again sorry for the trouble...thanx
<script language="JavaScript">
/* ### This function will be called when the user clicks prev , next or searchagain. ### bm = bookmark ### nav = prev or next depends on the navigation clicked by the user. ### type = itemtype of the last product diplayed in the current list. ### all these three parameters will be null if user clicks search again. */ function submitSearch(bm,nav,type) { document.frmSearch.BookMark.value =bm; document.frmSearch.prevnext.value = nav; document.frmSearch.itype.value = type; document.frmSearch.submit(); } function validateqty(txtQty,code,which,code1) { var element; var i,temp1,temp2; element = "document.frmSearch" + ".qty" + txtQty + ".value"; temp1 = eval(element); retval=IsNumeric(temp1); if(retval == 1){ alert("Enter valid quantity"); eval("document.frmSearch" + ".qty" + txtQty + ".value=1"); eval("document.frmSearch" + ".qty" + txtQty + ".focus()"); return; } <%If Application("bAutoAdd") Then%> //showAdd() if(navigator.appName == "Microsoft Internet Explorer") miniCart.document.location.replace("<%=g_NonSecurePath%>includes/minicart.asp?CartId=<%=CartId%>&qty=" + eval(element) + "&type=" + which + "&ic=" + code1 + "&tpc=<%=tpdata%>"); else document.miniCart.document.first.src="<%=g_NonSecurePath%>includes/minicart.asp?CartId=<%=CartId%>&qty=" + eval(element) + "&type=" + which + "&ic=" + code1 + "&tpc=<%=tpdata%>"; return; <%End if%> document.frmAdd.qty.value = eval(element); document.frmAdd.ic.value = code; if(which=="K") document.frmAdd.type.value = "kit"; document.frmAdd.submit(); }
// This is the function to show added msg in IE (only for Auto Addition) function showAdd() { if(showadd.style.visibility != "visible") { showadd.style.visibility = "visible"; showadd.style.top = bbody.scrollTop + 100; setTimeout("showAdd()",1000); } else showadd.style.visibility = "hidden"; }
function validatewishqty(txtQty,code,which) { var element; var i,temp1,temp2; element = "document.frmSearch" + ".qty" + txtQty + ".value"; temp1 = eval(element); retval=IsNumeric(temp1); if(retval == 1){ alert("Enter valid quantity"); eval("document.frmSearch" + ".qty" + txtQty + ".value=1"); eval("document.frmSearch" + ".qty" + txtQty + ".focus()"); return; } document.frmWish.Wqty.value = eval(element); document.frmWish.Wic.value = code; document.frmWish.submit(); } /*#### This uses regular expression for valid the entered parameter a valid numeric.*/ function IsNumeric(value) { var validate=/(^\d+$)/ if ((validate.test(value)) && (value > 0)) return 0; else return 1; } </script>
There are many tutorials available. you will want to find ones specific for your programming language and your particular database. Again, I have no idea what type of database you are using, so I can't provide any suggestions.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE