Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('memory_limit', '-1');
- function doSearch(){
- $host = 'localhost';
- $db = 'webcrawler';
- $user = 'webcrawler';
- $pass = 'secret';
- $charset = 'utf8';
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $pdo = new PDO($dsn, $user, $pass);
- $sql = 'SELECT * FROM document
- WHERE MATCH (`text`, subject, title, description, creator, publisher)
- AGAINST (:search IN NATURAL LANGUAGE MODE);';
- $search = isset($_GET['search']) ? $_GET['search'] : '';
- if (empty($search)){
- echo "Please enter a search phrase.<br/>";
- return;
- }
- $stmt = $pdo->prepare($sql);
- $stmt->execute(['search' => $search]);
- $rowsAffected = $stmt->rowCount();
- echo "<em>Found $rowsAffected records matching search for '$search'.</em><br/>";
- if ($rowsAffected > 10) {
- echo "<em>Showing first 10 results...</em><br/>";
- }
- $counter = 1;
- while($doc = $stmt->fetch(PDO::FETCH_OBJ)) {
- echo "URL: $doc->url Content-Type: $doc->content_type Crawled Date: $doc->crawl_date<br/>";
- $counter++;
- if ($counter==10) break;
- }
- }
- ?>
- <?php doSearch(); ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment