2017 © Pedro Peláez
 

library search-string-parser

A php based parser class for use in search logic.

image

floor9design/search-string-parser

A php based parser class for use in search logic.

  • Tuesday, August 2, 2016
  • by elb98rm
  • Repository
  • 3 Watchers
  • 2 Stars
  • 130 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

search-string-parser

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

A php based parser that will turn a string into an array of search terms for usage in search logic. ** This software is currently in a beta release: 0.9.3 **, (*2)

It is to be released on packagist.org., (*3)

Items left to look at:, (*4)

  • Finish ParserEn implementation - currently under development
  • Testing has been restored to 100% on files not being redeveloped
  • Documentation to be expanded to be more "ELI5"

This should be PSR-2, PSR-4 compliant, but as it's a beta there may be some problems., (*5)

Install

Via Composer, (*6)

``` bash composer require league/search-string-parser, (*7)


## Usage There are different engines Parsers available. You can easily choose which you want to use. Currently in this Beta version ParserSimple and ParserEn are included. Instantiate the wrapper using an object of the type of search you want: ``` php // Instantiate $ssp = new SearchStringParser(new ParserSimple); // run a search: $string = 'some search terms "including literals enclosed in quotes"'; $array = $ssp->parse($string);

This will give you the following results set:, (*8)

``` php array( 0 => 'including literals enclosed in quotes', 1 => 'some', 2 => 'search', 3 => 'terms' );, (*9)


Spaces are treated as "OR", with literals meaning "This string exactly" * hello world => hello OR world * "hello world" => hello AND [ space ] AND world Your search string can include a combination of the following items: * strings - eg: hello world * literal string - eg: "hello world" * int - eg: 1 * float - eg: -14.54 * array * multi-dimensional array These are all parsed internally to form an array ready for you to use as you see fit! Here is a more complex example: ``` php // Instantiate $ssp = new SearchStringParser(new ParserSimple); // run a search: $complex = array( 0 => 'hello world', 1 => 'foo', 2 => 'bar "literal string"', 3 => 3, 4 => -19.27 ); $array = $ssp->parse($complex);

This gives the following result: ``` php array( 0 => 'literal string', 1 => 'hello', 2 => 'world', 3 => 'foo', 4 => 'bar', 5 => '3', 6 => '-19.27' );, (*10)


You can also change the delimiter: ``` php // Instantiate $ssp = new SearchStringParser(new ParserSimple); // run a search: $string = 'some "search terms" Pincluding literals enclosed in another letterP'; $array = $ssp->parse($string);

This will give you the following results set:, (*11)

``` php array( 0 => 'including literals enclosed in another letter', 1 => 'some', 2 => '"search', 3 => 'terms"' );, (*12)


A practical use case; In Zend Framework you may need to set up a set of search terms: ``` php // we are in the middle of the code, and the object has already been instantiated as above: $string = 'some input text "including literals enclosed in quotes"'; $array = $ssp->parse($string); // ... I'll now skip to the relevant part of zend - I assume you can write a query: foreach($array as $keyword) { $select->orWhere('data_table LIKE ?', "%$keyword%") } ``` Obviously, this is just a push in the right direction, though similar things can be done in almost all frameworks (as well as in raw SQL). ## Testing Ensure that you have run composer scripts to generate vendor/autoload.php Run the following in command line at the project root: ``` bash $ phpunit --bootstrap vendor/autoload.php tests/

Credits

License

GNU GENERAL PUBLIC LICENSE. Please see License File for more information., (*13)

The Versions

02/08 2016

dev-master

9999999-dev https://github.com/elb98rm/search-string-parser

A php based parser class for use in search logic.

  Sources   Download

GNU GENERAL

The Requires

  • php >=5.4

 

The Development Requires

parser search string

02/08 2016

dev-development

dev-development https://github.com/elb98rm/search-string-parser

A php based parser class for use in search logic.

  Sources   Download

GNU GENERAL

The Requires

  • php >=5.4

 

The Development Requires

parser search string

05/01 2015

0.9.1

0.9.1.0 https://github.com/elb98rm/:search-string-parser

A php based parser class for usage in search logic

  Sources   Download

GNU GENERAL

The Requires

  • php >=5.3.0

 

The Development Requires

parser search league package

05/01 2015

0.9.0

0.9.0.0 https://github.com/elb98rm/:search-string-parser

A php based parser class for usage in search logic

  Sources   Download

GNU GENERAL

The Requires

  • php >=5.3.0

 

The Development Requires

parser search league package