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 - searching using Boolean query syntax


  1. 1. Create a PHP script search_boolean_mode.php in your webroot with the following code:

    <?php
    // Include the api class
    require_once('sphinxapi.php');
    // Include the file which contains the function to display results
    require_once('display_results.php');
    $client = new SphinxClient();
    // Set search options
    $client->SetServer('localhost', 9312);
    $client->SetConnectTimeout(1);
    $client->SetArrayResult(true);
    display_results(
    $client->Query('php programming'),
    '"php programming" (default mode)');
    // Set the mode to SPH_MATCH_BOOLEAN
    $client->SetMatchMode(SPH_MATCH_BOOLEAN);
    // Search using AND operator
    display_results(
    $client->Query('php & programming'),
    '"php & programming"');
    // Search using OR operator
    display_results(
    $client->Query('php | programming'),
    '"php | programming"');
    // Search using NOT operator
    display_results(
    $client->Query('php -programming'),
    '"php -programming"');
    // Search by grouping...