public static function parseQuery($query, $pageSize = -1, $pageNum = 0) { global $DEBUG; /* OVERKILL? // We change this so that we keep a TREE of possible parses. $root = new ParseNode($query, 1.0, array(), array()); */ $query = trim($query); // first thing we do is see if this is a movie title: $movieList = \Query::byTitle($query); $resultsToUnion = self::getRelevanceByTitle($movieList, $query); // TODO test this // rest of the stuff we compose / intersect movie lists $movieListToFilter = array(); // QResult 's $constraints = array(); // Constraint 's # TODO commented out 'cuz I can't connect to rotten tomatoes # self::updateData($movieListToFilter, self::trySimilarMovies($query)); // -- we don't have a title; analyze for tokens $queryC = strtolower($query); // TODO could find names by capital letter maybe // $queryC = str_replace(" with ", " and ", $queryC); $queryC = str_replace(" but ", " and ", $queryC); // first turn emotions to genres (this should be done before cleaning) self::updateData($constraints, self::emotionsToGenres($queryC)); self::applyGenreAliases($queryC); $queryC = self::cleanQuery($queryC); $queryC = addslashes($queryC); self::updateData($constraints, Constraint::findDateRangeConstraints($queryC)); self::updateData($constraints, Constraint::findLengthConstraints($queryC)); self::updateData($constraints, Constraint::findFamilyConstraints($queryC)); self::updateData($constraints, Constraint::findGenreConstraints($queryC)); // TODO these two should be moved down for the more intense type of analysis. // self::updateData($constraints, Constraint::findDirectorConstraints($queryC)); // self::updateData($constraints, Constraint::findActorConstraints($queryC)); // clean some more again ? list($words, $tokenLim, $categories) = self::tokenize($queryC); $numWords = count($words); if ($DEBUG) { // we represent it as a string now echo "{$queryC}\n"; echo self::getStringRepOfCats($categories, $tokenLim, $numWords); echo "\nconstraints:\n"; foreach ($constraints as $const) { echo "- {$const->type}: " . $const->getSQLCondition() . "\n"; } } // now find continuous sections self::updateData($constraints, self::examineSections($words, $tokenLim, $categories)); $filteredResults = self::findMovieByConstraint($movieListToFilter, $constraints); // TODO changing type of filter $results = array_merge($resultsToUnion, $filteredResults); return self::getPage($results, $pageSize, $pageNum); }