Download the PHP package shopwwi/webman-scout without Composer

On this page you can find all versions of the php package shopwwi/webman-scout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package webman-scout

'Build Status' 'Latest Stable Version' 'Total Downloads' 'License'

安装

使用方法

设置

当使用 xunsearch 时,需提前在config/plugin/shopwwi/scout/ini下创建「indexName」.ini文件,亦可指定ini文件夹路径

搜索驱动安装

命令行

配置模型索引

每个 Eloquent 模型都与给定的搜索 「索引」同步,该索引包含该模型的所有可搜索记录。 换句话说,你可以将每个索引视为一个 MySQL 表。 默认情况下,每个模型都将持久化到与模型的典型 「表」名称匹配的索引。 通常,是模型名称的复数形式; 但你可以通过重写模型上的 searchableAs 方法来自由地自定义模型的索引:

配置可搜索数据

默认情况下,模型以完整的 toArray 格式持久化到搜索索引。如果要自定义同步到搜索索引的数据,可以覆盖模型上的 toSearchableArray 方法:

配置模型 ID

默认情况下,Scout 将使用模型的主键作为搜索索引中存储的唯一 ID /key。 可以通过模型上的 getScoutKeygetScoutKeyName 方法自定义:

自定义数据库搜索策略

默认情况下,数据库引擎将对你已配置为可搜索 的每个模型属性执行「where like」查询。但是,在某些情况下,这可能会导致性能不佳。因此,你可以通过配置数据库引擎的搜索策略,使某些指定的列使用全文搜索查询或仅使「where like」约束来搜索字符串的前缀(example%),而不是在整个字符串中搜索(%example%)。

要定义此行为,你可以将 PHP 属性分配给模型的 toSearchableArray 方法。任何未分配额外搜索策略行为的列将继续使用默认的「where like」策略:

修改导入查询

如果要修改用于检索所有模型以进行批量导入的查询,可以在模型上定义 makeAllSearchableUsing 方法。这是一个很好的地方,可以在导入模型之前添加任何可能需要的即时关系加载:

添加记录

一旦将 Shopwwi\WebmanScout\Searchable trait 添加到模型中,你只需 save 或 create 模型实例,它就会自动添加到搜索索引中。如果已将 Scout 配置为 使用队列,此操作将由队列 worker 进程在后台执行:

通过查询添加

如果你希望通过 Eloquent 查询将模型集合添加到搜索索引中,你也可以在 Eloquent 查询构造器上链式调用 searchable 方法。searchable 会把构造器的查询 结果分块 并将记录添加到搜索索引中。同样,如果你已将 Scout 配置为使用队列,则队列 worker 将在后台导入所有块:

你还可以在 Eloquent 关联实例上调用 searchable 方法:

或者,如果内存中已经有一组 Eloquent 模型,可以调用集合实例上的 searchable 方法,将模型实例添加到相应的索引中:

更新记录

要更新可搜索的模型,只需要更新模型实例的属性并将模型 save 到数据库。Scout 会自动将更新同步到你的搜索索引中:

你也可以在 Eloquent 查询语句上使用 searchable 方法来更新一个模型的集合。如果这个模型不存在你检索的索引里,就会被创建:

如果要更新关系中所有模型的搜索索引记录,可以在关系实例上调用 searchable

或者,如果内存中已经有 Eloquent 模型集合,则可以调用集合实例上的 searchable 方法来更新相应索引中的模型实例:

移除记录

要从索引中删除记录,只需从数据库中 delete 模型即可。即使你正在使用 软删除 模型,也可以这样做:

如果你不希望记录在删除之前被检索到,可以在 Eloquent 查询实例或集合上使用 unsearchable 方法:

如果要删除关系中所有模型的搜索索引记录,可以在关系实例上调用 unsearchable

或者,如果内存中已经有 Eloquent 模型集合,则可以调用集合实例上的 unsearchable 方法,从相应的索引中删除模型实例:

暂停索引

你可能需要在执行一批 Eloquent 操作的时候,不同步模型数据到搜索索引。此时你可以使用 withoutSyncingToSearch 方法来执行此操作。这个方法接受一个立即执行的回调。该回调中所有的操作都不会同步到模型的索引:

有条件的搜索模型实例

有时你可能只需要在某些条件下使模型可搜索。例如,假设你有 app\model\Goods 模型可能是两种状态之一:「仓库中」和「线上」。你可能只允许搜索 「线上」的商品。为了实现这一点,你需要在模型中定义一个 shouldBeSearchable 方法:

搜索

你可以使用 search 方法来搜索模型。search 方法接受一个用于搜索模型的字符串。你还需要在搜索查询上链式调用 get 方法,才能用给定的搜索语句查询与之匹配的 Eloquent 模型:

由于 Scout 搜索返回 Eloquent 模型的集合,你甚至可以直接从路由或控制器返回结果,结果将自动转换为 JSON :

如果你想在它们转换成 Eloquent 模型前得到原始结果,你应该使用 raw 方法:

自定义索引

搜索查询通常会在模型的 searchableAs 方法指定的索引上执行。但是,你可以使用 within 方法指定应搜索的自定义索引:

Where 子句

Scout 允许你在搜索查询中添加简单的「where」子句。目前,这些子句仅支持基本的数值相等性检查,主要用于按所有者 ID 确定搜索查询的范围。

由于搜索索引不是关系数据库,因此目前不支持更高级的「where」子句。

分页

除了检索模型的集合,你也可以使用 paginate 方法对搜索结果进行分页。默认传参为「page」「limit」

通过将数量作为第一个参数传递给 paginate 方法,可以指定每页要检索多少个模型:

软删除

如果你索引的模型是 软删除,并且你需要搜索已删除的模型,请将 config 配置文件中的 soft_delete 选项设置为 true:

当此配置选项为 true 时,Scout 不会从搜索索引中删除软删除的模型。相反,它将在索引记录上设置一个隐藏的__soft_deleted 属性。然后,你可以在搜索时使用 withTrashed 或 onlyTrashed 方法检索软删除记录:


All versions of webman-scout with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3|^8.0
illuminate/bus Version >=8.0|^10.0
illuminate/contracts Version >=8.0|^10.0
illuminate/database Version >=8.0|^10.0
illuminate/http Version >=8.0|^10.0
illuminate/pagination Version >=8.0|^10.0
illuminate/queue Version >=8.0|^10.0
illuminate/support Version >=8.0|^10.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package shopwwi/webman-scout contains the following files

Loading the files please wait ....