简体   繁体   English

Laravel Nova v3 全局和资源级别间歇性搜索结果

[英]Laravel Nova v3 intermittent search results at global and resource level

Nova: v3.8.2 Laravel: 7新星:v3.8.2 Laravel:7

I have a Laravel Nova app with the following App/Nova/User.php resource:我有一个 Laravel Nova 应用程序,具有以下 App/Nova/User.php 资源:

/**
 * The columns that should be searched.
 *
 * @var array
 */
public static $search = [
    'firstname', 'lastname', 'email', 'username'
];

When using the global or resource level search you can search for the username, last name and first name successfully.使用全局或资源级搜索时,您可以成功搜索用户名、姓氏和名字。 But search results are intermittent across all these fields.但所有这些领域的搜索结果都是断断续续的。 For example, whole users are missing, or any searches on emails won't work.例如,整个用户都丢失了,或者对电子邮件的任何搜索都不起作用。

Though, within App/User.php we have email set to hidden:虽然,在 App/User.php 中,我们将 email 设置为隐藏:

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = [
    'email',
];

It may be to do with the later, but I'm not sure how to override this in the Nova users resource.这可能与后者有关,但我不确定如何在 Nova 用户资源中覆盖它。 Or it could be a separate issue altogether.或者它可能完全是一个单独的问题。

After some research and further testing, I found out that Nova uses Laravel Scout by default for searching.经过一些研究和进一步测试,我发现 Nova 默认使用 Laravel Scout 进行搜索。 I'd assumed incorrectly the default method was a direct saearch of the database.我错误地假设默认方法是直接搜索数据库。 In our case, our Scout Algolia setup has is very specific for the frontend.在我们的例子中,我们的 Scout Algolia 设置非常针对前端。 For example, we don't include email for security.例如,出于安全考虑,我们不包括 email。 Also, our local testing Algolia setup has a limited set of records.此外,我们的本地测试 Algolia 设置的记录集有限。 This was causing intermittent search results when testing.这导致测试时断断续续的搜索结果。

The best solution here is to setup Algolia correctly to support Nova.这里最好的解决方案是正确设置 Algolia 以支持 Nova。 But as a quick solution we can disable Scout on a Nova resource level:但作为快速解决方案,我们可以在 Nova 资源级别禁用 Scout:

public static function usesScout()
{
    return false;
}

https://github.com/laravel/nova-issues/issues/1349 https://github.com/laravel/nova-issues/issues/1349

Laravel Nova: Bypass the search with Scout Laravel Nova:使用 Scout 绕过搜索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM