TYPO3 8.7.13-MariaDB QueryBuilder全文

时间:2018-06-26 10:56:26

标签: php typo3 mariadb typo3-8.x

SELECT name 
FROM tx_snippethighlightsyntax_domain_model_snippets 
WHERE (MATCH(name, description, code, comment) AGAINST ('css'));

此查询可在phpMyAdmin和MariaDB中使用。现在,我的“问题”是使用QueryBuilder在TYPO3中进行调整。我没有看到任何MATCH或AGAINST运算符。

到目前为止,我的功能始于此:

private $tx = 'tx_snippethighlightsyntax_domain_model_snippets';

public function ftsSearch()
    {
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $ftsQueryBuilder = $connectionPool->getQueryBuilderForTable($this->tx);
        $fts = $ftsQueryBuilder
            ->select($this->tx . '.name')
            ->from($this->tx)
            ->where($ftsQueryBuilder->expr()->eq(
                MAGIC HAPPENS HERE ?
            )
            ->execute()
            ->fetchAll();
        return $fts;
    }

2 个答案:

答案 0 :(得分:1)

TYPO3核心中的扩展索引搜索在查询中使用MATCH和AGAINST。

以下来自IndexSearchRepository的代码应该可以帮助您建立查询

    $searchBoolean = '';
    if ($searchData['searchBoolean']) {
        $searchBoolean = ' IN BOOLEAN MODE';
    }
    $queryBuilder->andWhere(
        'MATCH (' . $queryBuilder->quoteIdentifier($searchData['fulltextIndex']) . ')'
        . ' AGAINST (' . $queryBuilder->createNamedParameter($searchData['searchString'])
        . $searchBoolean
        . ')'
    );

答案 1 :(得分:0)

private $tx = 'tx_snippethighlightsyntax_domain_model_snippets';

public function ftsSearch()
{
    $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
    $ftsQueryBuilder = $connectionPool->getQueryBuilderForTable($this->tx);
    $fts = $ftsQueryBuilder
        ->select($this->tx . '.name')
        ->from($this->tx)
        ->where('MATCH('
            . $this->tx .'.name,'
            . $this->tx .'.description,'
            . $this->tx .'.code,'
            . $this->tx .'.comment)'
            . ' AGAINST(' . $ftsQueryBuilder->createNamedParameter('put_search_here')
            . ')')
        ->execute()
        ->fetchAll();
    return $fts;
}

这个对我有用。谢谢!