+ {{ __('Community Search') }} +
+-
+ @foreach($results as $r)
+
-
+ ++
+ + + + {{$r->title}} + +
+{{$r->body}}
+
+ @endforeach
+
diff --git a/app/Http/Controllers/Community.php b/app/Http/Controllers/Community.php index 29615bde..344f5d9a 100644 --- a/app/Http/Controllers/Community.php +++ b/app/Http/Controllers/Community.php @@ -16,6 +16,13 @@ class Community extends Controller { + public function search(Request $request) + { + return view('communitysearch', [ + 'results' => Post::search($request->input('search'))->paginate(10) + ]); + } + public function view() { return view('community', [ diff --git a/app/Models/Post.php b/app/Models/Post.php index 03e5621e..c215da9f 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -4,10 +4,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; class Post extends Model { - use HasFactory; + use HasFactory, Searchable; protected $fillable = [ 'title', @@ -16,6 +17,13 @@ class Post extends Model 'subject_id' ]; + public function toSearchableArray() + { + return[ + 'title' => $this->title, + ]; + } + public function Comments() { return $this->hasMany(Comment::class); diff --git a/composer.json b/composer.json index e3e514be..94b99134 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "laravel/fortify": "^1.8", "laravel/framework": "^9.0", "laravel/sanctum": "^2.11", + "laravel/scout": "^9.4", "laravel/socialite": "^5.2", "laravel/telescope": "^4.6", "laravel/tinker": "^2.5", diff --git a/composer.lock b/composer.lock index 0ecad16b..a56a6754 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": "29bedcb18d7ccd2dfe99f2588933e5bf", + "content-hash": "00787fb9d916c7cb0b4ae64647fa0188", "packages": [ { "name": "asm89/stack-cors", @@ -1773,6 +1773,78 @@ }, "time": "2022-02-16T14:40:23+00:00" }, + { + "name": "laravel/scout", + "version": "v9.4.5", + "source": { + "type": "git", + "url": "https://github.com/laravel/scout.git", + "reference": "ac962d2e052e90ca271e9bb1b30229ed870c4963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/scout/zipball/ac962d2e052e90ca271e9bb1b30229ed870c4963", + "reference": "ac962d2e052e90ca271e9bb1b30229ed870c4963", + "shasum": "" + }, + "require": { + "illuminate/bus": "^8.0|^9.0", + "illuminate/contracts": "^8.0|^9.0", + "illuminate/database": "^8.0|^9.0", + "illuminate/http": "^8.0|^9.0", + "illuminate/pagination": "^8.0|^9.0", + "illuminate/queue": "^8.0|^9.0", + "illuminate/support": "^8.0|^9.0", + "php": "^7.3|^8.0" + }, + "require-dev": { + "meilisearch/meilisearch-php": "^0.19", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^6.17|^7.0", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "algolia/algoliasearch-client-php": "Required to use the Algolia engine (^2.2).", + "meilisearch/meilisearch-php": "Required to use the MeiliSearch engine (^0.17)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.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" + ], + "support": { + "issues": "https://github.com/laravel/scout/issues", + "source": "https://github.com/laravel/scout" + }, + "time": "2022-02-22T16:20:15+00:00" + }, { "name": "laravel/serializable-closure", "version": "v1.1.1", diff --git a/config/scout.php b/config/scout.php new file mode 100644 index 00000000..5c8b7d20 --- /dev/null +++ b/config/scout.php @@ -0,0 +1,137 @@ + env('SCOUT_DRIVER', 'algolia'), + + /* + |-------------------------------------------------------------------------- + | 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), + + /* + |-------------------------------------------------------------------------- + | Database Transactions + |-------------------------------------------------------------------------- + | + | This configuration option determines if your data will only be synced + | with your search indexes after every open database transaction has + | been committed, thus preventing any discarded data from syncing. + | + */ + + 'after_commit' => 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', ''), + ], + + /* + |-------------------------------------------------------------------------- + | MeiliSearch Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure your MeiliSearch settings. MeiliSearch is an open + | source search engine with minimal configuration. Below, you can state + | the host and key information for your own MeiliSearch installation. + | + | See: https://docs.meilisearch.com/guides/advanced_guides/configuration.html + | + */ + + 'meilisearch' => [ + 'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'), + 'key' => env('MEILISEARCH_KEY', null), + ], + +]; diff --git a/database/migrations/2022_03_15_183358_create_jobs_table.php b/database/migrations/2022_03_15_183358_create_jobs_table.php new file mode 100644 index 00000000..a786a891 --- /dev/null +++ b/database/migrations/2022_03_15_183358_create_jobs_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs'); + } +}; diff --git a/resources/views/community.blade.php b/resources/views/community.blade.php index 0fa32407..e1929d4b 100644 --- a/resources/views/community.blade.php +++ b/resources/views/community.blade.php @@ -25,8 +25,8 @@ class="px-4 border-r border-gray-200 text-gray-500 focus:outline-none focus:ring
{{$r->body}}
+