Files
materio-d9/web/modules/custom/materio_sapi/materio_sapi.install
T
bachirandClaude Opus 5.5 7786c2cf71 materio_sapi: neighbours cut relative to the search, OR query as fallback (H6)
- ScoreCut: the kNN search scores every visible node; keep the ones above
  the mean of this search by more than 2 standard deviations. A fixed
  threshold meant nothing (at 0.7, « bois » 664 nodes, « wood » 4 671);
  with k = 2, 373 and 382. Exact matches stay first.
- OR query off (OR_WITH_KNN), kept as the fallback when there are no
  neighbours: model stopped, slow or switched off, term chosen in the
  autocomplete.
- S4: 355 results (1 104), same exact matches; S5: 248 (3 338), better
  top results, 0.27 s instead of 1.3 s.
- Message « X exact result(s) out of N relevant result(s) for "…" », French
  text added by materio_sapi_update_11001 (translations live in the DB).
- ScoreCutTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
2026-11-17 19:56:53 +01:00

45 lines
1.4 KiB
PHP

<?php
/**
* @file
* Install, update and uninstall functions for materio_sapi.
*/
declare(strict_types=1);
/**
* Source of the search message (H6) and its French translation.
*
* Interface translations live in the database, not in the repository: the
* update brings the French text to every site.
*/
function materio_sapi_search_infos_strings(): array {
return [
'source' => '@exactmatchcount exact result(s) out of @count relevant result(s) for “@keys”',
'fr' => '@exactmatchcount résultat(s) exact(s) sur @count résultat(s) pertinent(s) pour « @keys »',
];
}
/**
* Adds the French translation of the new search message (H6).
*/
function materio_sapi_update_11001(): string {
if (!\Drupal::moduleHandler()->moduleExists('locale')) {
return 'locale is off: nothing to translate.';
}
$strings = materio_sapi_search_infos_strings();
$storage = \Drupal::service('locale.storage');
$source = $storage->findString(['source' => $strings['source'], 'context' => '']);
if (!$source) {
$source = $storage->createString(['source' => $strings['source'], 'context' => ''])->save();
}
$storage->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => $strings['fr'],
'customized' => LOCALE_CUSTOMIZED,
])->save();
_locale_refresh_translations(['fr'], [$source->lid]);
return 'French translation of the search message added.';
}