Book Image

Sphinx Search Beginner's Guide

By : Abbas Ali
Book Image

Sphinx Search Beginner's Guide

By: Abbas Ali

Overview of this book

Table of Contents (15 chapters)
Sphinx Search
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Time for action - add attributes to schema


  1. 1. Modify /home/abbas/sphinx/makeindex.php file and make the changes as highlighted next:

    <?php
    // Database connection credentials
    $dsn ='mysql:dbname=myblog;host=localhost';
    $user = 'root';
    $pass = '';
    // Instantiate the PDO (PHP 5 specific) class
    try {
    $dbh = new PDO($dsn, $user, $pass);
    } catch (PDOException $e){
    echo'Connection failed: '.$e->getMessage();
    }
    // We will use PHP's inbuilt XMLWriter to create the xml structure
    $xmlwriter = new XMLWriter();
    $xmlwriter->openMemory();
    $xmlwriter->setIndent(true);
    $xmlwriter->startDocument('1.0', 'UTF-8');
    // Start the parent docset element
    $xmlwriter->startElement('sphinx:docset');
    // Start the element for schema definition
    $xmlwriter->startElement('sphinx:schema');
    // Start the element for title field
    $xmlwriter->startElement('sphinx:field');
    $xmlwriter->writeAttribute("name", "title");
    $xmlwriter->endElement(); //end field
    // Start the element for content field
    $xmlwriter...