Skip to content

Commit

Permalink
Merge pull request #53 from WillTheDeveloper/scout-search
Browse files Browse the repository at this point in the history
Scout search
  • Loading branch information
WillTheDeveloper authored Mar 15, 2022
2 parents b655311 + d0bc2e0 commit 114443d
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 20 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/Community.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
10 changes: 9 additions & 1 deletion app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
74 changes: 73 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions config/scout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default Search Engine
|--------------------------------------------------------------------------
|
| This option controls the default search connection that gets used while
| using Laravel Scout. This connection is used when syncing all models
| to the search service. You should adjust this based on your needs.
|
| Supported: "algolia", "meilisearch", "database", "collection", "null"
|
*/

'driver' => 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),
],

];
36 changes: 36 additions & 0 deletions database/migrations/2022_03_15_183358_create_jobs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->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');
}
};
53 changes: 49 additions & 4 deletions resources/views/community.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class="px-4 border-r border-gray-200 text-gray-500 focus:outline-none focus:ring
</button>
<div class="flex-1 flex justify-between px-4 sm:px-6 lg:px-8">
<div class="flex-1 flex">
<form class="w-full flex md:ml-0" action="#" method="GET">
<label for="search-field" class="sr-only">Search</label>
<form class="w-full flex md:ml-0" action="{{route('community.search')}}" method="GET">
<label for="search" class="sr-only">Search</label>
<div class="relative w-full text-gray-400 focus-within:text-gray-600">
<div class="absolute inset-y-0 left-0 flex items-center pointer-events-none">
<!-- Heroicon name: solid/search -->
Expand All @@ -37,7 +37,7 @@ class="px-4 border-r border-gray-200 text-gray-500 focus:outline-none focus:ring
clip-rule="evenodd"/>
</svg>
</div>
<input id="search-field" name="search-field"
<input id="search" name="search"
class="block w-full h-full pl-8 pr-3 py-2 border-transparent text-gray-900 placeholder-gray-500 focus:outline-none focus:ring-0 focus:border-transparent focus:placeholder-gray-400 sm:text-sm"
placeholder="Search" type="search">
</div>
Expand Down Expand Up @@ -211,7 +211,52 @@ class="group flex items-center px-3 py-2 text-sm font-medium text-gray-600 round
</div>
</nav>
</div>
<main class="lg:col-span-9 xl:col-span-6">
<main class="lg:col-span-9 xl:col-span-6" x-data="{look: false}" @keyup.shift.enter.window="look = true" @keyup.esc.window="look = false">





<div x-cloak x-show="look">
<div class="fixed inset-0 z-10 overflow-y-auto p-4 sm:p-6 md:p-20" role="dialog" aria-modal="true">
<!--
Background overlay, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0"
To: "opacity-100"
Leaving: "ease-in duration-200"
From: "opacity-100"
To: "opacity-0"
-->
<div class="fixed inset-0 bg-gray-500 bg-opacity-25 transition-opacity" aria-hidden="true"></div>

<!--
Command palette, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0 scale-95"
To: "opacity-100 scale-100"
Leaving: "ease-in duration-200"
From: "opacity-100 scale-100"
To: "opacity-0 scale-95"
-->
<div class="mx-auto max-w-xl transform divide-y divide-gray-100 overflow-hidden rounded-xl bg-white shadow-2xl ring-1 ring-black ring-opacity-5 transition-all">
<form action="{{route('community.search')}}" method="get">
<div class="relative">
<!-- Heroicon name: solid/search -->
<svg class="pointer-events-none absolute top-3.5 left-4 h-5 w-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
</svg>
<input id="search" name="search" type="search" class="h-12 w-full border-0 bg-transparent pl-11 pr-4 text-gray-800 placeholder-gray-400 focus:ring-0 sm:text-sm" placeholder="Search..." role="combobox" aria-expanded="false" aria-controls="options">
</div>
</form>
</div>
</div>
</div>



<div class="px-4 sm:px-0">
<div class="sm:hidden">
<label for="question-tabs" class="sr-only">Select a tab</label>
Expand Down
Loading

0 comments on commit 114443d

Please sign in to comment.