Laravel 5.6 & Algolia 搜索 return 空结果
Laravel 5.6 & Algolia search return empty result
我在 Laravel 5.6 上使用 Algolia。我遵循 Laravel doc.
上的教程
$searches = Application::search($query)->get();
Collection {#243 ▼ #items: [] }
当我搜索应用程序时,结果 return 我 0 项。
我输入这个命令:
php artisan scout:import "App\Models\Application"
在 Algolia 上发送项目,它们出现在 Algolia 仪表板上,我可以看到。
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Application extends Model
{
use Searchable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'title',
'slug',
'short_description',
'long_description',
'state',
];
/**
* @return string
*/
public function searchableAs()
{
return 'applications';
}
/**
* @return mixed
*/
public function getScoutKey()
{
return $this->title;
}
}
您当前拥有 App\Models
的命名空间。您是否尝试过更新您的搜索调用以镜像此命名空间?:
$searches = App\Models\Application::search($query)->get();
这是因为您自定义了 Scout 键,但没有自定义 Scout 键名。
目前,Scout 将尝试构建一个 collection 与标题匹配的 ID。一旦定义了 getScoutKeyName
方法(应该 return 类似于字符串 title
的东西)。它应该工作
我在 Laravel 5.6 上使用 Algolia。我遵循 Laravel doc.
上的教程$searches = Application::search($query)->get();
Collection {#243 ▼ #items: [] }
当我搜索应用程序时,结果 return 我 0 项。
我输入这个命令:
php artisan scout:import "App\Models\Application"
在 Algolia 上发送项目,它们出现在 Algolia 仪表板上,我可以看到。
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Application extends Model
{
use Searchable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'title',
'slug',
'short_description',
'long_description',
'state',
];
/**
* @return string
*/
public function searchableAs()
{
return 'applications';
}
/**
* @return mixed
*/
public function getScoutKey()
{
return $this->title;
}
}
您当前拥有 App\Models
的命名空间。您是否尝试过更新您的搜索调用以镜像此命名空间?:
$searches = App\Models\Application::search($query)->get();
这是因为您自定义了 Scout 键,但没有自定义 Scout 键名。
目前,Scout 将尝试构建一个 collection 与标题匹配的 ID。一旦定义了 getScoutKeyName
方法(应该 return 类似于字符串 title
的东西)。它应该工作