如何使用全文TNTSearch facade

时间:2016-12-06 08:08:08

标签: php laravel full-text-search

我尝试了TNTSearch,但结果仅适用于完整的单词。例如,短语Facilis dolorem为我提供了所有记录组合,其中包含facilis或单词dolorem.

如何在Laravel中使用TNTSearch进行搜索?

LIKE %lore%

如果我输入lore,,我就无法获得中间带有lore字样的记录。

3 个答案:

答案 0 :(得分:0)

您应该通过配置启用模糊搜索,如文档中所述:

'tntsearch' => [
'storage'  => storage_path(), //place where the index files will be stored
'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
'fuzzy' => [
    'prefix_length' => 2,
    'max_expansions' => 50,
    'distance' => 2
],

],

即。如果这是你的配置设置,你将.env中的TNTSEARCH_FUZZINESS变为true,你应该得到你期望的结果。

此外,如果您已经创建了索引,您似乎必须重新索引内容,以便启动模板...

答案 1 :(得分:0)

我的同样问题没有解决,最后使用了其他好的替代品: laravel-scout-mysql-driver 试试吧 但确切地回答了你的问题: 您必须在查询中使用*lore*。更多查询文档: Boolean Full-Text Searches

答案 2 :(得分:0)

我遇到了这个问题,并通过在'asYouType' => false,中添加config\scout.php来解决了。 我的代码是:

'tntsearch' => [
        'storage'  => storage_path(), //place where the index files will be stored
        'fuzziness' => true,
        'fuzzy' => [
            'prefix_length' => 2,
            'max_expansions' => 50,
            'distance' => 2
        ],
        'asYouType' => false,
    ],