Jump to content

Word Search


The Little Guy

Recommended Posts

Each member is allowed to post up to 40 words that describes them. I have a file that you pass a list of comma separated values, such as:

cool,cat,dog

 

this filters all the members that have those 3 words in their words list. The query I have to get those members works, but I think it is really slow since it uses having. Any thoughts on how to speed it up?

 

select *, count(*) c from words w left join users u on(w.owner = u.id) where w.word in('$filter') and u.id != $_id group by u.id having c >= $nwords limit 5

 

using the above words the query would look like this:

select *, count(*) c from words w left join users u on(w.owner = u.id) where w.word in('cool','cat','dog') and u.id != 4 group by u.id having c >= 3 limit 5

Link to comment
Share on other sites

What you could try instead is inner joining by user id a query for each word in the list.  The result set would only be the users who had all 3 words.. the logical equivalent of intersect of 3 seperate queries each for one of the 3 words.

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.