risototh/search-query-composer

Tokenizer and composer for search query from user input.

1.2.0 2023-05-05 18:20 UTC

This package is auto-updated.

Last update: 2024-05-05 20:35:23 UTC


README

This library is intended for use in cases, where you want to extend the search abilities of simple search input. It takes the input from user, and tries to interpret them as an expression. For example, user enters something like a AND NOT (b OR c) and this library will tokenize this input and construct the valid SQL statement fragment like

`field` LIKE '%a%'
AND NOT(
  `field` LIKE '%b%'
  OR
  `field` LIKE '%c%'
)

Features

  • PSR-4 autoloading compliant structure
  • Supports operators AND, OR, NOT
  • Supports subquery nesting
  • Easy to use

Use

Basic usage is very simple:

$userInput = 'a AND NOT (b OR c)';
$pdo = new \PDO('your pdo connection');
echo RisoToth\Database\SearchQuery::make($userInput, $pdo, '`field`');