PHP code example of pimcore / search-query-parser
1. Go to this page and download the library: Download pimcore/search-query-parser library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pimcore / search-query-parser example snippets
t = 'doe AND 1212 AND !foo OR (!(am*ya AND 12) blah) OR baz'; // complex query
$input = '*john* !502* AND foobar'; // LIKE %john% AND NOT LIKE 502% AND = foobar
// tokenizes query string
$lexer = new \SearchQueryParser\Lexer();
// contains array of extracted tokens
$tokens = $lexer->lex($input);
dump($tokens);
// parses tokens into an abstract query
$parser = new \SearchQueryParser\Parser();
$query = $parser->parse($tokens);
dump($query);
// use the Zend_Db query builder to transform the Query into conditions
$db = new Zend_Db_Adapter_Pdo_Sqlite(array(
'dbname' => ':memory:'
));
// dummy query
$select = $db
->select()
->from('foo');
// build conditions for every passed field
$queryBuilder = new \SearchQueryParser\QueryBuilder\ZendDbSelect([
'foo',
'bar'
]);
$queryBuilder->processQuery($select, $query);
dump($select->__toString());
t = 'foo !bar *doe*';
// returns an abstract query
dump(\SearchQueryParser\SearchQueryParser::parseQuery($input));