Package Data | |
---|---|
Maintainer Username: | digitlab |
Maintainer Contact: | nick@digitlab.co.za (Nicholas Wiersma) |
Package Create Date: | 2016-04-22 |
Package Last Update: | 2016-04-22 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:05:37 |
Package Statistics | |
---|---|
Total Downloads: | 13 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Parses Lucene/Google style search strings into PostgresSQL full text query string.
Install using composer:
composer require digitlab/search-parser
Add the service provider in app/config/app.php:
DigitLab\SearchParser\SearchParserServiceProvider::class,
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'
]
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'
]
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'
]
Adaptive View is licensed under The MIT License (MIT).