Jump to content

Check for similar entries in DB


therealwesfoster

Recommended Posts

What is an efficient way to check a database for similar entries? For example:

 

One user posts "what is your favorite kind of dog?". So when user #2 comes along and posts "what is your most favorite breed of dog?", how can I alert user #2 of the similar entry already posted?

 

Digg has this feature as well when digging something. What's the most efficient way of doing this?

Link to comment
Share on other sites

Thanks for the reply :)

 

LIKE would be good, but how would I implement that? Replace the spaces with %? That wouldn't work too well. What's you idea?

 

based on your first post i would create i string parser which removes words like "in" "the" "a" etc from topic titles. then i wouls create queries like this:

select * from topic_table where title like '%$parsedString%' limit 10;

 

you obviously will not want to list all the possible rows, so i limited it to 10.

Link to comment
Share on other sites

here's what'd i do though.

 

1) explode() the query string into individual words.

2) remove common words like ("the," "what," "when," "is," "a," etc...) from your array using preg_match or eregi

3) build a query that will check through your table for questions that contain each word: LIKE '% $word %'

4) ta-da - show the results to the user.

Link to comment
Share on other sites

here's what'd i do though.

 

1) explode() the query string into individual words.

2) remove common words like ("the," "what," "when," "is," "a," etc...) from your array using preg_match or eregi

3) build a query that will check through your table for questions that contain each word: LIKE '% $word %'

4) ta-da - show the results to the user.

 

That's definitely a start (and the reason I originally posted this in the php section...). But that would also bring up questions like "how bad do you hate dogs?" and "dogs or cats?". So there are still a few more functions that need to take place, and this is the tricky part

Link to comment
Share on other sites

here's what'd i do though.

 

1) explode() the query string into individual words.

2) remove common words like ("the," "what," "when," "is," "a," etc...) from your array using preg_match or eregi

3) build a query that will check through your table for questions that contain each word: LIKE '% $word %'

4) ta-da - show the results to the user.

 

didnt i say that?

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.