/**
* Parse the fulltext search parameter q
*
* @param string $qParam
* @param array $fullTextSearchColumns
* @return void
*/
protected function parseFullTextSearch($qParam, $fullTextSearchColumns)
{
if ($qParam == '') {
//Add where that will never be true
$this->query->whereRaw('0 = 1');
return;
}
$fulltextType = Config::get('apihandler.fulltext');
if ($fulltextType == 'native') {
//Use pdo's quote method to be protected against sql-injections.
//The usual placeholders unfortunately don't seem to work using AGAINST().
$qParam = $this->query->getConnection()->getPdo()->quote($qParam);
//Use native fulltext search
$this->query->whereRaw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE)');
//Add the * to the selects because of the score column
if (count($this->query->columns) == 0) {
$this->query->addSelect('*');
}
//Add the score column
$scoreColumn = Config::get('apihandler.fulltext_score_column');
$this->query->addSelect($this->query->raw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE) as `' . $scoreColumn . '`'));
} else {
$keywords = explode(' ', $qParam);
//Use default php implementation
$this->query->where(function ($query) use($fullTextSearchColumns, $keywords) {
foreach ($fullTextSearchColumns as $column) {
foreach ($keywords as $keyword) {
$query->orWhere($column, 'LIKE', '%' . $keyword . '%');
}
}
});
}
}