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 - filtering the result set


  1. 1. Create a PHP script search_filter.php in your webroot containing 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();
    $client->SetServer('localhost', 9312);
    $client->SetConnectTimeout(1);
    $client->SetArrayResult(true);
    $client->SetMatchMode(SPH_MATCH_ANY);
    // Returns all documents which match "programming games electronics"
    display_results(
    $client->Query('programming games electronics'),
    'all posts matching "programming games electronics"');
    // Filter by ID
    $client->SetIDRange(1, 4);
    // Same as above but with ID based filtering
    display_results(
    $client->Query('programming games electronics'),
    'above query with ID based filtering');
    // Reset the ID based filter
    $client->SetIDRange(0, 0);
    // Filter the posts by author's Aditya Mooley and Dr.Tarique Sani
    $client...