Sphinx PHP Geodist problems

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-05-27T18:07:04Z Indexed on 2010/05/27 18:11 UTC
Read the original article Hit count: 696

Filed under:
|
|
|
|

Below is my PHP function to call nearby points using Sphinx for MySQL. There are hundreds of thousands of nearby points which to what I can tell, are being indexed by Sphinx, but simply fails silently when searching with Sphinx. Other Sphinx queries I run against other indexes work completely fine.

function nearby($latitude, $longitude, $radius)
{
    global $sphinx;

    $sphinx->SetMatchMode(SPH_MATCH_ALL);
    $sphinx->SetArrayResult(true);
    $sphinx->SetLimits(0, 1000);
    $sphinx->SetGeoAnchor('latitude', 'longitude', (float) deg2rad($latitude), (float) deg2rad($longitude));
    $circle = (float) $radius * 1.609344;
    $sphinx->SetFilterFloatRange('@geodist', 0.0, $circle);

    $matches = $sphinx->Query('', 'geo');

    return $matches;
}

$nearby = nearby($latitude, $longitude, 10000);

var_dump($nearby);

This, when called with valid latitude and longitude co-ords and a very large radius for debugging produces:

bool(false)

Below is my sphinx.conf covering the geo part:

source geo
{
    type                    = mysql

    sql_host                = 127.0.0.1
    sql_user                = user
    sql_pass                = pass
    sql_db                  = db
    sql_port                = 3306

    sql_query_pre           = set names utf8
    sql_query_pre           = set session query_cache_type=OFF

    sql_query               = SELECT id,city,region,country,radians(longitude) AS longitude, radians(latitude) AS latitude FROM points;

    sql_attr_float          = longitude
    sql_attr_float          = latitude

    sql_ranged_throttle     = 0

    sql_query_info          = SELECT * FROM points WHERE id = $id
}

index geo
{
    source                  = geo
    path                    = /var/data/geo
    docinfo                 = extern
    #mlock                  = 0
    #morphology             = none
    min_word_len            = 1
    charset_type            = utf-8
    #charset_table          = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
    ignore_chars            = U+00AD
    html_strip              = 0
    enable_star             = 0
}

indexer
{
    mem_limit               = 1024M
}

searchd
{
    port                    = 3312
    log                     = /var/log/searchd.log
    query_log               = /var/log/query.log
    read_timeout            = 5
    max_children            = 5
    pid_file                = /var/log/searchd.pid
    max_matches             = 10000
    seamless_rotate         = 1
    preopen_indexes         = 0
    unlink_old              = 1
}

© Stack Overflow or respective owner

Related posts about php

Related posts about geolocation