mapado / simstring-bundle
此包已被废弃,不再维护。未建议替代包。
Mapado Simstring Bundle: 记录搜索
v1.1.1
2014-12-19 11:09 UTC
Requires
- php: >=5.3.3
- symfony/config: ~2.3
- symfony/console: ~2.3
- symfony/dependency-injection: ~2.3
- symfony/framework-bundle: ~2.3
- symfony/http-kernel: ~2.3
Requires (Dev)
- atoum/atoum: dev-master@dev
- raulfraile/ladybug-bundle: ~0.7
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
迭代器。