0

私は一種のビデオ アーカイブ wfsu.org/dimensions に取り組んでおり、mysql と php を使用して、関連するビデオの適切なクエリとアルゴリズムの組み合わせを考え出そうとしています。データベースには、タイトル、キーワード、説明、カテゴリ、およびプロデューサー用の別の正規化された 1:m テーブルがあります。私は単純なアルゴリズムを持っていますが、機知に富んだ人なら誰でもそれを見ると、「関連する」ビデオのセットが非常に貧弱であることがわかります。アイデアや助けをいただければ幸いです!!

リクエストごとに、私が使用している単純なアルゴリズムは次のとおりです。

//if the segment isnt a generic dimensions use this query that makes sure they're in the same category
if($segType != 2)
{
    $query = "SELECT `title`, `description`, `air_date`, `keywords`, `post_id`, `img_filename`     
    FROM `archive_post` 
    WHERE `segment_type` = $segType 
    AND `post_id` != $id 
    AND NOW() > ADDTIME(`air_date`, '20:0:0') 
    ORDER BY `air_date` DESC LIMIT 5";
}
else //otherwise we want a query that checks to see if there are any similar keywords
{
    $query = "SELECT `title`, `description`, `air_date`, `keywords`, `post_id`, `img_filename` 
    FROM `archive_post` 
    WHERE (";
            $kwArray = preg_split("/[\s,-]+/", mysql_real_escape_string($keywords));

            foreach($kwArray as $kw)
            {
                $query .= "`keywords` LIKE '%$kw%' OR";
    }
    $query = substr($query, 0, -3);
    $query .=  ")
    AND `post_id` != $id 
    AND NOW() > ADDTIME(`air_date`, '20:0:0') 
    ORDER BY `air_date` DESC LIMIT 5";
}

$result = $dbConnection->runQuery($query);
if(mysql_num_rows($result) == 0) //if we can't find any 'related' videos what do?
{

}
else
{
    while($row = mysql_fetch_array($result))
    {
            $moreTitle = $row['title'];
    $moreID = $row['post_id'];
            $moreDescription = cleanDescription($row['description']);
            $moreDescription = substr($moreDescription, 0, 50).'...';
            $moreDate = strtotime( $row['air_date'], time() );  
            $moreDate = date( "F j, Y" , $moreDate );

            $relatedVideos .= "<li> <a href='viewvideo.php?num=$moreID'></a><h3>$moreTitle</h3>
                        <div class='featuredStory'><span class='featuredDate'>$moreDate</span> &sdot; $moreDescription</div></li>";
    }
}
4

1 に答える 1