Feature: Product Search Service Updates
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Command;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Laravel\Scout\EngineManager;
|
||||
use Laravel\Scout\Engines\MeilisearchEngine;
|
||||
use Lunar\Models\Product;
|
||||
|
||||
/**
|
||||
* lunarphp/meilisearch's own `lunar:meilisearch:setup` only pushes
|
||||
* filterableAttributes/sortableAttributes (see MeilisearchSetup::handle())
|
||||
* — it has no notion of typo tolerance or prefix search, and Meilisearch's
|
||||
* defaults for both are loose enough to produce bad matches on short Greek
|
||||
* words. Confirmed via showMatchesPosition that a query for "Κάπτεν" was
|
||||
* matching "κανένας" purely through prefixSearch's default 'indexingTime'
|
||||
* behavior (their edit distance is far past anything typo tolerance would
|
||||
* bridge) — fixed by disabling prefix search below, verified afterward with
|
||||
* "Super"/"Superheroes"-style prefix probes returning no results for a
|
||||
* partial word. minWordSizeForTypos is tightened defensively alongside it
|
||||
* so short words in general get less typo-tolerant fuzzing, even though a
|
||||
* separate short-word collision case ("Κάπτεν" vs "κάποτε", high letter
|
||||
* overlap despite real edit distance) persisted after both settings were
|
||||
* confirmed live and wasn't fully root-caused — treated as a known,
|
||||
* narrow edge case rather than a blocker. Run this after
|
||||
* `lunar:meilisearch:setup`, whenever Product's index needs
|
||||
* (re)provisioning.
|
||||
*
|
||||
* Disabling prefix search here is a deliberate tradeoff: it also turns off
|
||||
* legitimate partial-word matching (typing "car" matching "cart" before
|
||||
* you finish the word) — useful for a future autocomplete/search-as-you-
|
||||
* type UI. If that's built later, re-enable prefixSearch deliberately then,
|
||||
* informed by real UX needs, rather than leaving it on by accident today.
|
||||
*/
|
||||
class TuneProductSearchCommand extends Command
|
||||
{
|
||||
protected $signature = 'lunar:meilisearch:tune-product-search';
|
||||
|
||||
protected $description = 'Tighten typo-tolerance and disable prefix search on the product search index';
|
||||
|
||||
public function handle(EngineManager $engineManager): void
|
||||
{
|
||||
/** @var MeilisearchEngine $engine */
|
||||
$engine = $engineManager->createMeilisearchDriver();
|
||||
|
||||
$index = $engine->getIndex((new Product)->searchableAs());
|
||||
|
||||
$this->components->info('Updating typo tolerance for product search...');
|
||||
|
||||
$task = $index->updateTypoTolerance([
|
||||
'minWordSizeForTypos' => [
|
||||
'oneTypo' => 8,
|
||||
'twoTypos' => 12,
|
||||
],
|
||||
]);
|
||||
|
||||
$engine->waitForTask($task['taskUid']);
|
||||
|
||||
$this->components->info('Disabling prefix search for product search...');
|
||||
|
||||
$task = $index->updatePrefixSearch('disabled');
|
||||
|
||||
$engine->waitForTask($task['taskUid']);
|
||||
|
||||
$this->components->info('Product search index tuned.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user