add new search engine

This commit is contained in:
ludo
2024-01-31 23:45:58 +01:00
parent 8eb3104b2a
commit 067532b6fc
5 changed files with 59 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Models\Shop;
use App\Models\Botanic\Specie;
use App\Models\Botanic\Variety;
use App\Repositories\Shop\Articles;
use App\Traits\Model\HasComments;
use App\Traits\Model\Imageable;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
@@ -15,6 +16,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kirschbaum\PowerJoins\PowerJoins;
use Laravel\Scout\Searchable;
use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
use Spatie\MediaLibrary\HasMedia;
@@ -31,6 +33,7 @@ class Article extends Model implements HasMedia
use Imageable;
use Powerjoins;
use RevisionableTrait;
use Searchable;
use SoftDeletes;
use Taggable;
use UserStamps;
@@ -192,7 +195,31 @@ class Article extends Model implements HasMedia
public function scopeWithAvailableOffers($query, $saleChannelId = false)
{
return $query->whereHas('offers', function ($query) use ($saleChannelId) {
$query->active()->byStockAvailable()->bySaleChannel($saleChannelId);
$query->active()->byStockAvailable();
if ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
}
});
}
public function toSearchableArray(): array
{
$description = $this->description;
$product = $this->product ?? false;
if (is_object($product)) {
$description .= ' ' . $product ? $product->description : '';
$description .= ' ' . $product ? $product->plus ?? '' : '';
$specie = $product ? $product->specie : false;
$description .= ' ' . $specie ? $specie->description ?? '' : '';
}
return [
'id' => (int) $this->id,
'name' => $this->name,
'description' => html_entity_decode(strip_tags($description)),
];
}
}

View File

@@ -2,8 +2,14 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Article;
class Searches
{
public static function search($query)
{
return Article::withAvailableOffers()->search($query)->get();
}
public static function getResults($options)
{
return Articles::getArticlesToSell($options);

View File

@@ -36,6 +36,7 @@
"gzero/eloquent-tree": "^3.1",
"hassankhan/config": "^3.1",
"htmlmin/htmlmin": "^9.0",
"http-interop/http-factory-guzzle": "^1.2",
"intervention/image": "^2.7",
"jasonlewis/expressive-date": "^1.0",
"jenssegers/date": "^4.0",
@@ -59,6 +60,7 @@
"league/period": "^5.3",
"livewire/livewire": "^2.12",
"maatwebsite/excel": "^3.1",
"meilisearch/meilisearch-php": "^1.6",
"moneyphp/money": "^4.3",
"mpdf/mpdf": "^8.2",
"mpociot/teamwork": "^8.1",

View File

@@ -1,5 +1,7 @@
<?php
use App\Models\Shop\Article;
return [
/*
@@ -132,6 +134,12 @@ return [
'meilisearch' => [
'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
'key' => env('MEILISEARCH_KEY', null),
'index-settings' => [
Article::class => [
'filterableAttributes'=> ['id', 'name', 'description'],
'sortableAttributes' => ['created_at'],
],
],
],
];

View File

@@ -0,0 +1,15 @@
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//192.168.1.10:2080/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->