即使有浮点数和弧度,Sphinx RT索引也会返回巨大的@geodist

时间:2011-04-20 11:41:08

标签: php indexing sphinx real-time

在广泛阅读了我在Sphinx论坛和本网站上发现的所有帖子后,我仍然感到困惑。我使用@geodist实现了地理搜索的实时索引。一切正常,但@geodist返回的是不可思议的大值。我能找到的唯一支持建议将度数转换为弧度并使用浮点数,但我已经做到了。请参阅下面的代码。

的sphinx.conf:

index rt_deals
{
                type = rt
                rt_mem_limit = 32M
                path = /var/lib/sphinx/rt_deals
                charset_type = sbcs
                charset_table = 0..9, A..Z->a..z, a..z, U+C5->U+E5, U+E5, U+C4->U+E4, U+E4, $

                rt_field = deal_types
                rt_attr_uint = venue_id
                rt_attr_float = venue_latitude
                rt_attr_float = venue_longitude
                rt_attr_timestamp = dt_start
                rt_attr_timestamp = dt_end
}

indexer
{
                mem_limit = 32M
}

searchd
{
                listen = 9312
                listen = 9306:mysql41
                log = /var/log/sphinx/searchd.log
                query_log = /var/log/sphinx/query.log
                read_timeout = 5
                max_children = 30
                pid_file = /var/run/sphinx/searchd.pid
                max_matches = 1000
                seamless_rotate = 1
                preopen_indexes = 0
                unlink_old = 1
                workers = threads # for RT to work
}

实时索引测试数据

INSERT INTO rt_deals (id,deal_types,venue_id,venue_latitude,venue_longitude) VALUES
(46,'b',41,0.7390897867826055,-1.2415384027937675), (45,'b
c',42,0.7387899148438626,-1.24255786085905);

PHP代码:

include('include/sphinxapi.php');

$_longitude = '42.358431';
$_latitude = '-71.059773';

$search = new SphinxClient();
$search->SetServer('[SERVER IP REMOVED]', 9312);
$search->SetConnectTimeout(1);
$search->SetArrayResult(true);
$search->SetMatchMode(SPH_MATCH_ALL);
$search->SetGeoAnchor('venue_latitude', 'venue_longitude', (float)deg2rad($_latitude),
(float)deg2rad($_longitude));
$search->SetSelect('*');
$search->SetLimits(0, 100);
$result = $search->Query('b', 'rt_deals');

# results, print_r($result):

Array
(
        [error] =>
        [warning] =>
        [status] => 0
        [fields] => Array
                (
                        [0] => deal_types
                )
        [attrs] => Array
                (
                        [venue_id] => 1
                        [venue_latitude] => 5
                        [venue_longitude] => 5
                        [dt_start] => 2
                        [dt_end] => 2
                        [@geodist] => 5
                )
        [matches] => Array
                (
                        [0] => Array
                                (
                                [id] => 45
                                [weight] => 1
                                [attrs] => Array
                                (
                                [venue_id] => 42
                                [venue_latitude] => 0.73878991603851
                                [venue_longitude] => -1.2425578832626
                                [dt_start] => 0
                                [dt_end] => 0
                                [@geodist] => 15278498
                                )
                                )
                        [1] => Array
                                (
                                [id] => 46
                                [weight] => 1
                                [attrs] => Array
                                (
                                [venue_id] => 41
                                [venue_latitude] => 0.73908978700638
                                [venue_longitude] => -1.2415384054184
                                [dt_start] => 0
                                [dt_end] => 0
                                [@geodist] => 15278115
                                )
                                )
                )
        [total] => 2
        [total_found] => 2
        [time] => 0.000
        [words] => Array
                (
                        [b] => Array
                                (
                                [docs] => 2
                                [hits] => 2
                                )
                )
)

我打算也使用SetFilterFloatRange,但只有在返回的数字有意义之后。 我希望我只是错过了什么,但我找不到任何遗漏的东西 文档。我感谢您给予的任何帮助!

1 个答案:

答案 0 :(得分:1)

我使用过这篇文章,在我玩乐时也帮助了我:

http://www.god-object.com/2009/10/20/geospatial-search-using-sphinx-search-and-php/

另外,[@geodist] => 15278115以米为单位表示