diff --git a/app/Console/Commands/EsTest.php b/app/Console/Commands/EsTest.php new file mode 100644 index 0000000..6c6296c --- /dev/null +++ b/app/Console/Commands/EsTest.php @@ -0,0 +1,45 @@ +get(); + dd($gds); + return 0; + } +} diff --git a/app/Models/LanzuGoods.php b/app/Models/LanzuGoods.php new file mode 100644 index 0000000..163d2f2 --- /dev/null +++ b/app/Models/LanzuGoods.php @@ -0,0 +1,48 @@ + $this->name, + 'market_id' => $this->market_id, + 'store_id' => $this->store_id, + ]; + } + + /** + * 指定 搜索索引中存储的唯一ID + * @return mixed + */ + public function getScoutKey() + { + return $this->id; + } + + /** + * 指定 搜索索引中存储的唯一ID的键名 + * @return string + */ + public function getScoutKeyName() + { + return 'id'; + } + +} diff --git a/composer.json b/composer.json index f795599..a45ffbb 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,9 @@ "guzzlehttp/guzzle": "^6.3", "iidestiny/laravel-filesystem-oss": "^2.0", "laravel/framework": "^7.0", + "laravel/scout": "^8.3", "laravel/tinker": "^2.0", + "matchish/laravel-scout-elasticsearch": "^4.0", "overtrue/laravel-wechat": "~5.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index d8f4dbc..1f29929 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b3d2ad98d7c44d90fdb1789d0ac90e0f", + "content-hash": "84376492bcb35a9e12770be80cda5b0e", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -869,6 +869,188 @@ ], "time": "2020-06-16T20:11:17+00:00" }, + { + "name": "elasticsearch/elasticsearch", + "version": "v7.9.0", + "source": { + "type": "git", + "url": "https://github.com/elastic/elasticsearch-php.git", + "reference": "1380925ccd276ab897c76596cf3705cb9714a78c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/elastic/elasticsearch-php/zipball/1380925ccd276ab897c76596cf3705cb9714a78c", + "reference": "1380925ccd276ab897c76596cf3705cb9714a78c", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-json": ">=1.3.7", + "ezimuel/ringphp": "^1.1.2", + "php": "^7.1", + "psr/log": "~1.0" + }, + "require-dev": { + "cpliakas/git-wrapper": "~2.0", + "doctrine/inflector": "^1.3", + "mockery/mockery": "^1.2", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.4", + "symfony/finder": "~4.0", + "symfony/yaml": "~4.0" + }, + "suggest": { + "ext-curl": "*", + "monolog/monolog": "Allows for client-level logging and tracing" + }, + "type": "library", + "autoload": { + "files": [ + "src/autoload.php" + ], + "psr-4": { + "Elasticsearch\\": "src/Elasticsearch/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Zachary Tong" + }, + { + "name": "Enrico Zimuel" + } + ], + "description": "PHP Client for Elasticsearch", + "keywords": [ + "client", + "elasticsearch", + "search" + ], + "time": "2020-08-18T13:44:18+00:00" + }, + { + "name": "ezimuel/guzzlestreams", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/ezimuel/guzzlestreams.git", + "reference": "abe3791d231167f14eb80d413420d1eab91163a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ezimuel/guzzlestreams/zipball/abe3791d231167f14eb80d413420d1eab91163a8", + "reference": "abe3791d231167f14eb80d413420d1eab91163a8", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Fork of guzzle/streams (abandoned) to be used with elasticsearch-php", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "time": "2020-02-14T23:11:50+00:00" + }, + { + "name": "ezimuel/ringphp", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/ezimuel/ringphp.git", + "reference": "0b78f89d8e0bb9e380046c31adfa40347e9f663b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ezimuel/ringphp/zipball/0b78f89d8e0bb9e380046c31adfa40347e9f663b", + "reference": "0b78f89d8e0bb9e380046c31adfa40347e9f663b", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ezimuel/guzzlestreams": "^3.0.1", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Fork of guzzle/RingPHP (abandoned) to be used with elasticsearch-php", + "time": "2020-02-14T23:51:21+00:00" + }, { "name": "fideloper/proxy", "version": "4.4.0", @@ -1482,6 +1664,78 @@ ], "time": "2020-07-27T18:25:06+00:00" }, + { + "name": "laravel/scout", + "version": "v8.3.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/scout.git", + "reference": "da05fbb539889338a7f0cabb0cf5acdd0083278c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/scout/zipball/da05fbb539889338a7f0cabb0cf5acdd0083278c", + "reference": "da05fbb539889338a7f0cabb0cf5acdd0083278c", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "illuminate/bus": "^6.0|^7.0|^8.0", + "illuminate/contracts": "^6.0|^7.0|^8.0", + "illuminate/database": "^6.0|^7.0|^8.0", + "illuminate/http": "^6.0|^7.0|^8.0", + "illuminate/pagination": "^6.0|^7.0|^8.0", + "illuminate/queue": "^6.0|^7.0|^8.0", + "illuminate/support": "^6.0|^7.0|^8.0", + "php": "^7.2" + }, + "require-dev": { + "algolia/algoliasearch-client-php": "^2.2", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^8.0|^9.3" + }, + "suggest": { + "algolia/algoliasearch-client-php": "Required to use the Algolia engine (^2.2)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Scout\\ScoutServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Scout\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Scout provides a driver based solution to searching your Eloquent models.", + "keywords": [ + "algolia", + "laravel", + "search" + ], + "time": "2020-08-25T18:14:31+00:00" + }, { "name": "laravel/tinker", "version": "v2.4.1", @@ -1717,6 +1971,72 @@ ], "time": "2020-07-26T07:20:36+00:00" }, + { + "name": "matchish/laravel-scout-elasticsearch", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/matchish/laravel-scout-elasticsearch.git", + "reference": "f65731880ac8c2c42c6790e8917550cdca8e30ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/matchish/laravel-scout-elasticsearch/zipball/f65731880ac8c2c42c6790e8917550cdca8e30ab", + "reference": "f65731880ac8c2c42c6790e8917550cdca8e30ab", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "elasticsearch/elasticsearch": ">=7.2", + "laravel/scout": "^8.0", + "ongr/elasticsearch-dsl": "^7.0", + "php": "^7.2" + }, + "require-dev": { + "fzaninotto/faker": "^1.8", + "illuminate/support": "^6.0|^7.0", + "nunomaduro/larastan": "~0.5", + "orchestra/testbench": "^4.0|^5.0", + "phpunit/phpunit": "^8.0|^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Matchish\\ScoutElasticSearch\\ScoutElasticSearchServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Matchish\\ScoutElasticSearch\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sergey Shliakhov", + "email": "shlyakhov.up@gmail.com" + } + ], + "description": "Search among multiple models with ElasticSearch and Laravel Scout", + "keywords": [ + "elasticsearch", + "extended", + "laravel", + "scout", + "search" + ], + "time": "2020-03-26T04:06:20+00:00" + }, { "name": "monolog/monolog", "version": "2.1.1", @@ -1947,6 +2267,64 @@ ], "time": "2020-07-25T13:18:53+00:00" }, + { + "name": "ongr/elasticsearch-dsl", + "version": "v7.2.0", + "source": { + "type": "git", + "url": "https://github.com/ongr-io/ElasticsearchDSL.git", + "reference": "b7653ed32d6d5b65aeef3b7ef4f46e7ac069c393" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ongr-io/ElasticsearchDSL/zipball/b7653ed32d6d5b65aeef3b7ef4f46e7ac069c393", + "reference": "b7653ed32d6d5b65aeef3b7ef4f46e7ac069c393", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "elasticsearch/elasticsearch": "^7.0", + "paragonie/random_compat": "*", + "php": "^7.2", + "symfony/serializer": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0", + "squizlabs/php_codesniffer": "^3.0" + }, + "suggest": { + "elasticsearch/elasticsearch": "This library is for elasticsearch/elasticsearch client to enhance it with DSL functionality." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.1-dev" + } + }, + "autoload": { + "psr-4": { + "ONGR\\ElasticsearchDSL\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "ONGR team", + "homepage": "http://www.ongr.io" + } + ], + "description": "Elasticsearch DSL library", + "homepage": "http://ongr.io", + "time": "2020-02-20T20:35:10+00:00" + }, { "name": "opis/closure", "version": "3.5.5", @@ -2131,12 +2509,6 @@ "wechat", "weibo" ], - "funding": [ - { - "url": "https://www.patreon.com/overtrue", - "type": "patreon" - } - ], "time": "2020-03-04T15:22:25+00:00" }, { @@ -2210,20 +2582,6 @@ "weixin", "weixin-sdk" ], - "funding": [ - { - "url": "https://www.easywechat.com/img/pay/wechat.jpg", - "type": "custom" - }, - { - "url": "https://github.com/overtrue", - "type": "github" - }, - { - "url": "https://www.patreon.com/overtrue", - "type": "patreon" - } - ], "time": "2020-07-29T07:36:50+00:00" }, { @@ -2994,6 +3352,58 @@ ], "time": "2020-07-28T16:51:01+00:00" }, + { + "name": "react/promise", + "version": "v2.8.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^6.5 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2020-05-12T15:16:56+00:00" + }, { "name": "spatie/eloquent-sortable", "version": "3.8.2", @@ -3203,20 +3613,6 @@ "caching", "psr6" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-07-23T17:22:30+00:00" }, { @@ -3285,20 +3681,6 @@ "interoperability", "standards" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-07-06T13:23:11+00:00" }, { @@ -4898,20 +5280,6 @@ "psr-17", "psr-7" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-06-25T08:21:47+00:00" }, { @@ -4998,6 +5366,95 @@ ], "time": "2020-06-18T18:24:02+00:00" }, + { + "name": "symfony/serializer", + "version": "v5.1.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/serializer.git", + "reference": "a2c913f5a25a13bd5878dff1fe9c922157bb73a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/serializer/zipball/a2c913f5a25a13bd5878dff1fe9c922157bb73a2", + "reference": "a2c913f5a25a13bd5878dff1fe9c922157bb73a2", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-php80": "^1.15" + }, + "conflict": { + "phpdocumentor/type-resolver": "<0.2.1", + "symfony/dependency-injection": "<4.4", + "symfony/property-access": "<4.4", + "symfony/property-info": "<4.4", + "symfony/yaml": "<4.4" + }, + "require-dev": { + "doctrine/annotations": "~1.0", + "doctrine/cache": "~1.0", + "phpdocumentor/reflection-docblock": "^3.2|^4.0", + "symfony/cache": "^4.4|^5.0", + "symfony/config": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/error-handler": "^4.4|^5.0", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/mime": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", + "symfony/property-info": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0" + }, + "suggest": { + "doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.", + "doctrine/cache": "For using the default cached annotation reader and metadata cache.", + "psr/cache-implementation": "For using the metadata cache.", + "symfony/config": "For using the XML mapping loader.", + "symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.", + "symfony/property-access": "For using the ObjectNormalizer.", + "symfony/property-info": "To deserialize relations.", + "symfony/yaml": "For using the default YAML mapping loader." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Serializer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Serializer Component", + "homepage": "https://symfony.com", + "time": "2020-08-18T11:41:36+00:00" + }, { "name": "symfony/service-contracts", "version": "v2.1.3", @@ -5441,20 +5898,6 @@ "instantiate", "serialize" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-06-07T15:42:22+00:00" }, { @@ -6902,6 +7345,7 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2019-09-17T06:23:10+00:00" }, { @@ -7865,6 +8309,5 @@ "platform": { "php": "^7.2.5" }, - "platform-dev": [], - "plugin-api-version": "1.1.0" + "platform-dev": [] } diff --git a/config/app.php b/config/app.php index 5c4145e..635ba69 100644 --- a/config/app.php +++ b/config/app.php @@ -175,6 +175,7 @@ return [ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Iidestiny\LaravelFilesystemOss\OssStorageServiceProvider::class, + \Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class, ], /* diff --git a/config/elasticsearch.php b/config/elasticsearch.php new file mode 100644 index 0000000..184b060 --- /dev/null +++ b/config/elasticsearch.php @@ -0,0 +1,23 @@ + [ + 'mappings' => [ + 'lanzu-goods-test' => [ + "properties"=> [ + "name"=> [ + "type"=> "text", + "analyzer"=> "ik_max_word", + "search_analyzer"=> "ik_smart" + ], + 'store_id'=>[ + "type"=> "integer", + ], + 'market_id'=>[ + "type"=> "integer", + ] + ] + ] + ] + ], +]; diff --git a/config/scout.php b/config/scout.php new file mode 100644 index 0000000..bb11106 --- /dev/null +++ b/config/scout.php @@ -0,0 +1,106 @@ + env('SCOUT_DRIVER', 'Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine'), + + /* + |-------------------------------------------------------------------------- + | Index Prefix + |-------------------------------------------------------------------------- + | + | Here you may specify a prefix that will be applied to all search index + | names used by Scout. This prefix may be useful if you have multiple + | "tenants" or applications sharing the same search infrastructure. + | + */ + + 'prefix' => env('SCOUT_PREFIX', ''), + + /* + |-------------------------------------------------------------------------- + | Queue Data Syncing + |-------------------------------------------------------------------------- + | + | This option allows you to control if the operations that sync your data + | with your search engines are queued. When this is set to "true" then + | all automatic data syncing will get queued for better performance. + | + */ + + 'queue' => env('SCOUT_QUEUE', false), + + /* + |-------------------------------------------------------------------------- + | Chunk Sizes + |-------------------------------------------------------------------------- + | + | These options allow you to control the maximum chunk size when you are + | mass importing data into the search engine. This allows you to fine + | tune each of these chunk sizes based on the power of the servers. + | + */ + + 'chunk' => [ + 'searchable' => 500, + 'unsearchable' => 500, + ], + + /* + |-------------------------------------------------------------------------- + | Soft Deletes + |-------------------------------------------------------------------------- + | + | This option allows to control whether to keep soft deleted records in + | the search indexes. Maintaining soft deleted records can be useful + | if your application still needs to search for the records later. + | + */ + + 'soft_delete' => false, + + /* + |-------------------------------------------------------------------------- + | Identify User + |-------------------------------------------------------------------------- + | + | This option allows you to control whether to notify the search engine + | of the user performing the search. This is sometimes useful if the + | engine supports any analytics based on this application's users. + | + | Supported engines: "algolia" + | + */ + + 'identify' => env('SCOUT_IDENTIFY', false), + + /* + |-------------------------------------------------------------------------- + | Algolia Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure your Algolia settings. Algolia is a cloud hosted + | search engine which works great with Scout out of the box. Just plug + | in your application ID and admin API key to get started searching. + | + */ + + 'algolia' => [ + 'id' => env('ALGOLIA_APP_ID', ''), + 'secret' => env('ALGOLIA_SECRET', ''), + ], + +];