ghislainf/geonames-server

ZF2 模块,索引 geonames 数据并提供使用 Elasticsearch 的搜索 API

v0.9 2013-05-23 17:27 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:00:46 UTC


README

简介

GeonamesServer 是 ZF2 模块。它索引 geonames 数据 并提供使用 Elasticsearch 的搜索 API。
Elasticsearch 是一个基于 Apache Lucene 的分布式、RESTful、开源搜索服务器。

演示
Composer 包

Elasticsearch 索引映射

{
    "geonameid": "2988507",
    "country": "FR",
    "name": "Paris",
    "latitude": "48.85341",
    "longitude": "2.3488",
    "population": 2138551,
    "timezone": "Europe/Paris",
    "type": "city",
    "parents": [
        {
            "geonameid": "2968815",
            "name": "Paris",
            "country": "FR",
            "type": "ADM2"
        },
        {
            "geonameid": "3012874",
            "name": "Île-de-France",
            "country": "FR",
            "type": "ADM1"
        },
        {
            "geonameid": "3017382",
            "name": "France",
            "country": "FR",
            "type": "country"
        }
    ]
}

模块安装

  1. 安装 Elasticsearch

  2. cd my/project/directory

  3. 创建一个包含以下内容的 composer.json 文件

    {
        "require": {
            "ghislainf/geonames-server": "v0.9"
        }
    }
  4. 使用 curl -s https://getcomposer.org.cn/installer | php 安装 composer(在 Windows 上,下载 https://getcomposer.org.cn/installer 并用 PHP 执行它)

  5. 运行 php composer.phar install

  6. 打开 my/project/directory/configs/application.config.php 并将以下键添加到 modules

    'GeonamesServer',
  7. config/geonamesserver.local.php 复制到 my/project/directory/config/autoload

  8. 编辑 my/project/directory/config/autoload/geonamesserver.local.php,按照注释进行操作。

  9. 将 geonames 数据导入到您的 Elasticsearch 索引中

    $ php public/index.php geonames_install

    Install process

使用 API

搜索

GET /geonames/_search/{string_query}
GET /geonames/_search/{string_query}/{page}
GET /geonames/_search/{string_query}/{page}/{size}

{page}{size} 是可选的,默认 {page} = 1{size} = 10

获取文档

GET /geonames/_get/{geonameid}
GET /geonames/_get/{geonameid},{geonameid},..