sspat/es-query-sanitizer
最新稳定版本:1.0.2
Composer 安装命令:
composer require sspat/es-query-sanitizer
包简介
Simple helper class to sanitize ElasticSearch reserved characters from query strings
README 文档
README
Inspired by node-elasticsearch-sanitize
Features
Accepts an arbitrary string as input and escapes the ElasticSearch reserved characters:
+ - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ / AND OR NOT space
Returns a sanitized string which can be safely used in an ElasticSearch query_string query.
Installation
The preferred way to install this extension is through composer.
Either run
composer require sspat/es-query-sanitizer
or add
"sspat/es-query-sanitizer": "~1.0"
to the require section of your composer.json file.
Usage
To use pass in a string:
$unescapedQueryString = 'AND there! are? (lots of) char*cters 2 ^escape!' $escapedQueryString = \sspat\ESQuerySanitizer\Sanitizer::escape($unescapedQueryString); echo $escapedQueryString; // \A\N\D\ there\!\ are\?\ \(lots\ of\)\ char\*cters\ 2\ \^escape\!
You can also pass an array as the second argument, if you want to prevent some characters from being escaped:
$unescapedQueryString = 'AND there! are? (lots of) char*cters 2 ^escape!' $excludeCharacters = ['!', '^']; $escapedQueryString = \sspat\ESQuerySanitizer\Sanitizer::escape($unescapedQueryString, $excludeCharacters); echo $escapedQueryString; // \A\N\D\ there!\ are\?\ \(lots\ of\)\ char\*cters\ 2\ ^escape!
统计信息
- 总下载量: 182.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-18