PHP and coreseek are combined to develop an efficient movie search engine
Introduction: Movie search engines play an important role in today's Internet era, providing users with fast and accurate search results. In this article, we will introduce how to use PHP and coreseek to develop an efficient movie search engine.
1. What is coreseek?
Coreseek is an open source full-text search engine tool, customized and optimized based on the Sphinx search engine. Sphinx search engine is a fast and efficient full-text search engine that is widely used in various fields.
2. Why choose PHP and coreseek?
PHP is an easy-to-learn, powerful programming language that is widely used in the field of web development. As an efficient full-text search engine tool, coreseek can be used with PHP to quickly build an efficient search engine.
3. Steps to build a movie search engine
/usr/local/coreseek/etc/
directory. CREATE DATABASE IF NOT EXISTS `movie_search`; USE `movie_search`; CREATE TABLE IF NOT EXISTS `movies` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, `director` VARCHAR(255) NOT NULL, `release_date` DATE NOT NULL, `rating` DECIMAL(3,1) NOT NULL, `description` TEXT NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `movies` (`title`, `director`, `release_date`, `rating`, `description`) VALUES ('The Shawshank Redemption', 'Frank Darabont', '1994-10-14', 9.3, 'The Shawshank Redemption is a 1994 American drama film.'), ('The Godfather', 'Francis Ford Coppola', '1972-03-24', 9.2, 'The Godfather is a 1972 American crime film.'), ('Pulp Fiction', 'Quentin Tarantino', '1994-05-21', 8.9, 'Pulp Fiction is a 1994 American crime film.');
sphinx.conf
and make the necessary configurations to Adapted to our movie search engine needs. The sample code for modifying the configuration items is as follows: source movies { type = mysql sql_host = localhost sql_user = your_mysql_username sql_pass = your_mysql_password sql_db = movie_search sql_sock = /var/run/mysqld/mysqld.sock sql_query = SELECT id, title, director, release_date, rating, description FROM movies } index movies { source = movies path = /usr/local/coreseek/data/movie_search docinfo = extern mlock = 1 mlock_retry = 5 morphology = stem_en, soundex_en min_word_len = 3 } searchd { listen = 9312 listen = 9306:mysql41 log = /var/log/coreseek/searchd.log query_log = /var/log/coreseek/query.log read_timeout = 5 max_children = 30 pid_file = /usr/local/coreseek/var/searchd.pid seamless_rotate = 1 preopen_indexes = 0 unlink_old = 1 workers = threads binlog_path = }
search.php
and copy and paste the following code into it: <?php require_once('sphinxapi.php'); $sphinx = new SphinxClient(); $sphinx->SetServer('localhost', 9312); $sphinx->SetMatchMode(SPH_MATCH_ALL); $query = isset($_GET['q']) ? $_GET['q'] : ''; $result = $sphinx->Query($query, 'movies'); if ($result === false) { echo "Error: " . $sphinx->GetLastError(); } else { if ($sphinx->GetTotalFound() > 0) { echo "Search results for: " . $query . "<br>"; foreach ($result['matches'] as $match) { echo "<div>"; echo "Title: " . $match['attrs']['title'] . "<br>"; echo "Director: " . $match['attrs']['director'] . "<br>"; echo "Release Date: " . $match['attrs']['release_date'] . "<br>"; echo "Rating: " . $match['attrs']['rating'] . "<br>"; echo "Description: " . $match['attrs']['description'] . "<br>"; echo "</div>"; } } else { echo "No results found for: " . $query; } } ?>
search.php
, pass the search keyword through the URL parameter q
to search. For example: http://localhost/search.php?q=The Shawshank Redemption
. Through the above steps, we successfully built a movie search engine based on PHP and coreseek. You can expand and optimize this search engine according to your own needs, such as adding more search conditions, increasing sorting functions, etc.
Conclusion:
In this article we introduced how to use PHP and coreseek to develop an efficient movie search engine. By using coreseek as a full-text search engine tool, combined with the PHP programming language, we can quickly build a powerful search engine. I hope this article can provide you with some help in developing a movie search engine.
The above is the detailed content of PHP and coreseek are combined to develop an efficient movie search engine. For more information, please follow other related articles on the PHP Chinese website!