tyv Posted February 29, 2008 Share Posted February 29, 2008 Hi, My website's search function looks up entire phrases instead of individual words. For example, if I query "Google Groups," I would like my search to come up with everything in my database that has the words "Google" and "Groups," not just the phrase "Google Groups." I would want my search to bring back "Google-tastic Search" or "Group Compu-Google." Right now it only brings back "Google Groups #1," "Google Group #2," etc. I'm at a loss at how to begin implementing this change. Any suggestions/scripts? I'm working with ASP files, Javascript and HTML. My database is managed with SQL. Thanks in advance for any help. tyv Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2008 Share Posted March 4, 2008 Break up the search phrase on spaces and search for each individual word. In Javascript you break up a string using string.split. words = phrase.split(" "); Then you would build the beginning of the SQL query and loop through the array of words using OR to add each word to the query. sql = "SELECT * FROM table WHERE ";where = "";for (i = 0; i < words.length; i++){ if (where != "") where += " OR "; where += "field LIKE '%" + words[i] + "%'";}sql += where; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.