如何索引sql数据库以使用Match Against查询

时间:2011-11-14 19:16:12

标签: mysql drupal phpmyadmin

我想在我的sql中使用Match Against查询来进行以下地理位置查询: -

SELECT location.lid, location_instance.uid, users.name
         , users.mail , location.latitude , location.longitude , users.picture, 
         ( 6371 * ACOS( COS( RADIANS($lat) ) * COS( RADIANS( location.latitude ) ) 
         * COS( RADIANS( location.longitude ) - RADIANS($lon) ) + SIN( RADIANS($lat) ) 
         * SIN( RADIANS( location.latitude ) ) ) ) AS distance
            from {location} LEFT JOIN {location_instance} ON location.lid = location_instance.lid 
            LEFT JOIN {users} ON location_instance.uid = users.uid WHERE MATCH (users.name) 
            AGAINST ('$search_term' IN BOOLEAN MODE) ORDER BY distance

但我想我最初必须在我的数据库中运行索引查询。请引导我一个网络人员

编辑:

1 个答案:

答案 0 :(得分:0)

添加全文索引的SQL: -

alter table users add fulltext index (name);

添加索引后: -

show index from users;

你应该看到类似的东西: -

       Table: users
  Non_unique: 1
    Key_name: name
Seq_in_index: 1
 Column_name: name
   Collation: NULL
 Cardinality: ????
    Sub_part: NULL
      Packed: NULL
        Null: 
  Index_type: FULLTEXT
     Comment: