我正在使用 Laravel 7,MS 0.13
我正在尝试使用以下方法索引我的模型:
php artisan scout:import "App\Models\Product"
然后我做(local_product 是我的索引):
curl -X GET 'http://localhost:7700/indexes/local_product/documents'
我得到[]
如果我在 Algolia 中建立索引,我的文件在那里就可以了。
另外,如果我索引电影:
curl -X POST 'http://127.0.0.1:7700/indexes/movies/documents' --data @movies.json
电影也被索引。
你好@elfeffe ,
如果没有更多信息,这很难为您提供帮助。
如果您记录您的 meilisearch 实例,您是否得到:
"POST /indexes/local_product/documents?primaryKey=id HTTP/1.1" 202 14
如果您在产品模型中使用了toSearchableArray()
,您能否向我展示内容,以便我能够重现相同的错误。
我正在使用 MongoDb。 我认为关键是_id
可以这样吗?
我使用 toSearchableArray 过滤一些字段,但它们在 Algolia 上建立索引。 我转储了最后的数组,没关系。
我现在没有电脑,你想让我试试什么?
我不明白你的意思
如果您记录您的 meilisearch 实例,您是否得到:
让我知道你想让我尝试什么
如果我尝试
curl \-X POST 'http://localhost:7700/indexes/local_product/documents' \--data '[{"id": 287947,"title": "Shazam","poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg","overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.","release_date": "2019-03-23"}]'
我明白了{"updateId":31}
但后来我做curl -X GET 'http://localhost:7700/indexes/local_product/documents'
我得到
[]
再次
你好@elfeffe
您可以随时查看更新状态,大多数时候MeiliSearch会告诉您错误是什么,以防更新失败。
您可以检查:获取更新状态
对于最后一个示例,您可以尝试
curl -X GET 'http://localhost:7700/indexes/local_product/updates/31'
这应该会给你更多关于正在发生的事情的信息。
我正在使用 MongoDb。 我认为关键是_id
可以这样吗?
当您创建索引local_product
时,您是否指定了关键参数?
php artisan scout:index local_product --key _id
我使用 toSearchableArray 过滤一些字段,但它们在 Algolia 上建立索引。 我转储了最后的数组,没关系。
您是否也可以通过评论 toSearchableArray() 来尝试,我认为这不是这里的问题,但尝试起来没有任何成本。
我已删除 toSearchableArray()
然后我尝试做:
php artisan scout:index local_product --key _id
不工作。
然后做php artisan scout:index local_product --key id
和...一起
/**
* Get the value used to index the model.
*
* <strong i="14">@return</strong> mixed
*/
public function getScoutKey()
{
return $this->id;
}
/**
* Get the key name used to index the model.
*
* <strong i="15">@return</strong> mixed
*/
public function getScoutKeyName()
{
return 'id';
}
没什么,当我做的时候curl -X GET 'http://localhost:7700/indexes/local_product/documents'
我只得到一个文件,一个使用索引的文件
curl \-X POST 'http://localhost:7700/indexes/local_product/documents' \--data '[{"id": 287947,"title": "Shazam","poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg","overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.","release_date": "2019-03-23"}]'
有没有我可以检查的日志?
当你导入你的数据时,你有没有得到这样的东西:
shok@pop-os:~/web/blog$ php artisan scout:import "App\Models\Post"
Imported [App\Models\Post] models up to ID: 100
All [App\Models\Post] records have been imported.
日志位于storage/logs/laravel.log
您是否在scout.php
中设置 queue => true 或在 .env 中设置 SCOUT_QUEUE=true ?
我已经尝试过队列的真假。 我总是得到
导入的 [AppModelsProduct] 型号最多 ID:5eea4b314c80095faf5be593
导入的 [AppModelsProduct] 型号最多 ID:5eea4bd94c80095faf5be787
导入的 [AppModelsProduct] 型号最多 ID:5eea4cc34c80095faf5be97b
导入的 [AppModelsProduct] 型号最多 ID:5eea4dfa4c80095faf5beb6f
导入的 [AppModelsProduct] 型号最多 ID:5eea4f6b4c80095faf5bed63
导入的 [AppModelsProduct] 型号最多 ID:5eea51164c80095faf5bef57
导入的 [AppModelsProduct] 型号最多 ID:5eea524e4c80095faf5bf099
但是没有文件。
我知道 laravel 的日志在哪里,但我没有错误,我想看到的是 MS 日志。
有什么办法可以看到发生了什么?
使用所有相同的设置,Algolia 正在索引我的文档。
好吧,Meilisearch laravel scout 只是一个类似于 Algolia 的复制粘贴的引擎。 所以这应该不是问题,但我也从未尝试过用 mongodb 运行它......
@eskombro @curquiza可以回答是 MS 日志。
这与 MongoDB 有关,因为用户模型是 MySQL 并且可以工作。
我的意思是,这与 MongoDB / Meilisearch 有关,因为 Algolia 也与 MongoDB 一起使用。
如果我能看到一些来自 MS 的日志,那就太好了,如果 Algolia 支持它但不支持 Meilisearch,那就太难过了。
我可以尝试解决问题,但我需要您的帮助来了解如何使用 laravel 安装 mongoDB
至于现在,MeiliSearch 日志直接打印到标准输出,所以这取决于你在哪里运行你的 MeiliSearch 实例。 它在哪里运行?
我在这里打开了一个讨论 MeiliSearch 中持久日志的问题: https ://github.com/meilisearch/MeiliSearch/issues/898
@elfeffe您是否按照我在之前评论中的建议检查了更新状态? 如果文档成功发送到 MeilISearch 并且您获得了状态 ID,您很可能会在该更新状态中找到有关 MeilISearch 尝试索引时出现问题的信息。 试试这个: https ://github.com/meilisearch/meilisearch-laravel-scout/issues/36#issuecomment -668787383
看这个
curl \-X POST 'http://localhost:7700/indexes/local_product/documents' \--data '[{"id": 287947,"title": "Shazam","poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg","overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.","release_date": "2019-03-23"}]'
这行得通,但是
curl \-X POST 'http://localhost:7700/indexes/local_product/documents' \--data '[{"id": 5eea4bd94c80095faf5be787,"title": "Shazam 2","poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg","overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.","release_date": "2019-03-23"}]'
“5eea4bd94c80095faf5be787”是一个 MongoDB _id
回报这美丽
{"message":"无效 JSON:第 1 行第 11 列无效数字","errorCode":"bad_request","errorType":"invalid_request_error","errorLink":" https://docs.meilisearch.com/errors #bad_request "}
我认为 JSON 是有效的,MS 和自定义密钥存在一些问题。
我不知道是长度,字母还是什么。
经过一些尝试,我认为字母是问题,MS 不接受 id 上的字母。 但是 Laravel 让你把字母放在那里。
这就是我认为的问题
是的,您只需将其作为字符串发送,并用双引号括起来
它将使用"id": "5eea4bd94c80095faf5be787"
而不是"id": 5eea4bd94c80095faf5be787
因为5eea4bd94c80095faf5be787
不是有效数字🙂
但我无法控制你的 Scout 扩展如何发送它🙂
即使这样做
/**
* Get the value used to index the model.
*
* <strong i="6">@return</strong> mixed
*/
public function getScoutKey()
{
return (string)$this->_id;
}
它不起作用,我认为这个引擎必须处理字符串 id
在 toSearchableArray() 中做同样的事情
return [ 'id' => (string) $this->_id]
or
return [ '_id' => (string) $this->_id]
我不知道你设置了什么键
public function toSearchableArray()
{
$array = $this->toArray();
$array['id'] = (string)$array['_id'];
return $array;
}
这样可行
最后一件事。
Algolia 自动处理,连同索引创建。
我的意思是,如果不存在,Algolia 会创建索引,并且我可以用字母索引 ID 而无需任何转换。
我认为 MS 应该包括这两个功能。
我的意思是,如果不存在,Algolia 会创建索引
事实上,MeiliSearch API 还没有处理这个特性。
作为替代解决方案,我们的大多数 SDK 都提供了get_or_create_index
方法(就像 PHP SDK 一样)🙂
我可以用字母索引 ID 而无需任何转换。
您遇到的问题来自 JSON 有效性。 甚至 Algolia API 也不接受无效的 JSON:发送带有字母的数字而不引用它( "
)被认为是无效的 JSON 并且会失败。
查看 Algolia 仪表板:
也许 Algolia 的 Laravel SDK 将您的数字与字母转换为字符串,这就是您没有失败的原因🙂
我认为 MS 应该包括这两个功能。
所以也许meilisearch-laravel-scout
可以包含“引用功能”,但 MeiliSearch 不能,因为它需要一个有效的 JSON 😉
是的,在这两种情况下,我都在谈论这个 Scout 引擎,我们在这里是 Scout 集成。
SDK 可以提供创建索引的方法,但如果索引不存在,Scout 会失败。
与带有字母的 Id 相同,我知道 JSOn 格式不正确,但是 Scout 引擎会在它失败之前控制它。
就像 Algolia 一样,因为它不会因字母而失败。
好的好的不确定明白😉
它们可能是很好的实现功能! 🙂
编辑:我们应该考虑是否在 meilisearch-php 或 meilisearch-laravel-scout 包中实现它。
@curquiza
看情况,两者都好。
如果我们在 scout 中实现它,我猜 symfony(和其他框架实现)也应该实现它(可能已经是这样了)。 那么将它放在 SDK 中可能会更好吗?
我不确定 scout 是否为 Algolia 实现它,我认为这是由 Algolia PHP SDK 处理的,当我有一点空闲时间时我会检查一下。
@shokme ,你是对的,在 PHP SDK 中而不是在 laravel-scout 集成中这样做可能更聪明。
让我们知道您的调查,我将相应地移动(或重新创建)问题! 🙂
所以,在调查了整个事情之后。
我已经使用jenssegers/laravel-mongodb
在 laravel 中安装了 mongodb。
我从创建索引开始。
php artisan scout:index cars -k _id
创建模型
<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model;
use Laravel\Scout\Searchable;
class Car extends Model
{
use Searchable;
public function getScoutKey() // not required if this is already your primary key
{
return $this->_id;
}
public function getScoutKeyName() // not required if this is already your primary key
{
return '_id';
}
}
创造一辆新车
$car = new App\Car();
$car->name = 'mustang';
$car->constructor = 'ford';
$car->type = 'muscle';
$car->horses = 280;
$car->save();
模型发送到meilisearch没有任何问题!
{
"status": "processed",
"updateId": 1,
"type": {
"name": "DocumentsAddition",
"number": 1
},
"duration": 0.005275826,
"enqueuedAt": "2020-08-29T17:43:55.104917708Z",
"processedAt": "2020-08-29T17:43:55.121602037Z"
}
进行搜索时,我得到了正确的结果
App\Car::search('mustang')->get();
```json
[
{
"_id": "5f4a93dbd9668370086c7752",
“名称”:“野马”,
“构造函数”:“福特”,
“类型”:“肌肉”,
“马”:280,
"updated_at": "2020-08-29T17:43:55.102000Z",
“created_at”:“2020-08-29T17:43:55.102000Z”
}
]
The only problem I have encounter while trying to reproduce the bug was by forgot to set `_id` has primaryKey
and the update status was returning:
```json
{
"status": "failed",
"updateId": 3,
"type": {
"name": "DocumentsAddition",
"number": 1
},
"error": "serializer error; Primary key is missing.",
"duration": 9.817e-6,
"enqueuedAt": "2020-08-29T17:21:00.098580201Z",
"processedAt": "2020-08-29T17:21:00.100495474Z"
}
所以,老实说,我不明白为什么你没有得到回复$this->_id
@elfeffe
@shokme我不知道。 几天后,我将通过搜索恢复我的工作,如果我发现新的东西,我会通知你。
SDK 应该像 Algolia 一样自动创建索引,并使用正确的 Id,以避免错误。
SDK 应该像 Algolia 一样自动创建索引,并使用正确的 Id,以避免错误。
计划在MeiliSearch核心引擎中! 🙂
https://github.com/meilisearch/MeiliSearch/issues/918
最有用的评论
这样可行