Jump to content

Querying words instead of phrases


tyv
 Share

Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...