Jump to content

MySQL Search (using LIKE)


immanuelx2

Recommended Posts

Hey guys.

 

I am building a PHP/MySQL search feature that is quite simple. A user inputs keyword(s) and the MySQL finds the terms in a body of text.

 

However, if that body of text contains an URL (bbcode [ur=http://www.blahblahblah.com]Blah[/url]) it will actually search through the URL and return a part of that. Is there some way I can get the MySQL to ignore anything inside [] brackets?

 

Thanks in advance.

Link to comment
Share on other sites

Is your database ever going to be large?  Are you aware that when you do LIKE '%SOMETHING%' MySQL will table scan?  Using Regex functions to accomplish the same thing will also table scan.  It's just not a great approach for full text searching.  MySQL does have the Fulltext index type. 

 

My suggestion would be to use the fulltext index type, and as you fetch each row in the result:

 

1. Make a copy of the data column(s) variables, use preg_replace to remove any URL's from the copy of the data.

 

2.  Use strpos on the url eliminated data, and if you get a match on any of the words in the search phrase, return the row, otherwise exclude it.  If you do match, you want to return the original data, so that you don't improperly filter out url's.

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.