Jump to content

MySQL keyword frequency


jaoudestudios

Recommended Posts

Hi,

 

I hope someone can help.

 

I am doing a mysql search on 3 columns within a table, and I am ranking the returned result and ordering by the total relevance. However, I would like to add another count to the relevance if the keyword appears in the field more than once.

 

Below is a simplified version.

SELECT *, (

(CASE WHEN title LIKE '%the%' THEN 2 ELSE 0 END) +

(CASE WHEN content LIKE '%the%' THEN 1 ELSE 0 END)

) as relevance

FROM content WHERE (page LIKE '%the%' OR title LIKE '%the%' OR content LIKE '%the%')

ORDER BY relevance DESC

 

So if 'the' appears in the 'title' column and 'content' column the result will be 3. But if 'the' appears three times in the 'content' column it won't total 3 and then add it to the 2 from 'title' to equal 5. But I would like it to total 5.

 

Hope that makes sense.

Thanks,

Eddie

Link to comment
Share on other sites

I have created a simple stored procedure and I can get it to work on the command line, but I can not get it to work through php 5.

 

I have read many examples on how to call the stored procedure through php, but how do I set it? on the command line I use 'SOURCE procedure_file.sql' and it is ready to be called.

 

Please can you show me how to call the source file in php?

Link to comment
Share on other sites

how would I do that? through the sql textarea?

 

I would need to load the external script (procedure) and then call it.

 

Can I send the script in a query instead of loading it from a *.sql file.

Well, you only need to "load" it once... and since the stuff in the .sql file is SQL statements, yes.

Link to comment
Share on other sites

what about if the mysql has been restarted, will it keep the stored procedure? if not is there a way for the stored procedure to always auto load - maybe through the php?

It will not "go away" -- it is stored in the proc table of the mysql database.

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.