PHP Recommendation Engine Code
This project is used by anyone who wants to implement recommendation f
Brought to you by:
svlzx
File | Date | Author | Commit |
---|---|---|---|
config.php | 2012-11-09 |
![]() |
[36066e] Initial commit |
functions.php | 2012-11-09 |
![]() |
[36066e] Initial commit |
index.php | 2012-11-09 |
![]() |
[36066e] Initial commit |
readme.txt | 2012-11-09 |
![]() |
[36066e] Initial commit |
recommendation.php | 2012-11-09 |
![]() |
[36066e] Initial commit |
test.sql | 2012-11-09 |
![]() |
[36066e] Initial commit |
words-en_US.php | 2012-11-09 |
![]() |
[36066e] Initial commit |
****************************************************************************** * OpenSource RECOMMENDATION ENGINE * Date: 22.10.2012 * Developer: Seval Unver sevalunver@gmail.com * * This project is used by anyone who wants to implement recommendation for his website content. * Actually this project is written for an upload site. Also user will see the recommended uploads * based on its title, description and tags. For example, if it is a video upload site, * users will see the related(recommended) videos next to a video. * Project is working on console, because we thought this script works periodically like * one time per day. So if you want to use it like a webservice, you can modify it easily. * The main sql algorithm is taken from Wordpress YARPP. * ****************************************************************************** HOW TO RUN: 1. Create a database on mysql and import test.sql into that database. 2. Put 'recommendation' folder in your host. Open config.php --> Change your database configurations. Default values: DB_SERVER:localhost DB_USERNAME:root DB_PASSWORD:1234 DB_DATABASE:test STORE_SESSIONS:mysql --> You can change weight of each parameter for recommodation algorithm. Default weights: - title keywords : 5 - description keywords : 3 - Tags : 2 --> Also you can determine a threshold for score of related videos. Default threshold: - threshold : 0 3. Open console and go to your folder. Here are example commands: $ php index.php -q all $ php index.php -q 1 $ php index.php -j 1 $ php index.php -h You can use these arguments: -q <upload_id> : to refresh cache for one upload. -q all : to refresh cache for all uploads. -j <upload id> : to get the json obj of recommendations. -h : to see the help ****************************************************************************** ADD SQL INTO DATABASE: CREATE TABLE IF NOT EXISTS `user_uploads` ( `upload_id` int(11) NOT NULL AUTO_INCREMENT, `def_title` VARCHAR(100) NOT NULL, `def_description` VARCHAR(400) NOT NULL, `def_tags` VARCHAR(400) NOT NULL, `deleted` int(11) NOT NULL DEFAULT '0', `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`upload_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ALTER TABLE `user_uploads` ADD FULLTEXT `def_title` ( `def_title` ); ALTER TABLE `user_uploads` ADD FULLTEXT `def_description` ( `def_description` ); ALTER TABLE `user_uploads` ADD FULLTEXT `def_tags` ( `def_tags` ); CREATE TABLE IF NOT EXISTS `recommendation_cache` ( `reference_id` int(11) NOT NULL, `upload_id` int(11) NOT NULL, `score` float(10,2) NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, KEY `reference_id` (`reference_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ****************************************************************************** RECOMMODATION ALGORITHM FOR user_uploads <--- Algorithm in example ---> SELECT 6 as reference_id, upload_id, ROUND(0 + (MATCH (def_description) AGAINST ('test soap opera hospital')) * 3.2 + (MATCH (def_title) AGAINST ('General ABC')) * 2.7 + (MATCH (def_tags) AGAINST ('capture')) * 1, 1) as score FROM user_uploads WHERE approval_state = 1 and deleted = 0 and upload_id != 6 group by upload_id having score >= 1 and upload_id != 0 order by score desc limit 5; <--- Example From Wordpress YARPP: ---> SELECT 4024 as reference_id, ID, ROUND(0 + (MATCH (post_content) AGAINST ('abshshhshshhs')) * 1 + (MATCH (post_title) AGAINST ('halloween')) * 1 + count(distinct if( terms.term_taxonomy_id in (598,447), terms.term_taxonomy_id, null)) *1 + count(distinct if( terms.term_taxonomy_id in (649,47,808,861,824), terms.term_taxonomy_id, null )) * 1,1 ) as score FROM wp_posts left join wp_term_relationships as terms on ( terms.object_id - wp_posts.ID ) WHERE post_status in ( 'publish', 'static') and ID != '4024' and post_date <- '2010-10-29 16:22:51' and post_password - '' and post_type - 'post' group by ID having score >- 5.00 and bit_or(terms.term_taxonomy_id in (601)) - 0 order by score desc limit 5 *****************************************************************************