Jump to content

Querying words instead of phrases


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...