digitlab/search-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

digitlab/search-parser

Composer 安装命令:

composer require digitlab/search-parser

包简介

Search string parser for Laravel.

README 文档

README

StyleCI Build Status Total Downloads Latest Stable Version License

Parses Lucene/Google style search strings into PostgresSQL full text query string.

Installation

Install using composer:

composer require digitlab/search-parser

Add the service provider in app/config/app.php:

DigitLab\SearchParser\SearchParserServiceProvider::class,

Usage

Basic Usage

To just parse a full text query you can simply use SearchParser:

$parser = new SearchParser();
$filters = $parser->parse('string to parse');

will produce

[
    'search' => 'string&to&parse'
]

Filters

To handle filters you need to extend SearchParser and add a handle function or add a pass through filter:

class CustomSearchParser extends SearchParser
{
    /**
     * The filters that should be returned without handlers.
     *
     * @var array
     */
    protected $passthruFilters = ['other'];

    /**
     * Handle the state filter.
     *
     * @param mixed $state
     * @return array
     */
    protected function handleState($state)
    {
        return ['some' => $state];
    }
}
$parser = new CustomSearchParser();
$filters = $parser->parse('state:pending other:string string to parse');

will produce

[
    'search' => 'string&to&parse',
    'some' => 'pending',
    'other' => 'string'
]

Custom Query Key

You can customise the array key of the query by overriding the $queryName variable in your custom class.

class CustomSearchParser extends SearchParser
{
    /**
     * The name of the query in the result array.
     *
     * @var string
     */
    protected $queryName = 'other';
}
$parser = new CustomSearchParser();
$filters = $parser->parse('string to parse');

will produce

[
    'other' => 'string&to&parse'
]

License

Adaptive View is licensed under The MIT License (MIT).

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固