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 - adding code to perform geo distance search


  1. 1. Modify /path/to/webroot/properties/geo_search.php and add the following (highlighted) code:

    <?php
    /**
    * File: /path/to/webroot/properties/geo_search.php
    */
    include('init.php');
    // Get the data from form (if submitted)
    $latitude = !empty($_POST['latitude']) ? $_POST['latitude'] : '';
    $longitude = !empty($_POST['longitude']) ? $_POST['longitude'] : '';
    $radius = !empty($_POST['radius']) ? $_POST['radius'] : 5;
    // If we have coordinates then perform the search
    if (!empty($latitude) && !empty($longitude)) {
    // Include the api class
    require_once('sphinxapi.php');
    $client = new SphinxClient();
    // Set search options
    $client->SetServer('localhost', 9312);
    $client->SetConnectTimeout(1);
    $client->SetArrayResult(true);
    // Set the mode to SPH_MATCH_FULLSCAN
    $client->SetMatchMode(SPH_MATCH_FULLSCAN);
    // Convert the latitude and longitude to radians
    $lat = $latitude * (M_PI / 180);
    $lon = $longitude * (M_PI / 180)...