easy-mysqli-fulltext
easy-mysqli-fulltext copied to clipboard
An easy-to-use Library to perform ranked MYSQLi fulltext searches
EasyMysqliFulltext
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! :-)