承接 shopapps/scout-solr-engine 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shopapps/scout-solr-engine

Composer 安装命令:

composer require shopapps/scout-solr-engine

包简介

An Apache Solr driver for laravel scout

README 文档

README

GitHub issues Latest Stable Version License PHP Version Require

This package provides a basic implementation of the Apache Solr search engine within Laravel Scout.

Installation

composer require shopapps/scout-solr-engine

config

This package provides a config file that can be modified using .env variables.
You can initialize your own config file with:

php artisan vendor:publish --provider="Scout\Solr\ScoutSolrServiceProvider"

scout:index

By default, Solr doesn't allow indexes (cores) to be created without providing the proper folders and files on the file system first. However, if a default config set is set up in the Solr instance this becomes possible through the API.
The scout:index command will only work if the Solr instance is properly configured and the config files has the corresponding name for the config set folder. For more information, see https://solr.apache.org/guide/8_9/config-sets.html#config-sets

To get the _default configset onto your server try the following (adjusting the command to match your solr version/location:

sudo cp -r /opt/solr-9.2.1/server/solr/configsets /var/solr/data
sudo chown -R solr:solr /var/solr/data/configsets

then checking that folder you should see something like:

sudo ls -lah /var/solr/data/configsets/

total 16K
drwxr-xr-x  4 solr solr 4.0K Jul 13 07:03 .
drwxr-x--- 13 solr solr 4.0K Jul 13 07:03 ..
drwxr-xr-x  3 solr solr 4.0K Jul 13 07:03 _default
drwxr-xr-x  3 solr solr 4.0K Jul 13 07:03 sample_techproducts_configs

most likely you can safely delete the sample_techproducts_configs folder from there unless you are using it :-)

Cores (indexes)

Within the config file a core (index) is not provided. The engine will determine which core to connect to using the searchableAs() method on the model.

Alternatively, if a specific model is on a different Solr instance, another configuration can be provided for this model. It's important for the configuration key to match the searchableAs() of the model.

When in Cloud mode i could not get this to work fully, so instead you could try:

Step 1: Create a collection in solr via admin panel.

http://127.0.0.1:8983/solr/#/~collections

choose add collection and configure it across your shards and replicas ( for demo mode use shards: 2 and replicas: 2)

Step 2: Setup your schema in the Model

make sure your model is configured to use the correct Searchable trait

<?php

namespace App\Models\User;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

use Scout\Solr\Traits\Searchable; // <--- THIS IS IMPORTANT


class User extends Model
{
    use HasFactory;
    use Searchable;

configure the searchable_fields property on your model, to use the schema you want to create in Solr.

protected $searchable_fields = [
        'id'            => ['type' => 'string', 'indexed' => true, 'stored' => true],
        'role_id'       => ['type' => 'plong', 'indexed' => true, 'stored' => true],
        'name'          => ['type' => 'string', 'indexed' => true, 'stored' => true],
        'description'   => ['type' => 'text_general', 'indexed' => true, 'stored' => true],
        'is_active'     => ['type' => 'boolean', 'indexed' => true, 'stored' => true],
        'created_at'    => ['type' => 'pdate', 'indexed' => true, 'stored' => true],
        'updated_at'    => ['type' => 'pdate', 'indexed' => true, 'stored' => true],
    ];

Step 3: Build the schema

$model = new \App\Models\User();
$model->buildSolrSchema();

this will log any issues to the laravel log file

Solarium

This package uses solarium/solarium to handle requests to the solr instance. This app is meant to be a simple implementation of the laravel/scout engine. For complex queries to the solr instance I would recommend initializing your own Solarium client and use that package. Visit https://solarium.readthedocs.io/en/stable/ to view the documentation of the solarium package.

For convenience, any unknown methods used on the engine will be forwarded to the solarium client.

$model = new \App\Models\SearchableModel();

/** @var \Scout\Solr\Engines\SolrEngine $engine */
$engine = app(\Laravel\Scout\EngineManager::class)->engine();
$select = $engine->setCore($model)->createSelect();
$select->setQuery('*:*');
$result = $engine->select($select, $engine->getEndpointFromConfig($model->searchableAs())); // getEndpointFromConfig() is only necessary when your model does not use the default solr instance.

Usage

not the best example but you get the idea

$res = Product::search()
  ->where('owner', 1021)
  ->paginate();

or...

$res = Product::search('description: "red" AND name: "car"')
  ->where('owner', 1021)
  ->paginate();

Events

The Solr Engine dispatches several events allowing you to hook into specific points in the engine.

Event Usage
Scout\Solr\Events\BeforeSelect Contains the Solr Solarium\QueryType\Select\Query\Query object and Scout Builder object. This event allows you to create complex queries using the Solarium package.
Scout\Solr\Events\BeforeSelect Contains the Solr Solarium\QueryType\Select\Result\Result object and Model object. This event allows you to create complex queries using the Solarium package.

Credits

This is a complete hash-up of lots of other great developers work. I needed to get something working for a project but most packages were out of date for laravel 10, scout 10 and solr 9 If you spot your code in here, please accept my appology and let me know and i'll add you to the list:

shopapps/scout-solr-engine 适用场景与选型建议

shopapps/scout-solr-engine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 157 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「solr」 「search」 「engine」 「driver」 「laravel」 「apache」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shopapps/scout-solr-engine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shopapps/scout-solr-engine 我们能提供哪些服务?
定制开发 / 二次开发

基于 shopapps/scout-solr-engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 157
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-10