なんもわからんわー
This commit is contained in:
parent
d69fe6a22a
commit
c7aa002625
50
app/Console/Commands/NormalizeTags.php
Normal file
50
app/Console/Commands/NormalizeTags.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Tag;
|
||||
use App\Utilities\Formatter;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NormalizeTags extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'tissue:tag:normalize';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Normalize tags';
|
||||
|
||||
private $formatter;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Formatter $formatter)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach (Tag::query()->orderBy('name')->cursor() as $tag) {
|
||||
$normalizedName = $this->formatter->normalizeToSearchIndex($tag->name);
|
||||
$this->line("{$tag->name} : {$normalizedName}");
|
||||
}
|
||||
}
|
||||
}
|
@ -132,4 +132,15 @@ class Formatter
|
||||
|
||||
return $bytes . 'B';
|
||||
}
|
||||
|
||||
public function normalizeToSearchIndex(string $text): string
|
||||
{
|
||||
$text = \Normalizer::normalize($text, \Normalizer::FORM_KC);
|
||||
// $text = \Transliterator::create('Katakana-Hiragana')->transliterate($text);
|
||||
$text = mb_convert_kana($text, 'c');
|
||||
$text = preg_replace('/[^\p{L}\p{N}]/u', '', $text);
|
||||
$text = mb_strtolower($text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user