search fix

This commit is contained in:
Simon Pocrnjič 2024-11-21 21:08:47 +01:00
parent 713bd9ffe3
commit 09fcac7cb5
11 changed files with 126 additions and 262 deletions

View File

@ -35,14 +35,10 @@ protected function makeAllSearchableUsing(Builder $query): Builder
public function toSearchableArray(): array
{
$array = $this->toArray();
$array['person'] = $this->person ? $this->person->only(['full_name', 'tax_number', 'social_security_number']): null;
$array['person_addresses'] = $this->person->addresses ? $this->person->addresses->only(['adddress'])->toArray() : [];
$array['person_phones'] = $this->person->phones ? $this->person->phones->only(['nu'])->toArray() : [];
return $array;
return [
'person.full_name' => '',
'person_addresses.address' => ''
];
}

View File

@ -34,13 +34,10 @@ protected function makeAllSearchableUsing(Builder $query): Builder
public function toSearchableArray(): array
{
$array = $this->toArray();
$array['person'] = $this->person ? $this->person->only(['full_name', 'tax_number', 'social_security_number']): null;
$array['person_addresses'] = $this->person->addresses ? $this->person->addresses->only(['adddress'])->toArray() : [];
$array['person_phones'] = $this->person->phones ? $this->person->phones->only(['nu'])->toArray() : [];
return $array;
return [
'person.full_name' => ''
];
}
public function client(): BelongsTo

View File

@ -63,11 +63,11 @@ protected function makeAllSearchableUsing(Builder $query): Builder
public function toSearchableArray(): array
{
return [
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'full_name' => $this->full_name,
'addresses' => $this->addresses,
'phones' => $this->phones
'first_name' => '',
'last_name' => '',
'full_name' => '',
'person_addresses.address' => '',
'person_phones.nu' => ''
];
}

View File

