Example #1
0
 public static function bySimilarity($movie)
 {
     $movies = array();
     if ($movie->similarLink != "") {
         $url = "{$movie->similarLink}?limit=5&apikey=y9ycwv778uspxkj6g4txme2h";
         $similar = json_decode(Utils::getWebData($url), true);
         foreach ($similar["movies"] as $sMovie) {
             $movies[] = Query::byTitle($sMovie["title"]);
         }
     }
     //var_dump($movies);
     return $movies;
 }
Example #2
0
 public static function trySimilarMovies(&$query)
 {
     $movieListToReturn = array();
     $pattern = '/(movies?)? like (.*)$/i';
     // the pattern we look for
     $queryCopy = substr($query, 0);
     // make a copy
     $matches = array();
     for (; strlen($queryCopy) > 0; $queryCopy = \Utils::removeLastWord($queryCopy)) {
         if (preg_match($pattern, $queryCopy, $matches) == 1) {
             // collect these movies, with relevances
             $likeTitles = \Query::byTitle($matches[2]);
             if (count($likeTitles) === 0) {
                 continue;
             }
             // not there may be multiple movies that matched... search through all
             $likeResults = self::getRelevanceByTitle($likeTitles, $matches[2]);
             foreach ($likeResults as $similarTo) {
                 // similarTo is (movie, relevance) pair
                 $simMovies = Query::bySimilarity($similarTo->movie);
                 // we use the same relevance for all similar movies
                 self::updateData($movieListToReturn, QResult::getResults($simMovies, $similarTo->relevance));
             }
             // also delete this section of the query
             //         -- this is ok here, since we already "continue'd" if this code does not apply
             $query = preg_replace($pattern, SEP, $query);
             break;
         }
     }
     return $movieListToReturn;
 }