alexschwarz89 / easy-mysqli-fulltext
An easy-to-use Library to perform ranked MYSQLi fulltext searches
2.0.0
2018-09-21 11:18 UTC
Requires
- php: >=7.1
- ext-mysqli: *
- aura/sqlquery: 2.7.1
- vlucas/phpdotenv: ^2.0
This package is not auto-updated.
Last update: 2024-11-09 17:38:40 UTC
README
An easy-to-use Library to perform ranked fulltext searches with MYSQLi.
Install
Install via composer:
{ "require": { "alexschwarz89/EasyMysqliFulltext": "2.0.0" } }
Run composer install
.
Getting Started
You will find a example file in examples/index.php to use with the included testdata.sql.
Set up search on a existing MYSQLi connection
use \Alexschwarz89\EasyMysqliFulltext\Search; $search = new Search( $mysqliInstance );
Simply searching for "example" in our testdata
$query = new SearchQuery($search); $query->setTable('testdata') ->setSearchFields('description') ->mustInclude('example'); $search->setSearchQuery( $query ); try { $search->execute(); } catch (EmptySearchTermException $e) { // Handle invalid search terms }
You can also
Use Search without an existing MYSQLi connection
$search = Search::createWithMYSQLi('localhost', 'username', 'password', 'dbname');
You can also pass the connection variables via Environment Variable (.env) and just Use
$search = Search::createWithMYSQLi();
.env file saved in your root directory
DATABASE_HOST=localhost
DATABASE_USERNAME=username
DATABASE_PASSWORD=password
DATABASE_NAME=database_name
Build more complex search queries
$query->setTable('testdata') ->setSearchFields('description,title,isbn,author') ->mustInclude('example') ->canInclude('another') ->exclude('again') ->preferWithout('this') ->orderBy('some_field', 'ASC');
Contributing is surely allowed! :-)