mapado/simstring-bundle

此包已被废弃,不再维护。未建议替代包。

Mapado Simstring Bundle: 记录搜索

安装次数: 2,210

依赖项: 0

建议者: 0

安全性: 0

星标: 3

关注者: 14

分支: 2

公开问题: 0

类型:symfony-bundle

v1.1.1 2014-12-19 11:09 UTC

This package is auto-updated.

Last update: 2023-09-15 20:01:25 UTC


README

Mapado SimstringBundle : 用于simstring记录搜索的Symfony扩展包

安装

此扩展使用Simstring。您可以在mapado.com上找到我们如何使用它的描述在我们的博客上

您必须安装Simsting PHP扩展以使此包工作。

获取扩展包

在您的composer.json中添加以下内容

{
	"require": {
		"mapado/simstring-bundle": "1.*"
	}
}

然后运行

php composer.phar update

或者

composer update

如果您全局安装了composer。

将类添加到您的kernel

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Mapado\SimstringBundle\MapadoSimstringBundle(),
    );
}

配置

声明您的数据库

# app/config/config.yml
mapado_simstring:
    databases:
        city: "path/to/your/database/city.db"
        country: "path/to/your/database/country.db"

声明您的读取器

# app/config/config.yml
mapado_simstring:
    databases:
        city: "path/to/your/database/city.db"
        country: "path/to/your/database/country.db"
    reader:
        city_cosine:
            database: city
            measure: cosine # values are cosine/dice/jaccard/overlap/exact
            threshold: 0.7 # float between 0 and 1
            min_results: 1 # minimim number of results if you have a lower threshold limit
        # you can add as many reader you like

声明您的写入器

# app/config/config.yml
mapado_simstring:
    databases:
        city: "path/to/your/database/city.db"
        country: "path/to/your/database/country.db"
    reader:
        city:
            database: city
            measure: cosine # values are cosine/dice/jaccard/overlap/exact (default is: exact)
            threshold: 0.7 # float between 0 and 1
            min_results: 1 # minimim number of results if you have a lower threshold limit
        # you can add as many reader you like

    writer:
        city:
            database: city
            unicode: false # not required
            ngram: 3 # not required
            be: false # not required

与Doctrine ORM关联

SimstringBundle与Doctrine ORM兼容。您只需添加一些数据库设置即可从数据库中获取对象。

# app/config/config.yml
mapado_simstring:
    databases:
        city: 
            path: "path/to/your/database/city.db"
            persistence:
                driver: orm # only ORM is supported for the moment
                model: \Mapado\MyEntityBundle\Entity\City # required
                field: simstringColumn # required
                options: # optional
                    manager: geolocation # if not set, the default manager will be used
                    repository_method: findVisibleBy # findBy is used by default

用法

现在您可以在控制器中或通过命令行使用这些函数

命令行

# Perform the query
php app/console mapado:simstring:search city cihcago
# will output chicago

# Perform an insert
php app/console mapado:simstring:insert city chicago houson boston montréal
# will rewrite the database with this cities

控制器

// Perform the query
$resultList = $this->get('mapado.simstring.city_reader')->find('New Yrok');

// Dynamically change the threshold
$resultList = $this->get('mapado.simstring.city_reader')->find('New Yrok', 0.3);

$resultList将是一个具有字符串(或实体,如果您使用了ORM映射器)值的SimstringResult迭代器。