有条件地向 Laravel Scout 添加索引(Algolia)

编程入门 行业动态 更新时间:2024-10-27 08:40:09
本文介绍了有条件地向 Laravel Scout 添加索引(Algolia)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试根据条件使用 Laravel Scout 向 Algolia 添加索引.例如,我有一个 Article 模型,如果文章是 active,我只想将这篇文章添加到 Algolia.我的第一种方法是这样的:

I'm trying to add index to Algolia using Laravel Scout based on a condition. For example I have a Article model and I only want to add this article to Algolia if the article is active. My first approach was this:

public function toSearchableArray() { if($this->active) return $record; return []; }

这只会添加活动记录,但仍会尝试添加在 algolia 中被视为操作的空数组(我将为此付费).第二种方法是使用来自 scout 的 shouldBesearchable() 函数:

this only adds the active records but still attempts to add empty arrays which is considered as Operation in algolia ( I will be charged for it). The second approach was to use shouldBesearchable() function from scout:

public function shouldBeSearchable() { if($this->active) return true; return false; }

这不适用于 php artisan scout:import "AppArticle".有没有人遇到过类似的问题?

This doesn't work with php artisan scout:import "AppArticle". Has anyone faced a similar problem?

推荐答案

这是 Laravel Scout 中的一个错误,shouldBeSearchable 尚未发布(在 master 分支上)所以你可能会遇到这样的问题一个.

It was a bug in Laravel Scout, shouldBeSearchable is not release yet (on master branch) so you may experience some issue like this one.

不过,好消息是:这个 PR 刚刚修复了它.github/laravel/scout/pull/250

Although, good news: it was just fixed by this PR. github/laravel/scout/pull/250

更多推荐

有条件地向 Laravel Scout 添加索引(Algolia)

本文发布于:2023-11-28 19:51:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有条件   索引   Scout   Laravel   Algolia

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!