2017 © Pedro Peláez
 

library search-parser

Search string parser for Laravel.

image

digitlab/search-parser

Search string parser for Laravel.

  • Friday, April 22, 2016
  • by digitlab
  • Repository
  • 1 Watchers
  • 2 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Search Parser

StyleCI Build Status Total Downloads Latest Stable Version License, (*1)

Parses Lucene/Google style search strings into PostgresSQL full text query string., (*2)

Installation

Install using composer:, (*3)

composer require digitlab/search-parser

Add the service provider in app/config/app.php:, (*4)

DigitLab\SearchParser\SearchParserServiceProvider::class,

Usage

Basic Usage

To just parse a full text query you can simply use SearchParser:, (*5)

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

will produce, (*6)

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

Filters

To handle filters you need to extend SearchParser and add a handle function or add a pass through filter:, (*7)

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, (*8)

[
    '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., (*9)

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, (*10)

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

License

Adaptive View is licensed under The MIT License (MIT)., (*11)

The Versions

22/04 2016

dev-master

9999999-dev http://digitlab.co.za

Search string parser for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Wiersma

laravel parser search

22/04 2016

v1.0.0

1.0.0.0 http://digitlab.co.za

Search string parser for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicholas Wiersma

laravel parser search