与mysql和php相关的视频

与mysql和php相关的视频,php,mysql,search,relation,Php,Mysql,Search,Relation,我正在研究一种视频存档,wfsu.org/dimensions,并试图为使用mysql和php的相关视频提供一个良好的查询/算法组合。该数据库包含标题、关键字、描述、类别和另一个用于生产者的标准化1:m表。我有一个简单的算法,但如果任何有智慧的人看到它,他们会发现它产生了一组非常糟糕的“相关”视频。任何想法或帮助都将不胜感激 根据请求,这里是我正在使用的简化算法: //if the segment isnt a generic dimensions use this query that mak

我正在研究一种视频存档,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>";
    }
}
//如果段不是通用维度,请使用此查询确保它们位于同一类别中
如果($segType!=2)
{
$query=“选择'title','description','air\u date','keywords','post\u id','img\u filename`”
从“存档”到“发布”
其中,`segment\u type`=$segType
和'post_id`!=$id
现在()>ADDTIME('air_date','20:0:0')
按“空运日期”说明限额5”订购;
}
else//否则,我们需要一个查询来检查是否存在任何类似的关键字
{
$query=“选择'title','description','air\u date','keywords','post\u id','img\u filename`”
从“存档”到“发布”
其中(“;
$kwArray=preg_split(“/[\s,-]+/”,mysql_real_escape_string($keywords));
foreach($kwArray作为$kw)
{
$query.=“`keywords`如“%$kw%”或“;
}
$query=substr($query,0,-3);
$query.=”)
和'post_id`!=$id
现在()>ADDTIME('air_date','20:0:0')
按“空运日期”说明限额5”订购;
}
$result=$dbConnection->runQuery($query);
if(mysql_num_rows($result)==0)//如果我们找不到任何“相关”视频,该怎么办?
{
}
其他的
{
while($row=mysql\u fetch\u数组($result))
{
$moretTitle=$row['title'];
$moreID=$row['post_id'];
$morescription=cleanscription($row['description']);
$morescription=substr($morescription,0,50)。“…”;
$moreDate=strottime($row['air_date',time());
$moreDate=日期(“F j,Y”,$moreDate);
$relatedVideos.=“
  • $moretTitle $moreDate&sdot;$moreDescription
  • ”; } }
    我将回答我的问题,这样任何处于类似困境的人都能得到面包屑。我研究了mysql的全文功能。首先,我发现它只用于myISAM,阅读后,我发现与当前的innodb相比,myISAM不太理想


    最后,我对我想要搜索的内容的3个关键部分的索引进行了全文查询,结果非常符合我的需要

    到目前为止你有什么代码?你尝试过什么?我在寻找更多的通用概念或想法,但我加入了一些代码来帮助你了解我正在做的事情。请看一下我的主要答案中包含的概念。这就是你将在书中看到的那种概念。很棒的阅读,我现在相当确定我在我的头上!我可能已经通过mysql全文和自然语言搜索功能找到了我自己问题的答案。如果我想出了一个解决方案,我一定会把它张贴给其他感兴趣的人。