@ -6,7 +6,6 @@
"license": "MIT",
"require": {
"php": "^8.2",
"algolia/scout-extended": "3.1",
"arielmejiadev/larapex-charts": "^2.1",
"diglactic/laravel-breadcrumbs": "^9.0",
"http-interop/http-factory-guzzle": "^1.2",

206
composer.lock generated
View File

@ -4,163 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c042c0c871352d0b2fbd12893a3cb9ae",
"content-hash": "1125fcd2a303fd68a7e84ac445b3b914",
"packages": [
{
"name": "algolia/algoliasearch-client-php",
"version": "3.4.1",
"source": {
"type": "git",
"url": "https://github.com/algolia/algoliasearch-client-php.git",
"reference": "cf87b649f745479c0800299481d91dc303e23cea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/algolia/algoliasearch-client-php/zipball/cf87b649f745479c0800299481d91dc303e23cea",
"reference": "cf87b649f745479c0800299481d91dc303e23cea",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": "^7.3 || ^8.0",
"psr/http-message": "^1.1 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"fzaninotto/faker": "^1.8",
"phpunit/phpunit": "^8.0 || ^9.0",
"symfony/yaml": "^2.0 || ^4.0"
},
"suggest": {
"guzzlehttp/guzzle": "If you prefer to use Guzzle HTTP client instead of the Http Client implementation provided by the package"
},
"bin": [
"bin/algolia-doctor"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-2.0": "2.0.x-dev"
}
},
"autoload": {
"files": [
"src/Http/Psr7/functions.php",
"src/functions.php"
],
"psr-4": {
"Algolia\\AlgoliaSearch\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Algolia Team",
"email": "contact@algolia.com"
}
],
"description": "Algolia Search API Client for PHP",
"keywords": [
"algolia",
"api",
"client",
"php",
"search"
],
"support": {
"issues": "https://github.com/algolia/algoliasearch-client-php/issues",
"source": "https://github.com/algolia/algoliasearch-client-php/tree/3.4.1"
},
"time": "2023-08-28T14:34:04+00:00"
},
{
"name": "algolia/scout-extended",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/algolia/scout-extended.git",
"reference": "74d8c73955c07ce52633f74005624545239a9522"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/algolia/scout-extended/zipball/74d8c73955c07ce52633f74005624545239a9522",
"reference": "74d8c73955c07ce52633f74005624545239a9522",
"shasum": ""
},
"require": {
"algolia/algoliasearch-client-php": "^3.0.0",
"ext-json": "*",
"illuminate/console": "^9.0|^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/database": "^9.0|^10.0|^11.0",
"illuminate/filesystem": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"laravel/scout": "^9.0|^10.0",
"php": "^8.0",
"riimu/kit-phpencoder": "^2.4"
},
"require-dev": {
"fakerphp/faker": "^1.13",
"laravel/legacy-factories": "^1.1",
"mockery/mockery": "^1.4",
"nunomaduro/larastan": "^1.0|^2.0",
"orchestra/testbench": "^4.9|^5.9|^6.6|^7.0|^8.0|^9.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.0|^9.0|^10.5"
},
"suggest": {
"ext-dom": "Required to use the HTML Splitter."
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Algolia\\ScoutExtended\\ScoutExtendedServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Algolia\\ScoutExtended\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nuno Maduro",
"email": "enunomaduro@gmail.com"
},
{
"name": "Algolia Team",
"email": "contact@algolia.com"
}
],
"description": "Scout Extended extends Laravel Scout adding algolia-specific features",
"keywords": [
"algolia",
"analytics",
"extended",
"laravel",
"places",
"scout",
"search"
],
"support": {
"issues": "https://github.com/algolia/scout-extended/issues",
"source": "https://github.com/algolia/scout-extended/tree/v3.1.0"
},
"time": "2024-03-21T14:34:08+00:00"
},
{
"name": "arielmejiadev/larapex-charts",
"version": "2.1.1",
@ -4294,55 +4139,6 @@
],
"time": "2024-04-27T21:32:50+00:00"
},
{
"name": "riimu/kit-phpencoder",
"version": "v2.4.2",
"source": {
"type": "git",
"url": "https://github.com/Riimu/Kit-PHPEncoder.git",
"reference": "72ff7825de193b272e17b228394819dbfc638e72"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Riimu/Kit-PHPEncoder/zipball/72ff7825de193b272e17b228394819dbfc638e72",
"reference": "72ff7825de193b272e17b228394819dbfc638e72",
"shasum": ""
},
"require": {
"php": ">=5.6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Riimu\\Kit\\PHPEncoder\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Riikka Kalliomäki",
"email": "riikka.kalliomaki@gmail.com",
"homepage": "http://riimu.net"
}
],
"description": "Highly customizable alternative to var_export for PHP code generation",
"homepage": "http://kit.riimu.net",
"keywords": [
"code",
"encoder",
"export",
"generator",
"variable"
],
"support": {
"issues": "https://github.com/Riimu/Kit-PHPEncoder/issues",
"source": "https://github.com/Riimu/Kit-PHPEncoder/tree/v2.4.2"
},
"time": "2022-12-10T18:12:25+00:00"
},
{
"name": "robertboes/inertia-breadcrumbs",
"version": "0.6.0",

View File

@ -113,8 +113,8 @@
*/
'algolia' => [
'id' => env('ALGOLIA_APP_ID', 'ZDAXR87LZV'),
'secret' => env('ALGOLIA_SECRET', '8797318d18e10541ad15d49ae1e64db2'),
'id' => env('ALGOLIA_APP_ID', ''),
'secret' => env('ALGOLIA_SECRET', ''),
],
/*

View File

@ -15,7 +15,7 @@ public function up(): void
$table->id();
$table->date('due_date')->nullable();
$table->decimal('amount', 8, 4)->nullable();
$table->text('note')->default('');
$table->text('note')->nullable()->default('');
$table->foreignIdFor(\App\Models\Action::class);
$table->foreignIdFor(\App\Models\Decision::class);
$table->foreignIdFor(\App\Models\ClientCase::class);

View File

@ -147,7 +147,7 @@ public function run(): void
'user_id' => 1
])->clientCase()->create(
[
'client_id' => 4
'client_id' => 2
]
);
@ -166,7 +166,7 @@ public function run(): void
'user_id' => 1
])->clientCase()->create(
[
'client_id' => 4
'client_id' => 2
]
);

View File

@ -40,7 +40,7 @@ const onSearchFocus = () => {
}
const onSearchBlue = () => {
setTimeout(() => querySearchList.value = true, 100)
setTimeout(() => querySearchList.value = true, 300)
}
watch(querySearch, debounce((value) => {
@ -129,25 +129,25 @@ watch(querySearch, debounce((value) => {
</fwb-input>
<fwb-list-group ref="querySearchDiv" class="absolute" :hidden="querySearchList">
<fwb-list-group-item>
<div>
<p>Naročniki:</p>
<fwb-list-group>
<fwb-list-group-item hover v-for="client in querySearchResult.clients">
<a :href="route('client.show', {uuid: client.uuid})">{{ client.person.full_name }}</a>
</fwb-list-group-item>
</fwb-list-group>
</div>
<fwb-list-group-item class="px-0 flex flex-col">
<p>Naročniki:</p>
<fwb-list-group>
<fwb-list-group-item hover v-for="client in querySearchResult.clients">
<a :href="route('client.show', {uuid: client.client_uuid})">{{ client.full_name }}</a>
</fwb-list-group-item>
</fwb-list-group>
</fwb-list-group-item>
<fwb-list-group-item>
<div>
<p>Primeri:</p>
<fwb-list-group>
<fwb-list-group-item hover v-for="clientCase in querySearchResult.client_cases">
<a :href="route('clientCase.show', {uuid: clientCase.uuid})">{{ clientCase.person.full_name }}</a>
</fwb-list-group-item>
</fwb-list-group>
</div>
<fwb-list-group-item class="px-0 flex flex-col">
<p>Primeri:</p>
<fwb-list-group>
<fwb-list-group-item hover v-for="clientCase in querySearchResult.client_cases">
<a :href="route('clientCase.show', {uuid: clientCase.case_uuid})">{{ clientCase.full_name }}</a>
</fwb-list-group-item>
</fwb-list-group>
</fwb-list-group-item>
</fwb-list-group>
</div>
@ -313,6 +313,42 @@ watch(querySearch, debounce((value) => {
</template>
</template>
</div>
<div class="px-2 w-full relative">
<fwb-input
v-model="querySearch"
placeholder="Iskalnik..."
size="md"
@focus="onSearchFocus"
@blur="onSearchBlue"
>
<template #prefix>
<SearchIcon />
</template>
</fwb-input>
<fwb-list-group ref="querySearchDiv" class="absolute px-2 w-full mx-auto" :hidden="querySearchList">
<fwb-list-group-item class="px-0 flex flex-col">
<p>Naročniki:</p>
<fwb-list-group class="w-full">
<fwb-list-group-item hover v-for="client in querySearchResult.clients">
<a :href="route('client.show', {uuid: client.client_uuid})">{{ client.full_name }}</a>
</fwb-list-group-item>
</fwb-list-group>
</fwb-list-group-item>
<fwb-list-group-item class="px-0 flex flex-col">
<p>Primeri:</p>
<fwb-list-group class="w-full">
<fwb-list-group-item hover v-for="clientCase in querySearchResult.client_cases">
<a :href="route('clientCase.show', {uuid: clientCase.case_uuid})">{{ clientCase.full_name }}</a>
</fwb-list-group-item>
</fwb-list-group>
</fwb-list-group-item>
</fwb-list-group>
</div>
</div>
</div>
</nav>

View File

@ -6,11 +6,11 @@
use App\Http\Controllers\ContractController;
use App\Http\Controllers\SettingController;
use App\Models\Person\Person;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use ArielMejiaDev\LarapexCharts\LarapexChart;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use \Illuminate\Database\Eloquent\Builder;
Route::redirect('/', 'login');
@ -45,27 +45,49 @@
Route::get('search', function(Request $request) {
if( !empty($request->input('query')) ) {
/*$clients = App\Models\Client::search($request->input('query'))
->query(function($q) use($request) {
$q->with('person')->limit($request->input('limit'));
->query( function($builder) use($request){
$builder->leftJoin('person', 'clients.person_id', '=', 'person.id')
->leftJoin('person_addresses', 'person_addresses.person_id', '=', 'person.id')
->select('clients.*', 'person.full_name as person_fullname')
->limit($request->input('limit'));
})
->get();*/
$clients = App\Models\Client::search($request->input('query'))
->query( fn(Builder $builder) =>
$builder->with('person:id,full_name')->limit($request->input('limit'))
)
->get();
$clientCases = App\Models\ClientCase::search($request->input('query'))
->query( fn(Builder $builder) =>
$builder->with('person:id,full_name')->limit($request->input('limit'))
)
->query(function($builder) use($request){
$builder->join('person', 'client_cases.person_id', '=', 'person.id')
->select('client_cases.*', 'person.full_name as person_fullname')
->limit($request->input('limit'));
})
->get();*/
$clients = App\Models\Person\Person::search($request->input('query'))
->query(function($builder) use($request): void {
$builder->join('clients', 'person.id', '=', 'clients.person_id')
->leftJoin('person_addresses', 'person.id', '=', 'person_addresses.person_id')
->leftJoin('person_phones', 'person.id', '=', 'person_phones.person_id')
->select('person.*', 'clients.uuid as client_uuid')
->limit($request->input('limit'));
})
->get();
$clientCases = App\Models\Person\Person::search($request->input('query'))
->query(function($builder) use($request): void {
$builder->join('client_cases', 'person.id', '=', 'client_cases.person_id')
->leftJoin('person_addresses', 'person.id', '=', 'person_addresses.person_id')
->leftJoin('person_phones', 'person.id', '=', 'person_phones.person_id')
->select('person.*', 'client_cases.uuid as case_uuid')
->limit($request->input('limit'));
})
->get();
return [
'clients' => $clients,
'client_cases' => $clientCases
'client_cases' => $clientCases,
'query' => $request->input('query')
];
}

View File

@ -0,0 +1,18 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class StringNormalizerTest extends TestCase
{
/**
* A basic feature test example.
*/
public function test_example(): void
{
$this->assertTrue(\Normalizer::normalize('Naročnik'));
}
}