Compare commits
8
Commits
b214fefa51
..
stage
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36086fd191 | ||
|
|
7755ff3f01 | ||
|
|
91d03b44ce | ||
|
|
030fe5ee86 | ||
|
|
2e93c5c0f8 | ||
|
|
9557b6bd0b | ||
|
|
e597cde3f3 | ||
|
|
a00da727f8 |
@@ -12,6 +12,8 @@ web/modules/dev/*.tar.gz
|
||||
# Ignore sensitive information
|
||||
/web/sites/*/settings.php
|
||||
/web/sites/*/settings.local.php
|
||||
# Local backups of the settings files
|
||||
/web/sites/*/settings*.php.bak*
|
||||
/web/sites/*/services*.yml
|
||||
|
||||
# Ignore Drupal's file directory
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
description: 'L''inspiration par la matière'
|
||||
urls_to_cache: "/fr/pricing\r\n/fr/blabla\r\n/fr/base\r\n/fr/showrooms"
|
||||
start_url: /
|
||||
lang: fr
|
||||
cache_version: '1'
|
||||
@@ -1,20 +0,0 @@
|
||||
site_name: materiO
|
||||
short_name: materiO
|
||||
description: 'The material library your projects deserve'
|
||||
start_url: /
|
||||
lang: fr
|
||||
theme_color: '#ffffff'
|
||||
background_color: '#ffffff'
|
||||
display: standalone
|
||||
default_image: '0'
|
||||
urls_to_cache: "/en/pricing\r\n/en/blabla\r\n/en/base\r\n/en/showrooms"
|
||||
urls_to_exclude: "admin/.*\r\nuser/.*"
|
||||
offline_page: /offline
|
||||
cache_version: '2'
|
||||
cross_origin: false
|
||||
skip_waiting: false
|
||||
_core:
|
||||
default_config_hash: cP1TZQyv1WdET3iepl2QoyOPK7VeO0xHm0lU_FU1Wmc
|
||||
image: /sites/default/files/pwa/materiopwaicon.png
|
||||
image_small: /sites/default/files/pwa/materiopwaicon.pngcopy.png
|
||||
image_very_small: /sites/default/files/pwa/materiopwaicon.pngcopy2.png
|
||||
@@ -1,23 +0,0 @@
|
||||
touch_icons:
|
||||
touch-icon-default: touch-icon-default
|
||||
meta_tags:
|
||||
meta-capable: meta-capable
|
||||
meta-status-bar-style: meta-status-bar-style
|
||||
color_select: black_translucent
|
||||
home_screen_icons:
|
||||
iphone5-splash: iphone5-splash
|
||||
iphone6-splash: iphone6-splash
|
||||
iphoneplus-splash: iphoneplus-splash
|
||||
iphonex-splash: iphonex-splash
|
||||
iphonexr-splash: iphonexr-splash
|
||||
iphonexsmax-splash: iphonexsmax-splash
|
||||
ipad-splash: ipad-splash
|
||||
ipadpro1-splash: ipadpro1-splash
|
||||
ipadpro2-splash: ipadpro2-splash
|
||||
ipadpro3-splash: ipadpro3-splash
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- pwa_extras
|
||||
_core:
|
||||
default_config_hash: TOeFdF8Tjq2HqBmUgrTH06d7ZpY5qNLHZTLPIaCVsEk
|
||||
@@ -1,8 +1,8 @@
|
||||
status: 1
|
||||
pattern: "<?php\r\nreturn t('Home');\r\n\r\n?>"
|
||||
pattern: Home
|
||||
escape: false
|
||||
dependencies:
|
||||
config:
|
||||
- node.type.frontpage
|
||||
new_content_behavior: 1
|
||||
php: true
|
||||
php: false
|
||||
|
||||
@@ -11,6 +11,7 @@ dependencies:
|
||||
- field.storage.node.field_short_description
|
||||
- field.storage.node.field_tags
|
||||
- field.storage.node.field_thesaurus
|
||||
- field.storage.taxonomy_term.field_public_address
|
||||
- field.storage.taxonomy_term.field_synonyms
|
||||
- search_api.server.materio
|
||||
module:
|
||||
@@ -77,6 +78,17 @@ field_settings:
|
||||
dependencies:
|
||||
module:
|
||||
- node
|
||||
distributor_country:
|
||||
label: 'Distributor » Country'
|
||||
datasource_id: 'entity:node'
|
||||
property_path: 'field_distributor:entity:field_public_address:country_code'
|
||||
type: string
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_distributor
|
||||
- field.storage.taxonomy_term.field_public_address
|
||||
module:
|
||||
- taxonomy
|
||||
field_country_name_computed:
|
||||
label: 'Country Name'
|
||||
datasource_id: 'entity:node'
|
||||
@@ -111,6 +123,17 @@ field_settings:
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_short_description
|
||||
manufacturer_country:
|
||||
label: 'Manufacturer » Country'
|
||||
datasource_id: 'entity:node'
|
||||
property_path: 'field_manufacturer:entity:field_public_address:country_code'
|
||||
type: string
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_manufacturer
|
||||
- field.storage.taxonomy_term.field_public_address
|
||||
module:
|
||||
- taxonomy
|
||||
name:
|
||||
label: 'Manufacturer » Terme de taxonomie » Nom'
|
||||
datasource_id: 'entity:node'
|
||||
@@ -418,9 +441,11 @@ processor_settings:
|
||||
preprocess_query: -20
|
||||
all_fields: false
|
||||
aggregated_field: { }
|
||||
auto_aggregated_fulltext_field: { }
|
||||
content_access:
|
||||
weights:
|
||||
preprocess_query: -50
|
||||
custom_value: { }
|
||||
double_quote_workaround:
|
||||
weights:
|
||||
postprocess_query: 0
|
||||
@@ -443,16 +468,19 @@ processor_settings:
|
||||
- uuid
|
||||
replacement: '|9999999998|'
|
||||
entity_status: { }
|
||||
entity_type: { }
|
||||
html_filter:
|
||||
weights:
|
||||
preprocess_index: -15
|
||||
preprocess_query: -49
|
||||
all_fields: true
|
||||
fields:
|
||||
- distributor_country
|
||||
- field_country_name_computed
|
||||
- field_famille
|
||||
- field_reference
|
||||
- field_short_description
|
||||
- manufacturer_country
|
||||
- name
|
||||
- name_1
|
||||
- processed
|
||||
@@ -478,11 +506,11 @@ processor_settings:
|
||||
title: true
|
||||
alt: true
|
||||
tags:
|
||||
b: 2
|
||||
h1: 5
|
||||
h2: 3
|
||||
h3: 2
|
||||
strong: 2
|
||||
b: 2.0
|
||||
h1: 5.0
|
||||
h2: 3.0
|
||||
h3: 2.0
|
||||
strong: 2.0
|
||||
language_with_fallback: { }
|
||||
rendered_item: { }
|
||||
solr_date_range:
|
||||
@@ -493,6 +521,7 @@ tracker_settings:
|
||||
indexing_order: fifo
|
||||
options:
|
||||
cron_limit: 50
|
||||
delete_on_fail: true
|
||||
index_directly: true
|
||||
track_changes_in_references: true
|
||||
server: materio
|
||||
|
||||
@@ -52,6 +52,9 @@ final class NeighbourSearch {
|
||||
* Language of the results; the current language by default.
|
||||
* @param int $limit
|
||||
* Number of neighbours (topK).
|
||||
* @param callable|null $alter
|
||||
* Adds conditions to the Search API query, applied by Solr as pre-filters
|
||||
* of the kNN search (countries of materio_sapi, Q6).
|
||||
*
|
||||
* @return array<int, float>
|
||||
* Scores keyed by nid, best first, none when materio_ai is switched off.
|
||||
@@ -63,12 +66,12 @@ final class NeighbourSearch {
|
||||
* @throws \Drupal\search_api\SearchApiException
|
||||
* When Solr fails.
|
||||
*/
|
||||
public function search(string $phrase, ?string $langcode = NULL, int $limit = 100): array {
|
||||
public function search(string $phrase, ?string $langcode = NULL, int $limit = 100, ?callable $alter = NULL): array {
|
||||
// Switched off: no text is sent to the model, keyword results only.
|
||||
if (!$this->embedder->isEnabled()) {
|
||||
return [];
|
||||
}
|
||||
return $this->searchVector($this->embedder->embed($phrase), $langcode, $limit);
|
||||
return $this->searchVector($this->embedder->embed($phrase), $langcode, $limit, $alter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +83,7 @@ final class NeighbourSearch {
|
||||
* @return array<int, float>
|
||||
* Scores keyed by nid, best first.
|
||||
*/
|
||||
public function searchVector(array $vector, ?string $langcode = NULL, int $limit = 100): array {
|
||||
public function searchVector(array $vector, ?string $langcode = NULL, int $limit = 100, ?callable $alter = NULL): array {
|
||||
$dimension = (int) $this->configFactory->get('materio_ai.settings')->get('dimension');
|
||||
if (count($vector) !== $dimension || $limit <= 0) {
|
||||
return [];
|
||||
@@ -94,6 +97,9 @@ final class NeighbourSearch {
|
||||
// Only the item IDs are needed.
|
||||
$query->setOption('search_api_retrieved_field_values', ['search_api_id' => 'search_api_id']);
|
||||
$query->addTag(self::TAG);
|
||||
if ($alter) {
|
||||
$alter($query);
|
||||
}
|
||||
|
||||
$scores = [];
|
||||
foreach ($query->execute() as $item_id => $item) {
|
||||
|
||||
@@ -62,6 +62,13 @@ function materio_sapi_search_messages_strings(): array {
|
||||
=> '1 résultat exact pour « @keys »',
|
||||
$plural('@n exact result out of @total relevant results for “@keys”', '@n exact results out of @total relevant results for “@keys”')
|
||||
=> $plural('@n résultat exact sur @total résultats pertinents pour « @keys »', '@n résultats exacts sur @total résultats pertinents pour « @keys »'),
|
||||
// What makes a result exact, named (Q6, Q7).
|
||||
$plural('No exact result for @filters, @n close result for “@keys”', 'No exact result for @filters, @n close results for “@keys”')
|
||||
=> $plural('Aucun résultat exact pour @filters, @n résultat proche pour « @keys »', 'Aucun résultat exact pour @filters, @n résultats proches pour « @keys »'),
|
||||
'1 exact result for @filters: “@keys”'
|
||||
=> '1 résultat exact pour @filters : « @keys »',
|
||||
$plural('@n exact result for @filters, out of @total relevant results for “@keys”', '@n exact results for @filters, out of @total relevant results for “@keys”')
|
||||
=> $plural('@n résultat exact pour @filters, sur @total résultats pertinents pour « @keys »', '@n résultats exacts pour @filters, sur @total résultats pertinents pour « @keys »'),
|
||||
// Former text, French corrected ("le champs").
|
||||
'Please use the search form to search from our @count materials.'
|
||||
=> 'Utilisez le champ de recherche pour naviguer dans nos @count matériaux référencés.',
|
||||
@@ -93,3 +100,10 @@ function materio_sapi_update_11002(): string {
|
||||
_locale_refresh_translations(['fr'], $lids);
|
||||
return 'French translation of the search messages added.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the French translation of the messages naming the filters (Q6, Q7).
|
||||
*/
|
||||
function materio_sapi_update_11003(): string {
|
||||
return materio_sapi_update_11002();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\materio_ai\Exception\ModelPausedException;
|
||||
use Drupal\materio_sapi\CountryDetector;
|
||||
use Drupal\materio_sapi\KeywordText;
|
||||
use Drupal\materio_sapi\RankFusion;
|
||||
use Drupal\materio_sapi\ScoreCut;
|
||||
@@ -106,14 +107,29 @@ class Base extends ControllerBase {
|
||||
public const KNN_SIGMA = 2.0;
|
||||
|
||||
/**
|
||||
* Whether the OR query is merged with the neighbours (H3, H5).
|
||||
*
|
||||
* Off on trial since 17/11 (H6): on a phrase it matched about 40 % of the
|
||||
* catalogue. Kept: it still runs when there are no neighbours (model
|
||||
* stopped, slow or switched off, term chosen in the autocomplete), so that
|
||||
* the search answers as before.
|
||||
* For a single word typed, neighbours within this gap to the best score only
|
||||
* (Q9): « datte » kept 246 neighbours, 4 with it.
|
||||
*/
|
||||
public const OR_WITH_KNN = FALSE;
|
||||
public const KNN_SINGLE_WORD_MARGIN = 0.04;
|
||||
|
||||
/**
|
||||
* Best text matches merged with the neighbours (Q8).
|
||||
*
|
||||
* With the neighbours, the keyword query over every field (description
|
||||
* included) needs every word, not one of them (on a phrase, « one of them »
|
||||
* matched about 40 % of the catalogue, H6), and only its best matches are
|
||||
* fused: the model misses rare words found only in a description
|
||||
* (« métamorphose », 01/12). Without neighbours (model stopped, slow or
|
||||
* switched off) it runs as before: any word, every match.
|
||||
*/
|
||||
public const TEXT_WITH_KNN_LIMIT = 100;
|
||||
|
||||
/**
|
||||
* Weight of those text matches in the fusion, the neighbours weighing 1
|
||||
* (Q8): at equal weight they pushed BiMetal into the first five of
|
||||
* « textile qui change de couleur ».
|
||||
*/
|
||||
public const TEXT_WITH_KNN_WEIGHT = 1.0;
|
||||
|
||||
/**
|
||||
* Number of neighbours found, for the response tuning of H6.
|
||||
@@ -122,6 +138,52 @@ class Base extends ControllerBase {
|
||||
*/
|
||||
protected $knn_count = 0;
|
||||
|
||||
/**
|
||||
* Countries named in the phrase (Q6): ISO codes, and the phrase without them.
|
||||
*
|
||||
* @var array{codes: string[], forms: string[], rest: string}
|
||||
*/
|
||||
protected $countries = ['codes' => [], 'forms' => [], 'rest' => ''];
|
||||
|
||||
/**
|
||||
* Tags and thesaurus terms named like the countries found (japon, chine…).
|
||||
*
|
||||
* @var int[]|null
|
||||
*/
|
||||
private ?array $countryTermIds = NULL;
|
||||
|
||||
/**
|
||||
* Whether the queries are restricted to the countries found (Q6) and to the
|
||||
* terms chosen in the autocomplete (Q7).
|
||||
*/
|
||||
private bool $countryFilter = FALSE;
|
||||
|
||||
/**
|
||||
* Terms chosen in the autocomplete, as IDs (Q7).
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private array $termIds = [];
|
||||
|
||||
/**
|
||||
* What makes a result exact, for the message: names of the chosen terms,
|
||||
* countries as typed (Q6, Q7).
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private array $filterNames = [];
|
||||
|
||||
/**
|
||||
* Whether the whole phrase is a single word, stop words aside (Q9): a
|
||||
* country or a term is a word too, « pigment Italie » is two.
|
||||
*/
|
||||
private bool $singleWord = FALSE;
|
||||
|
||||
/**
|
||||
* Most terms taken from a request (Q7).
|
||||
*/
|
||||
public const MAX_TERMS = 10;
|
||||
|
||||
/**
|
||||
* The reference query, run before the others.
|
||||
*
|
||||
@@ -160,11 +222,11 @@ class Base extends ControllerBase {
|
||||
]);
|
||||
$cache = \Drupal::cache('materio_sapi');
|
||||
if ($cached = $cache->get($cid)) {
|
||||
[$this->results, $this->exactematch_count, $this->knn_count] = $cached->data;
|
||||
[$this->results, $this->exactematch_count, $this->knn_count, $this->filterNames] = $cached->data + [3 => []];
|
||||
return;
|
||||
}
|
||||
$this->sapiQuery();
|
||||
$cache->set($cid, [$this->results, $this->exactematch_count, $this->knn_count], \Drupal::time()->getRequestTime() + self::RANKING_LIFETIME, ['node_list']);
|
||||
$cache->set($cid, [$this->results, $this->exactematch_count, $this->knn_count, $this->filterNames], \Drupal::time()->getRequestTime() + self::RANKING_LIFETIME, ['node_list']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,37 +250,166 @@ class Base extends ControllerBase {
|
||||
}
|
||||
|
||||
// Keys without the references (« bois R0208 » searches « bois »).
|
||||
$words = KeywordText::words(preg_replace(self::REFERENCE_PATTERN, ' ', $this->phrase) ?? $this->phrase, $lang);
|
||||
$text = preg_replace(self::REFERENCE_PATTERN, ' ', $this->phrase) ?? $this->phrase;
|
||||
$words = KeywordText::words($text, $lang);
|
||||
// Only stop words: search the phrase as typed, as before.
|
||||
$keys = $words ? implode(' ', $words) : implode(' ', $this->keys);
|
||||
$this->singleWord = count(KeywordText::words($this->phrase, $lang)) === 1;
|
||||
|
||||
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
||||
// Exact material names (like "wood-skin"), then all words.
|
||||
$exact += $this->phraseQuery($keys, $lang);
|
||||
$exact += $this->andQuery($keys, $lang);
|
||||
// Terms chosen in the autocomplete (Q7) and a country named in the
|
||||
// phrase (Q6) are conditions, not keywords: « pigment Italie » searches
|
||||
// « pigment » among the records of Italian companies or tagged Italie;
|
||||
// [céramique] [translucide] japon searches « japon » among the records
|
||||
// that have both terms. The phrase keeps the names of the terms for the
|
||||
// titles and the model; the conditions use their IDs.
|
||||
$this->termIds = $this->chosenTermIds();
|
||||
$free = $this->termIds ? $this->withoutTermNames($text, $lang) : $text;
|
||||
$this->countries = CountryDetector::detect($free);
|
||||
$this->countryFilter = $this->termIds || $this->countries['codes'];
|
||||
$this->filterNames = [...$this->termNames($lang), ...$this->countries['forms']];
|
||||
$this->knn_count = 0;
|
||||
if (!$this->countryFilter) {
|
||||
[$nids, $uuids, $this->exactematch_count] = $this->rank($keys, $words, $lang, $exact, TRUE);
|
||||
}
|
||||
else {
|
||||
$rest = KeywordText::words($this->countries['rest'], $lang);
|
||||
if (!$rest) {
|
||||
// The terms or the country alone (« italien »): all their records.
|
||||
$exact += $this->countryQuery($lang);
|
||||
$this->exactematch_count = count($exact);
|
||||
$nids = array_keys($exact);
|
||||
$uuids = array_column($exact, 1, 0);
|
||||
}
|
||||
else {
|
||||
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
||||
// A title may hold the country (« papier japonais »): whole phrase.
|
||||
$exact += $this->phraseQuery($keys, $lang);
|
||||
}
|
||||
if ($this->termIds) {
|
||||
// Terms chosen are a filter asked for (Q7): all their records are
|
||||
// exact, the rest of the phrase only orders them. « bois-résiné
|
||||
// qui sent bon » gave no exact match and 2 of the 31 records of
|
||||
// the term on top, the others scattered or cut (01/12).
|
||||
[$nids, $uuids, $this->exactematch_count] = $this->termRecords(implode(' ', $rest), $rest, $lang, $exact);
|
||||
}
|
||||
else {
|
||||
// The records of the country first: their exact matches on the
|
||||
// rest of the phrase, then their neighbours…
|
||||
[$nids, $uuids, $this->exactematch_count] = $this->rank(implode(' ', $rest), $rest, $lang, $exact, FALSE);
|
||||
}
|
||||
}
|
||||
// …then the same search everywhere, so that the list does not stop
|
||||
// after a handful of records (51 Portuguese records in all,
|
||||
// « céramique Portugal » gave 2 results, 30/11; 13 records have both
|
||||
// céramique and translucide, 01/12). Counted as close results: only
|
||||
// the records of the terms and the country are exact. The names of the
|
||||
// terms count again here, as words; nothing more for a country alone.
|
||||
$this->countryFilter = FALSE;
|
||||
$wide = KeywordText::words($this->countries['codes'] ? CountryDetector::detect($text)['rest'] : $text, $lang);
|
||||
if ($wide) {
|
||||
[$more, $more_uuids] = $this->rank(implode(' ', $wide), $wide, $lang, [], TRUE);
|
||||
$nids = array_merge($nids, array_values(array_diff($more, $nids)));
|
||||
$uuids += $more_uuids;
|
||||
}
|
||||
}
|
||||
$this->exactematch_count = count($exact);
|
||||
|
||||
// Exact matches first, then the neighbours that stand out (H6), merged
|
||||
// with the OR query when it is on (H5). No neighbours: the OR query alone.
|
||||
$neighbours = $this->neighbours($lang);
|
||||
$or = ($neighbours === NULL || self::OR_WITH_KNN) ? $this->orQuery($keys, $lang) : [];
|
||||
$neighbours = $neighbours === NULL ? [] : ScoreCut::aboveMean($neighbours, self::KNN_SIGMA);
|
||||
$this->knn_count = count($neighbours);
|
||||
$nids = RankFusion::fuse(array_keys($exact), array_filter([array_keys($or), array_keys($neighbours)]));
|
||||
|
||||
$uuids = array_column($exact + $or, 1, 0) + $this->uuids(array_diff(array_keys($neighbours), array_keys($exact + $or)));
|
||||
$this->results = [
|
||||
'uuids' => array_map(static fn ($nid) => $uuids[$nid], $nids),
|
||||
'nids' => $nids,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Exact matches first, then the neighbours that stand out (H6), merged with
|
||||
* the OR query when it is on (H5). No neighbours: the OR query alone.
|
||||
*
|
||||
* @param string $keys
|
||||
* Keys without stop words.
|
||||
* @param string[] $words
|
||||
* The same, as a list.
|
||||
* @param array<int, array{0: mixed, 1: string}> $exact
|
||||
* Exact matches already found (references, titles).
|
||||
* @param bool $titles
|
||||
* Whether to search the keys in the titles.
|
||||
*
|
||||
* @return array{0: array<int|string>, 1: array<int, string>, 2: int}
|
||||
* Node IDs in order, their UUIDs keyed by nid, number of exact matches.
|
||||
*/
|
||||
private function rank(string $keys, array $words, string $lang, array $exact, bool $titles): array {
|
||||
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
||||
// Exact material names (like "wood-skin"), then all words.
|
||||
if ($titles) {
|
||||
$exact += $this->phraseQuery($keys, $lang);
|
||||
}
|
||||
$exact += $this->andQuery($keys, $lang);
|
||||
}
|
||||
|
||||
$neighbours = $this->neighbours($lang);
|
||||
if ($neighbours === NULL) {
|
||||
$or = $this->orQuery($keys, $lang);
|
||||
}
|
||||
else {
|
||||
$or = count($words) <= self::SHORT_QUERY_WORDS ? $this->orQuery($keys, $lang, 'AND', self::TEXT_WITH_KNN_LIMIT) : [];
|
||||
// Text matches ordered by closeness to the phrase (every node has a
|
||||
// score before ScoreCut): a record that holds the words but means
|
||||
// something else goes down the list (Q8).
|
||||
$text_order = array_keys($or);
|
||||
usort($text_order, static fn ($a, $b): int => ($neighbours[$b] ?? -INF) <=> ($neighbours[$a] ?? -INF));
|
||||
$or = array_replace(array_flip($text_order), $or);
|
||||
}
|
||||
$neighbours = $neighbours === NULL ? [] : ScoreCut::aboveMean($neighbours, self::KNN_SIGMA);
|
||||
if ($this->singleWord) {
|
||||
$neighbours = ScoreCut::nearBest($neighbours, self::KNN_SINGLE_WORD_MARGIN);
|
||||
}
|
||||
$this->knn_count += count($neighbours);
|
||||
$weights = $neighbours ? [0 => self::TEXT_WITH_KNN_WEIGHT] : [];
|
||||
$nids = RankFusion::fuse(array_keys($exact), array_filter([array_keys($or), array_keys($neighbours)]), RankFusion::K, $weights);
|
||||
|
||||
$uuids = array_column($exact + $or, 1, 0) + $this->uuids(array_diff(array_keys($neighbours), array_keys($exact + $or)));
|
||||
return [$nids, $uuids, count($exact)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Every record of the chosen terms, in order (Q7).
|
||||
*
|
||||
* First the exact matches already found and the records whose tags hold
|
||||
* every other word, then the others by closeness to the phrase (no
|
||||
* ScoreCut: they are all kept), then those the model did not score.
|
||||
*
|
||||
* @param string $keys
|
||||
* Rest of the phrase, without stop words.
|
||||
* @param string[] $words
|
||||
* The same, as a list.
|
||||
* @param array<int, array{0: mixed, 1: string}> $exact
|
||||
* Exact matches already found (references, titles).
|
||||
*
|
||||
* @return array{0: array<int|string>, 1: array<int, string>, 2: int}
|
||||
* Node IDs in order, their UUIDs keyed by nid, number of exact matches.
|
||||
*/
|
||||
private function termRecords(string $keys, array $words, string $lang, array $exact): array {
|
||||
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
||||
$exact += $this->andQuery($keys, $lang);
|
||||
}
|
||||
$all = $this->countryQuery($lang);
|
||||
// A title holding the phrase counts only with the terms.
|
||||
$exact = array_intersect_key($exact, $all);
|
||||
$neighbours = $this->neighbours($lang) ?? [];
|
||||
$this->knn_count += count($neighbours);
|
||||
$nids = array_keys($exact);
|
||||
foreach (array_keys($neighbours) as $nid) {
|
||||
if (isset($all[$nid])) {
|
||||
$nids[] = $nid;
|
||||
}
|
||||
}
|
||||
$nids = array_values(array_unique(array_merge($nids, array_keys($all))));
|
||||
$uuids = array_column($exact + $all, 1, 0);
|
||||
return [$nids, $uuids, count($nids)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Nodes closest in meaning to the phrase (materio_ai, Solr kNN).
|
||||
*
|
||||
* Not for a term chosen in the autocomplete (direct search) nor without
|
||||
* the materio_ai service. On a model or Solr error, past the delay of
|
||||
* Not without the materio_ai service. On a model or Solr error, past the delay of
|
||||
* QueryEmbedder (1 s), or with materio_ai switched off, the keyword
|
||||
* results stand alone, with no message: the search answers as before H5.
|
||||
*
|
||||
@@ -227,17 +418,22 @@ class Base extends ControllerBase {
|
||||
* are no neighbours to use.
|
||||
*/
|
||||
private function neighbours(string $lang): ?array {
|
||||
if ($this->terms || !\Drupal::hasService('materio_ai.neighbour_search')) {
|
||||
if (!\Drupal::hasService('materio_ai.neighbour_search')) {
|
||||
return NULL;
|
||||
}
|
||||
// References are keywords: they mean nothing to the model.
|
||||
$phrase = trim(preg_replace(self::REFERENCE_PATTERN, ' ', $this->phrase) ?? '');
|
||||
// References are keywords: they mean nothing to the model. Neither do
|
||||
// countries (« italien » brought Milano, Veneto): they filter instead (Q6).
|
||||
// The names of the chosen terms stay (Q7): « céramique translucide » means
|
||||
// more to the model than « translucide ».
|
||||
$phrase = $this->countries['codes'] ? CountryDetector::detect($this->phrase)['rest'] : $this->phrase;
|
||||
$phrase = trim(preg_replace(self::REFERENCE_PATTERN, ' ', $phrase) ?? '');
|
||||
if ($phrase === '') {
|
||||
return NULL;
|
||||
}
|
||||
$alter = $this->countryFilter ? fn ($query) => $this->addCountryCondition($query) : NULL;
|
||||
try {
|
||||
// Empty when materio_ai is switched off.
|
||||
return \Drupal::service('materio_ai.neighbour_search')->search($phrase, $lang, self::KNN_LIMIT) ?: NULL;
|
||||
return \Drupal::service('materio_ai.neighbour_search')->search($phrase, $lang, self::KNN_LIMIT, $alter) ?: NULL;
|
||||
}
|
||||
catch (\Throwable $e) {
|
||||
// Paused model: its failure was logged when it happened.
|
||||
@@ -317,17 +513,6 @@ class Base extends ControllerBase {
|
||||
private function andQuery(string $keys, string $lang): array {
|
||||
$this->and_query = $this->keywordQuery('terms', 'AND', $keys, $lang, 'materio_sapi_search_and_query');
|
||||
|
||||
// A term chosen in the autocomplete restricts to the taxonomy fields.
|
||||
if ($this->terms && is_array($this->terms) && count($this->terms)) {
|
||||
$term_conditions = $this->and_query->createConditionGroup('OR');
|
||||
foreach ($this->terms as $term) {
|
||||
foreach (['tag_tid', 'thesaurus_tid'] as $field) {
|
||||
$term_conditions->addCondition($field, (int) $term->value);
|
||||
}
|
||||
}
|
||||
$this->and_query->addConditionGroup($term_conditions);
|
||||
}
|
||||
|
||||
// Thesaurus and tag fields only.
|
||||
$this->and_query->setFulltextFields([
|
||||
'thesaurus_name_0',
|
||||
@@ -345,9 +530,134 @@ class Base extends ControllerBase {
|
||||
'tag_name',
|
||||
'tag_synonyms',
|
||||
]);
|
||||
$this->addCountryCondition($this->and_query);
|
||||
return $this->collect($this->and_query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every record of the chosen terms and of the countries named (Q6, Q7).
|
||||
*
|
||||
* @return array<int, array{0: mixed, 1: string}>
|
||||
* [nid, uuid] keyed by nid, in result order.
|
||||
*/
|
||||
private function countryQuery(string $lang): array {
|
||||
$query = $this->keywordQuery('terms', 'AND', '', $lang, 'materio_sapi_search_country_query');
|
||||
$this->addCountryCondition($query);
|
||||
return $this->collect($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricts a query to the countries named in the phrase, if any (Q6).
|
||||
*
|
||||
* A record matches when its manufacturer or its distributor is in one of
|
||||
* the countries, or when it has a tag or thesaurus term of the same name
|
||||
* (japon, chine, inde…: both kept, decided on 30/11).
|
||||
*
|
||||
* @param \Drupal\search_api\Query\QueryInterface $query
|
||||
* The query, not executed yet.
|
||||
*/
|
||||
private function addCountryCondition($query): void {
|
||||
if (!$this->countryFilter) {
|
||||
return;
|
||||
}
|
||||
// Every chosen term, as a tag or a thesaurus term (Q7): AND between the
|
||||
// terms, so that choosing a second one narrows the list.
|
||||
foreach ($this->termIds as $tid) {
|
||||
$group = $query->createConditionGroup('OR');
|
||||
$group->addCondition('tag_tid', $tid);
|
||||
$group->addCondition('thesaurus_tid', $tid);
|
||||
$query->addConditionGroup($group);
|
||||
}
|
||||
$codes = $this->countries['codes'];
|
||||
if (!$codes) {
|
||||
return;
|
||||
}
|
||||
$group = $query->createConditionGroup('OR');
|
||||
$group->addCondition('manufacturer_country', $codes, 'IN');
|
||||
$group->addCondition('distributor_country', $codes, 'IN');
|
||||
if ($tids = $this->countryTermIds()) {
|
||||
$group->addCondition('tag_tid', $tids, 'IN');
|
||||
$group->addCondition('thesaurus_tid', $tids, 'IN');
|
||||
}
|
||||
$query->addConditionGroup($group);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDs of the terms chosen in the autocomplete (Q7).
|
||||
*
|
||||
* The request sends [{"value": tid, "label": name}, …]; only the IDs are
|
||||
* kept, the names come from the terms themselves.
|
||||
*
|
||||
* @return int[]
|
||||
* Term IDs, at most MAX_TERMS.
|
||||
*/
|
||||
private function chosenTermIds(): array {
|
||||
$ids = [];
|
||||
foreach (is_array($this->terms) ? $this->terms : [] as $term) {
|
||||
$tid = is_object($term) ? ($term->value ?? NULL) : $term;
|
||||
if (is_numeric($tid) && (int) $tid > 0) {
|
||||
$ids[(int) $tid] = (int) $tid;
|
||||
}
|
||||
}
|
||||
return array_slice(array_values($ids), 0, self::MAX_TERMS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the chosen terms in the language, in the order chosen (Q7).
|
||||
*
|
||||
* @return string[]
|
||||
* Names.
|
||||
*/
|
||||
private function termNames(string $lang): array {
|
||||
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($this->termIds);
|
||||
$names = [];
|
||||
foreach ($this->termIds as $tid) {
|
||||
if (isset($terms[$tid])) {
|
||||
$term = $terms[$tid];
|
||||
$names[] = $term->hasTranslation($lang) ? $term->getTranslation($lang)->label() : $term->label();
|
||||
}
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* The phrase without the names of the chosen terms (Q7).
|
||||
*
|
||||
* What is left is searched among the records of the terms.
|
||||
*/
|
||||
private function withoutTermNames(string $text, string $lang): string {
|
||||
$names = $this->termNames($lang);
|
||||
foreach (\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($this->termIds) as $term) {
|
||||
$names[] = $term->label();
|
||||
}
|
||||
// Longest first (« bois flotté » before « bois »).
|
||||
$names = array_unique(array_filter($names));
|
||||
usort($names, static fn ($a, $b): int => mb_strlen($b) <=> mb_strlen($a));
|
||||
foreach ($names as $name) {
|
||||
$text = preg_replace('/(?<![\p{L}\p{N}])' . preg_quote($name, '/') . '(?![\p{L}\p{N}])/iu', ' ', $text) ?? $text;
|
||||
}
|
||||
return trim(preg_replace('/\s+/u', ' ', $text) ?? $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags and thesaurus terms named like the countries found.
|
||||
*
|
||||
* @return int[]
|
||||
* Term IDs.
|
||||
*/
|
||||
private function countryTermIds(): array {
|
||||
if ($this->countryTermIds === NULL) {
|
||||
$forms = CountryDetector::forms($this->countries['codes']);
|
||||
// Accent and case insensitive in MariaDB (utf8mb4 collation).
|
||||
$this->countryTermIds = $forms ? array_map('intval', array_values(\Drupal::entityQuery('taxonomy_term')
|
||||
->accessCheck(FALSE)
|
||||
->condition('vid', ['tags', 'thesaurus'], 'IN')
|
||||
->condition('name', $forms, 'IN')
|
||||
->execute())) : [];
|
||||
}
|
||||
return $this->countryTermIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Any word, in every fulltext field.
|
||||
*
|
||||
@@ -357,12 +667,14 @@ class Base extends ControllerBase {
|
||||
* @return array<int, array{0: mixed, 1: string}>
|
||||
* [nid, uuid] keyed by nid, in result order.
|
||||
*/
|
||||
private function orQuery(string $keys, string $lang): array {
|
||||
private function orQuery(string $keys, string $lang, string $conjunction = 'OR', int $limit = 10000): array {
|
||||
// Terms mode, not direct: Search API escapes the words, so punctuation
|
||||
// and Solr syntax typed in a phrase (: ( " / \\ ~) are plain text (H3).
|
||||
// Hyphenated words as separate words, as the direct mode did: in terms mode
|
||||
// « bio-based » would be a quoted phrase (the phrase query keeps it whole).
|
||||
$this->or_query = $this->keywordQuery('terms', 'OR', preg_replace('/(?<=\p{L})-(?=\p{L})/u', ' ', $keys), $lang, 'materio_sapi_search_or_query');
|
||||
$this->or_query = $this->keywordQuery('terms', $conjunction, preg_replace('/(?<=\p{L})-(?=\p{L})/u', ' ', $keys), $lang, 'materio_sapi_search_or_query');
|
||||
$this->or_query->range(0, $limit);
|
||||
$this->addCountryCondition($this->or_query);
|
||||
return $this->collect($this->or_query);
|
||||
}
|
||||
|
||||
@@ -488,7 +800,7 @@ class Base extends ControllerBase {
|
||||
// count no longer depends on an arbitrary limit. Plurals and "close"
|
||||
// results without any exact match (F4).
|
||||
$resp['infos'] = (new SearchMessage($this->getStringTranslation()))
|
||||
->results($resp['exactematch_count'], $resp['count'], $this->phrase, $lang);
|
||||
->results($resp['exactematch_count'], $resp['count'], $this->phrase, $lang, $this->filterNames);
|
||||
// $resp['options'] = $this->query->getOptions();
|
||||
|
||||
// $uuids = [];
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\materio_sapi;
|
||||
|
||||
use Drupal\Component\Transliteration\PhpTransliteration;
|
||||
|
||||
/**
|
||||
* Finds the countries named in a search phrase (Q6).
|
||||
*
|
||||
* « pigment Italie » or « verre italien » ask for a place, not for a word of
|
||||
* the records: the country is taken out of the phrase and becomes a
|
||||
* condition (company of the country, or tag of the same name). Longest form
|
||||
* first (« Corée du Sud » before « Corée »). A word typed with accents must
|
||||
* match a form with the same accents (« chiné » is not « Chine »); a word
|
||||
* typed without accents matches any form once folded (« bresil »).
|
||||
*/
|
||||
final class CountryDetector {
|
||||
|
||||
/**
|
||||
* Most words in a form (« united states of america »).
|
||||
*/
|
||||
private const MAX_WORDS = 5;
|
||||
|
||||
/**
|
||||
* Codes keyed by form, accents kept, then accents removed.
|
||||
*
|
||||
* @var array{0: array<string, string[]>, 1: array<string, string[]>}|null
|
||||
*/
|
||||
private static ?array $maps = NULL;
|
||||
|
||||
/**
|
||||
* Splits a phrase into the countries it names and the rest.
|
||||
*
|
||||
* @return array{codes: string[], forms: string[], rest: string}
|
||||
* ISO codes found, the forms as typed, and the phrase without them.
|
||||
*/
|
||||
public static function detect(string $phrase): array {
|
||||
[$exact, $plain] = self::maps();
|
||||
// Words and what separates them, so that the rest keeps its punctuation.
|
||||
$tokens = preg_split('/([\s\-\'’,;:\/()]+)/u', $phrase, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$words = [];
|
||||
foreach ($tokens as $i => $token) {
|
||||
if (!preg_match('/^[\s\-\'’,;:\/()]+$/u', $token)) {
|
||||
$words[] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
$forms = [];
|
||||
$removed = [];
|
||||
$count = count($words);
|
||||
for ($w = 0; $w < $count;) {
|
||||
$found = FALSE;
|
||||
for ($n = min(self::MAX_WORDS, $count - $w); $n >= 1; $n--) {
|
||||
$slice = array_slice($words, $w, $n);
|
||||
$typed = implode(' ', array_map(static fn (int $i): string => $tokens[$i], $slice));
|
||||
$key = self::fold($typed);
|
||||
$match = self::plain($key) === $key ? ($plain[$key] ?? NULL) : ($exact[$key] ?? NULL);
|
||||
if ($match) {
|
||||
array_push($codes, ...$match);
|
||||
$forms[] = $typed;
|
||||
for ($i = $slice[0]; $i <= end($slice); $i++) {
|
||||
$removed[$i] = TRUE;
|
||||
}
|
||||
$w += $n;
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$w++;
|
||||
}
|
||||
}
|
||||
|
||||
$rest = '';
|
||||
foreach ($tokens as $i => $token) {
|
||||
$rest .= isset($removed[$i]) ? ' ' : $token;
|
||||
}
|
||||
$rest = preg_replace(['/\s+/u', '/\s+([,;:])/u'], [' ', '$1'], $rest) ?? $rest;
|
||||
return [
|
||||
'codes' => array_values(array_unique($codes)),
|
||||
'forms' => $forms,
|
||||
'rest' => trim($rest, " ,;:/-"),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms of the given countries, as stored (lowercase, accents kept).
|
||||
*
|
||||
* @param string[] $codes
|
||||
* ISO codes.
|
||||
*
|
||||
* @return string[]
|
||||
* Forms, for the tags of the same name.
|
||||
*/
|
||||
public static function forms(array $codes): array {
|
||||
$forms = [];
|
||||
foreach ($codes as $code) {
|
||||
array_push($forms, ...(CountryForms::FORMS[$code] ?? []));
|
||||
}
|
||||
return array_values(array_unique($forms));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lowercase, hyphens and apostrophes as spaces, spaces collapsed.
|
||||
*/
|
||||
public static function fold(string $text): string {
|
||||
$text = preg_replace('/[\-\'’]+/u', ' ', mb_strtolower($text)) ?? $text;
|
||||
return trim(preg_replace('/\s+/u', ' ', $text) ?? $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accents removed.
|
||||
*/
|
||||
public static function plain(string $text): string {
|
||||
static $transliteration;
|
||||
$transliteration ??= new PhpTransliteration();
|
||||
return $transliteration->removeDiacritics($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the lookup maps once.
|
||||
*
|
||||
* @return array{0: array<string, string[]>, 1: array<string, string[]>}
|
||||
* Accents kept, accents removed.
|
||||
*/
|
||||
private static function maps(): array {
|
||||
if (self::$maps === NULL) {
|
||||
$exact = $plain = [];
|
||||
foreach (CountryForms::FORMS as $code => $forms) {
|
||||
foreach ($forms as $form) {
|
||||
$exact[$form][] = $code;
|
||||
$plain[self::plain($form)][] = $code;
|
||||
}
|
||||
}
|
||||
self::$maps = [
|
||||
array_map('array_unique', $exact),
|
||||
array_map('array_unique', $plain),
|
||||
];
|
||||
}
|
||||
return self::$maps;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\materio_sapi;
|
||||
|
||||
/**
|
||||
* Names and demonyms of the countries, French and English (Q6).
|
||||
*
|
||||
* Generated by q6-generer-pays.py (recherche-ia project folder) from the
|
||||
* country list of Drupal and the demonyms of Wikidata (P1549), reviewed on
|
||||
* 30/11/2026. Do not edit by hand: change the script and generate again.
|
||||
* Lowercase, hyphens and apostrophes as spaces, accents kept. Left out
|
||||
* because they also name a material or a process: guernsey, jersey, panama, polish, suede, suède.
|
||||
*/
|
||||
final class CountryForms {
|
||||
|
||||
/**
|
||||
* Forms keyed by ISO 3166-1 alpha-2 code.
|
||||
*/
|
||||
public const FORMS = [
|
||||
'AC' => ['ascension island', 'île de l ascension'],
|
||||
'AD' => ['andorra', 'andorran', 'andorrane', 'andorranes', 'andorrans', 'andorre'],
|
||||
'AE' => ['emirati', 'emirats arabes unis', 'emiri', 'emirian', 'emirians', 'uae', 'united arab emirates', 'émirats arabes unis', 'émirien', 'émirienne', 'émiriennes', 'émiriens'],
|
||||
'AF' => ['afghan', 'afghane', 'afghanes', 'afghanistan', 'afghans'],
|
||||
'AG' => ['antigua & barbuda', 'antigua and barbuda', 'antiguan', 'antiguans', 'antiguayen', 'antiguayene', 'antiguayenes', 'antiguayenne', 'antiguayennes', 'antiguayens', 'barbudan', 'barbudans'],
|
||||
'AI' => ['anguilla', 'anguillan', 'anguillans'],
|
||||
'AL' => ['albanais', 'albanaise', 'albanaises', 'albania', 'albanian', 'albanians', 'albanie'],
|
||||
'AM' => ['armenia', 'armenian', 'armenians', 'arménie', 'arménien', 'arménienne', 'arméniennes', 'arméniens'],
|
||||
'AN' => ['antilles néerlandaises', 'dutch antillean', 'dutch antilleans', 'netherlands antilles'],
|
||||
'AO' => ['angola', 'angolais', 'angolaise', 'angolaises', 'angolan', 'angolans'],
|
||||
'AQ' => ['antarctica', 'antarcticain', 'antarcticaine', 'antarcticaines', 'antarcticains', 'antarctican', 'antarcticans', 'antarctique'],
|
||||
'AR' => ['argentin', 'argentina', 'argentine', 'argentines', 'argentinian', 'argentinians', 'argentins'],
|
||||
'AS' => ['american samoa', 'american samoan', 'american samoans', 'samoa américaines'],
|
||||
'AT' => ['austria', 'austrian', 'austrians', 'autriche', 'autrichien', 'autrichienne', 'autrichiennes', 'autrichiens'],
|
||||
'AU' => ['aussie', 'aussies', 'australia', 'australian', 'australians', 'australie', 'australien', 'australienne', 'australiennes', 'australiens'],
|
||||
'AW' => ['aruba', 'aruban', 'arubans'],
|
||||
'AX' => ['åland islands', 'ålandic', 'îles aland'],
|
||||
'AZ' => ['azerbaijan', 'azerbaijani', 'azerbaijanis', 'azerbaïdjan', 'azerbaïdjanais', 'azerbaïdjanaise', 'azerbaïdjanaises', 'azeri', 'azeris'],
|
||||
'BA' => ['bosnia & herzegovina', 'bosnian', 'bosnians', 'bosnie herzégovine', 'bosnien', 'bosnienne', 'bosniennes', 'bosniens', 'herzegovinian', 'herzegovinians'],
|
||||
'BB' => ['barbade', 'barbadian', 'barbadians', 'barbadien', 'barbadienne', 'barbadiennes', 'barbadiens', 'barbados'],
|
||||
'BD' => ['bangladais', 'bangladaise', 'bangladaises', 'bangladesh', 'bangladeshi'],
|
||||
'BE' => ['belge', 'belges', 'belgian', 'belgians', 'belgique', 'belgium'],
|
||||
'BF' => ['burkina faso', 'burkinabe', 'burkinabè', 'burkinabèe', 'burkinabèes', 'burkinabès', 'burkinabé'],
|
||||
'BG' => ['bulgare', 'bulgares', 'bulgaria', 'bulgarian', 'bulgarians', 'bulgarie'],
|
||||
'BH' => ['bahrain', 'bahraini', 'bahreïn', 'bahreïnien', 'bahreïnienne', 'bahreïniennes', 'bahreïniens'],
|
||||
'BI' => ['burundais', 'burundaise', 'burundaises', 'burundi', 'burundian', 'burundians'],
|
||||
'BJ' => ['benin', 'beninese', 'bénin', 'béninien', 'béninienne', 'béniniennes', 'béniniens', 'béninois', 'béninoise', 'béninoises'],
|
||||
'BL' => ['barthéloméen', 'barthéloméenne', 'barthéloméennes', 'barthéloméens', 'st. barthélemy'],
|
||||
'BM' => ['bermuda', 'bermudan', 'bermudans', 'bermudes', 'bermudian', 'bermudians', 'bermudien', 'bermudienne', 'bermudiennes', 'bermudiens'],
|
||||
'BN' => ['brunei', 'brunéien', 'brunéienne', 'brunéiennes', 'brunéiens'],
|
||||
'BO' => ['bolivia', 'bolivian', 'bolivians', 'bolivie', 'bolivien', 'bolivienne', 'boliviennes', 'boliviens'],
|
||||
'BQ' => ['caribbean netherlands', 'pays bas caribéens'],
|
||||
'BR' => ['brazil', 'brazilian', 'brazilians', 'brésil', 'brésilien', 'brésilienne', 'brésiliennes', 'brésiliens'],
|
||||
'BS' => ['bahamas', 'bahamian', 'bahamians', 'bahaméen', 'bahaméenne', 'bahaméennes', 'bahaméens'],
|
||||
'BT' => ['bhoutan', 'bhoutanais', 'bhoutanaise', 'bhoutanaises', 'bhutan', 'bhutanese'],
|
||||
'BV' => ['bouvet island', 'île bouvet'],
|
||||
'BW' => ['batswana', 'botswana', 'botswanais', 'botswanaise', 'botswanaises', 'botswanan', 'botswanans', 'motswana'],
|
||||
'BY' => ['belarus', 'belarusian', 'belarusians', 'biélorusse', 'biélorusses', 'biélorussie'],
|
||||
'BZ' => ['belize', 'belizean', 'belizeans', 'bélizien', 'bélizienne', 'béliziennes', 'béliziens'],
|
||||
'CA' => ['canada', 'canadian', 'canadians', 'canadien', 'canadienne', 'canadiennes', 'canadiens'],
|
||||
'CC' => ['cocos (keeling) islands', 'îles cocos (keeling)'],
|
||||
'CD' => ['congo kinshasa', 'congolais', 'congolaise', 'congolaises', 'congolese'],
|
||||
'CF' => ['centrafricain', 'centrafricaine', 'centrafricaines', 'centrafricains', 'central african', 'central african republic', 'central africans', 'république centrafricaine'],
|
||||
'CG' => ['congo brazzaville', 'congolais', 'congolaise', 'congolaises', 'congolese'],
|
||||
'CH' => ['suisse', 'suisses', 'suissesse', 'suissesses', 'swiss', 'switzerland'],
|
||||
'CI' => ['côte d ivoire', 'ivoirian', 'ivoirians', 'ivoirien', 'ivoirienne', 'ivoiriennes', 'ivoiriens', 'ivorian', 'ivorians'],
|
||||
'CK' => ['cook islander', 'cook islands', 'îles cook'],
|
||||
'CL' => ['chile', 'chilean', 'chileans', 'chili', 'chilien', 'chilienne', 'chiliennes', 'chiliens'],
|
||||
'CM' => ['cameroon', 'cameroonian', 'cameroonians', 'cameroun', 'camerounais', 'camerounaise', 'camerounaises'],
|
||||
'CN' => ['china', 'chine', 'chinese', 'chinois', 'chinoise', 'chinoises'],
|
||||
'CO' => ['colombia', 'colombian', 'colombians', 'colombie', 'colombien', 'colombienne', 'colombiennes', 'colombiens'],
|
||||
'CP' => ['clipperton island', 'île de clipperton'],
|
||||
'CQ' => ['sark', 'sercq'],
|
||||
'CR' => ['costa rica', 'costa rican', 'costa ricans', 'costaricien', 'costaricienne', 'costariciennes', 'costariciens'],
|
||||
'CU' => ['cuba', 'cubain', 'cubaine', 'cubaines', 'cubains', 'cuban', 'cubans'],
|
||||
'CV' => ['cabo verdean', 'cabo verdeans', 'cap verdien', 'cap verdienne', 'cap verdiennes', 'cap verdiens', 'cap vert', 'cape verde', 'cape verdean', 'cape verdeans', 'capverdien', 'capverdienne', 'capverdiennes', 'capverdiens'],
|
||||
'CW' => ['curaçao', 'curaçaoan', 'curaçaoans'],
|
||||
'CX' => ['christmas island', 'christmas islander', 'christmas islanders', 'île christmas'],
|
||||
'CY' => ['chypre', 'chypriote', 'chypriotes', 'cypriot', 'cypriote', 'cypriotes', 'cyprus'],
|
||||
'CZ' => ['czech', 'czech republic', 'czechia', 'république tchèque', 'tchèque', 'tchèques', 'tchéquie'],
|
||||
'DE' => ['allemagne', 'allemand', 'allemande', 'allemandes', 'allemands', 'german', 'germans', 'germany'],
|
||||
'DG' => ['diego garcia'],
|
||||
'DJ' => ['djibouti', 'djiboutian', 'djiboutians', 'djiboutien', 'djiboutienne', 'djiboutiennes', 'djiboutiens'],
|
||||
'DK' => ['dane', 'danemark', 'danish', 'danois', 'danoise', 'danoises', 'denmark'],
|
||||
'DM' => ['dominica', 'dominican', 'dominicans', 'dominiquais', 'dominiquaise', 'dominiquaises', 'dominique'],
|
||||
'DO' => ['dominicain', 'dominicaine', 'dominicaines', 'dominicains', 'dominican', 'dominican republic', 'dominicans', 'république dominicaine'],
|
||||
'DZ' => ['algeria', 'algerian', 'algerians', 'algérie', 'algérien', 'algérienne', 'algériennes', 'algériens'],
|
||||
'EA' => ['ceuta & melilla'],
|
||||
'EC' => ['ecuador', 'ecuadoran', 'ecuadorans', 'ecuadorian', 'ecuadorians', 'équateur', 'équatorien', 'équatorienne', 'équatoriennes', 'équatoriens'],
|
||||
'EE' => ['estonia', 'estonian', 'estonians', 'estonie', 'estonien', 'estonienne', 'estoniennes', 'estoniens'],
|
||||
'EG' => ['egypt', 'egyptian', 'egyptians', 'égypte', 'égyptien', 'égyptienne', 'égyptiennes', 'égyptiens'],
|
||||
'EH' => ['sahara occidental', 'western sahara'],
|
||||
'ER' => ['eritrea', 'eritrean', 'eritreans', 'érythrée', 'érythréen', 'érythréenne', 'érythréennes', 'érythréens'],
|
||||
'ES' => ['espagne', 'espagnol', 'espagnole', 'espagnoles', 'espagnols', 'spain', 'spaniard', 'spanish'],
|
||||
'ET' => ['ethiopia', 'ethiopian', 'ethiopians', 'éthiopie', 'éthiopien', 'éthiopienne', 'éthiopiennes', 'éthiopiens', 'éthiopique', 'éthiopiques'],
|
||||
'FI' => ['finland', 'finlandais', 'finlandaise', 'finlandaises', 'finlande', 'finn', 'finnish', 'finns'],
|
||||
'FJ' => ['fidji', 'fidjien', 'fidjienne', 'fidjiennes', 'fidjiens', 'fiji', 'fijian', 'fijians'],
|
||||
'FK' => ['falkland islands', 'îles malouines'],
|
||||
'FM' => ['micronesia', 'micronesian', 'micronesians', 'micronésie', 'micronésien', 'micronésienne', 'micronésiennes', 'micronésiens'],
|
||||
'FO' => ['faroe islander', 'faroe islands', 'faroese', 'féroïen', 'féroïene', 'féroïenes', 'féroïens', 'îles féroé'],
|
||||
'FR' => ['france', 'français', 'française', 'françaises', 'french'],
|
||||
'GA' => ['gabon', 'gabonais', 'gabonaise', 'gabonaises', 'gabonese'],
|
||||
'GB' => ['anglais', 'anglaise', 'anglaises', 'angleterre', 'britain', 'britannique', 'britanniques', 'british', 'briton', 'britons', 'england', 'grande bretagne', 'great britain', 'pays de galles', 'royaume uni', 'scotland', 'uk', 'united kingdom', 'wales', 'écosse'],
|
||||
'GD' => ['grenada', 'grenade', 'grenadian', 'grenadians', 'grenadien', 'grenadienne', 'grenadiennes', 'grenadiens'],
|
||||
'GE' => ['georgia', 'georgian', 'georgians', 'géorgie', 'géorgien', 'géorgienne', 'géorgiennes', 'géorgiens'],
|
||||
'GF' => ['french guiana', 'french guianese', 'guianese', 'guyanais', 'guyanaise', 'guyanaises', 'guyane française'],
|
||||
'GG' => ['guernesey'],
|
||||
'GH' => ['ghana', 'ghanaian', 'ghanaians', 'ghanéen', 'ghanéenne', 'ghanéennes', 'ghanéens'],
|
||||
'GI' => ['gibraltar', 'gibraltarian', 'gibraltarians', 'gibraltarien', 'gibraltarienne', 'gibraltariennes', 'gibraltariens'],
|
||||
'GL' => ['greenland', 'greenlandic', 'groenland', 'groenlandais', 'groenlandaise', 'groenlandaises'],
|
||||
'GM' => ['gambia', 'gambian', 'gambians', 'gambie', 'gambien', 'gambienne', 'gambiennes', 'gambiens'],
|
||||
'GN' => ['guinea', 'guinean', 'guineans', 'guinée', 'guinéen', 'guinéenne', 'guinéennes', 'guinéens'],
|
||||
'GP' => ['guadeloupe', 'guadeloupean', 'guadeloupeans'],
|
||||
'GQ' => ['equatoguinean', 'equatoguineans', 'equatorial guinea', 'equatorial guinean', 'equatorial guineans', 'guinée équatoriale', 'équatoguinéen', 'équatoguinéenne', 'équatoguinéennes', 'équatoguinéens'],
|
||||
'GR' => ['grec', 'grecque', 'grecques', 'grecs', 'greece', 'greek', 'grèce'],
|
||||
'GS' => ['géorgie du sud et les îles sandwich du sud', 'south georgia & south sandwich islands', 'south georgian', 'south georgians', 'south sandwich islander'],
|
||||
'GT' => ['guatemala', 'guatemalan', 'guatemalans', 'guatémalien', 'guatémalienne', 'guatémaliennes', 'guatémaliens', 'guatémaltèque', 'guatémaltèques'],
|
||||
'GU' => ['guam', 'guamanian', 'guamanians', 'guamanien', 'guamanienne', 'guamaniennes', 'guamaniens'],
|
||||
'GW' => ['bissaoguinéen', 'bissaoguinéenne', 'bissaoguinéennes', 'bissaoguinéens', 'bissau guinean', 'bissau guineans', 'guinea bissau', 'guinea bissauan', 'guinea bissauans', 'guinée bissau', 'guinéen', 'guinéenne', 'guinéennes', 'guinéens'],
|
||||
'GY' => ['guyana', 'guyanese', 'guyanien', 'guyanienne', 'guyaniennes', 'guyaniens'],
|
||||
'HK' => ['hong kong', 'hong kong people', 'hong kong sar china', 'hongkongais', 'hongkongaise', 'hongkongaises', 'hongkonger'],
|
||||
'HM' => ['heard & mcdonald islands', 'heard and mcdonald islander', 'îles heard et macdonald'],
|
||||
'HN' => ['honduran', 'hondurans', 'honduras', 'hondurien', 'hondurienne', 'honduriennes', 'honduriens'],
|
||||
'HR' => ['croate', 'croates', 'croatia', 'croatian', 'croatians', 'croatie'],
|
||||
'HT' => ['haiti', 'haitian', 'haitians', 'haïti', 'haïtien', 'haïtienne', 'haïtiennes', 'haïtiens'],
|
||||
'HU' => ['hongrie', 'hongrois', 'hongroise', 'hongroises', 'hungarian', 'hungarians', 'hungary'],
|
||||
'IC' => ['canary islands', 'îles canaries'],
|
||||
'ID' => ['indonesia', 'indonesian', 'indonesians', 'indonésie', 'indonésien', 'indonésienne', 'indonésiennes', 'indonésiens'],
|
||||
'IE' => ['ireland', 'irish', 'irlandais', 'irlandaise', 'irlandaises', 'irlande'],
|
||||
'IL' => ['israel', 'israeli', 'israelis', 'israélien', 'israélienne', 'israéliennes', 'israéliens', 'israël'],
|
||||
'IM' => ['isle of man', 'manx', 'île de man'],
|
||||
'IN' => ['inde', 'india', 'indian', 'indians', 'indien', 'indienne', 'indiennes', 'indiens'],
|
||||
'IO' => ['british', 'british indian ocean territory', 'territoire britannique de l océan indien'],
|
||||
'IQ' => ['irak', 'irakien', 'irakienne', 'irakiennes', 'irakiens', 'iraq', 'iraqi'],
|
||||
'IR' => ['iran', 'iranian', 'iranians', 'iranien', 'iranienne', 'iraniennes', 'iraniens', 'persian', 'persians'],
|
||||
'IS' => ['iceland', 'icelander', 'icelandic', 'islandais', 'islandaise', 'islandaises', 'islande'],
|
||||
'IT' => ['italian', 'italians', 'italie', 'italien', 'italienne', 'italiennes', 'italiens', 'italy'],
|
||||
'JE' => ['islander', 'jersey bean', 'jersey beans', 'jersey crapaud', 'jersey crapaude', 'jersey crapaudes', 'jersey crapauds', 'jerseyman', 'jerseymans', 'jerseywoman', 'jerseywomans', 'jèrriais(e)', 'jèrriais(e)e', 'jèrriais(e)es', 'jèrriais(e)s'],
|
||||
'JM' => ['jamaica', 'jamaican', 'jamaicans', 'jamaïcain', 'jamaïcaine', 'jamaïcaines', 'jamaïcains', 'jamaïquain', 'jamaïquaine', 'jamaïquaines', 'jamaïquains', 'jamaïque'],
|
||||
'JO' => ['jordan', 'jordanian', 'jordanians', 'jordanie', 'jordanien', 'jordanienne', 'jordaniennes', 'jordaniens'],
|
||||
'JP' => ['japan', 'japanese', 'japon', 'japonais', 'japonaise', 'japonaises'],
|
||||
'KE' => ['kenya', 'kenyan', 'kenyans', 'kényan', 'kényane', 'kényanes', 'kényans'],
|
||||
'KG' => ['kirghiz', 'kirghize', 'kirghizes', 'kirghizistan', 'kirghizs', 'kyrgyz', 'kyrgyzstan', 'kyrgyzstani'],
|
||||
'KH' => ['cambodge', 'cambodgien', 'cambodgienne', 'cambodgiennes', 'cambodgiens', 'cambodia', 'cambodian', 'cambodians'],
|
||||
'KI' => ['gilbertin', 'gilbertine', 'gilbertines', 'gilbertins', 'i kiribati', 'kiribati'],
|
||||
'KM' => ['comoran', 'comorans', 'comores', 'comorian', 'comorians', 'comorien', 'comorienne', 'comoriennes', 'comoriens', 'comoros'],
|
||||
'KN' => ['christophien', 'christophienne', 'christophiennes', 'christophiens', 'kittitian', 'kittitians', 'nevisian', 'nevisians', 'saint christophe et niévès', 'st. kitts & nevis'],
|
||||
'KP' => ['corée du nord', 'nord coréen', 'nord coréenne', 'nord coréennes', 'nord coréens', 'north korea', 'north korean', 'north koreans'],
|
||||
'KR' => ['corée', 'corée du sud', 'coréen', 'coréenne', 'coréennes', 'coréens', 'korea', 'korean', 'koreans', 'south korea', 'south korean', 'south koreans', 'sud coréen', 'sud coréenne', 'sud coréennes', 'sud coréens'],
|
||||
'KW' => ['koweït', 'koweïtien', 'koweïtienne', 'koweïtiennes', 'koweïtiens', 'kuwait', 'kuwaiti'],
|
||||
'KY' => ['cayman islands', 'caymanian', 'caymanians', 'îles caïmans'],
|
||||
'KZ' => ['kazakh', 'kazakhstan', 'kazakhstanais', 'kazakhstanaise', 'kazakhstanaises', 'kazakhstani'],
|
||||
'LA' => ['lao', 'laos', 'laotian', 'laotians', 'laotien', 'laotienne', 'laotiennes', 'laotiens'],
|
||||
'LB' => ['lebanese', 'lebanon', 'liban', 'libanais', 'libanaise', 'libanaises'],
|
||||
'LC' => ['lucien', 'lucienne', 'luciennes', 'luciens', 'saint lucian', 'saint lucians', 'sainte lucie', 'st. lucia'],
|
||||
'LI' => ['liechtenstein', 'liechtensteiner', 'liechtensteinois', 'liechtensteinoise', 'liechtensteinoises'],
|
||||
'LK' => ['sri lanka', 'sri lankan', 'sri lankans', 'srilankais', 'srilankaise', 'srilankaises'],
|
||||
'LR' => ['liberia', 'liberian', 'liberians', 'libéria', 'libérien', 'libérienne', 'libériennes', 'libériens'],
|
||||
'LS' => ['basotho', 'lesothien', 'lesothienne', 'lesothiennes', 'lesothiens', 'lesotho', 'lésothan', 'lésothane', 'lésothanes', 'lésothans', 'mosotho'],
|
||||
'LT' => ['lithuania', 'lithuanian', 'lithuanians', 'lituanie', 'lituanien', 'lituanienne', 'lituaniennes', 'lituaniens'],
|
||||
'LU' => ['luxembourg', 'luxembourgeois', 'luxembourgeoise', 'luxembourgeoises', 'luxembourgian', 'luxembourgians', 'luxembourgish'],
|
||||
'LV' => ['latvia', 'latvian', 'latvians', 'letton', 'lettonie', 'lettonne', 'lettonnes', 'lettons'],
|
||||
'LY' => ['libya', 'libyan', 'libyans', 'libyen', 'libyene', 'libyenes', 'libyenne', 'libyennes', 'libyens', 'lybie'],
|
||||
'MA' => ['maroc', 'marocain', 'marocaine', 'marocaines', 'marocains', 'moroccan', 'moroccans', 'morocco'],
|
||||
'MC' => ['monacan', 'monacans', 'monaco', 'monegasque', 'monégasque', 'monégasques'],
|
||||
'MD' => ['moldave', 'moldaves', 'moldavian', 'moldavians', 'moldavie', 'moldova', 'moldovan', 'moldovans'],
|
||||
'ME' => ['montenegrin', 'montenegrins', 'montenegro', 'monténégrin', 'monténégrine', 'monténégrines', 'monténégrins', 'monténégro'],
|
||||
'MF' => ['saint martinois', 'saint martinoise', 'saint martinoises', 'st. martin'],
|
||||
'MG' => ['madagascar', 'malagasy', 'malgache', 'malgaches'],
|
||||
'MH' => ['marshall islands', 'marshallais', 'marshallaise', 'marshallaises', 'marshallese', 'îles marshall'],
|
||||
'MK' => ['macedonian', 'macedonians', 'macédoine du nord', 'macédonien', 'macédonienne', 'macédoniennes', 'macédoniens', 'north macedonia'],
|
||||
'ML' => ['mali', 'malian', 'malians', 'malien', 'malienne', 'maliennes', 'maliens'],
|
||||
'MM' => ['birman', 'birmane', 'birmanes', 'birmans', 'burmese', 'myanma', 'myanmar (birmanie)', 'myanmar (burma)'],
|
||||
'MN' => ['mongol', 'mongole', 'mongoles', 'mongolia', 'mongolian', 'mongolians', 'mongolie', 'mongols'],
|
||||
'MO' => ['macanese', 'macao sar china', 'région administrative spéciale de macao de la république populaire de chine'],
|
||||
'MP' => ['chamorro', 'chamorros', 'northern mariana islander', 'northern mariana islanders', 'northern mariana islands', 'northern marianan', 'northern marianans', 'îles mariannes du nord'],
|
||||
'MQ' => ['martinique'],
|
||||
'MR' => ['mauritania', 'mauritanian', 'mauritanians', 'mauritanie', 'mauritanien', 'mauritanienne', 'mauritaniennes', 'mauritaniens'],
|
||||
'MS' => ['montserrat', 'montserratian', 'montserratians'],
|
||||
'MT' => ['malta', 'maltais', 'maltaise', 'maltaises', 'malte', 'maltese'],
|
||||
'MU' => ['maurice', 'mauricien', 'mauricienne', 'mauriciennes', 'mauriciens', 'mauritian', 'mauritians', 'mauritius'],
|
||||
'MV' => ['maldives', 'maldivian', 'maldivians', 'maldivien', 'maldivienne', 'maldiviennes', 'maldiviens'],
|
||||
'MW' => ['malawi', 'malawian', 'malawians', 'malawite', 'malawites'],
|
||||
'MX' => ['mexicain', 'mexicaine', 'mexicaines', 'mexicains', 'mexican', 'mexicans', 'mexico', 'mexique'],
|
||||
'MY' => ['malais', 'malaise', 'malaises', 'malaisie', 'malaisien', 'malaisienne', 'malaisiennes', 'malaisiens', 'malaysia', 'malaysian', 'malaysians'],
|
||||
'MZ' => ['mozambicain', 'mozambicaine', 'mozambicaines', 'mozambicains', 'mozambican', 'mozambicans', 'mozambique'],
|
||||
'NA' => ['namibia', 'namibian', 'namibians', 'namibie', 'namibien', 'namibienne', 'namibiennes', 'namibiens'],
|
||||
'NC' => ['calédonien', 'calédonienne', 'calédoniennes', 'calédoniens', 'new caledonia', 'new caledonian', 'new caledonians', 'nouvelle calédonie', 'néo calédonien', 'néo calédonienne', 'néo calédoniennes', 'néo calédoniens', 'néocalédonien', 'néocalédonienne', 'néocalédoniennes', 'néocalédoniens'],
|
||||
'NE' => ['niger', 'nigerien', 'nigeriens', 'nigérien', 'nigérienne', 'nigériennes', 'nigériens'],
|
||||
'NF' => ['norfolk island', 'norfolk islander', 'norfolk islanders', 'île norfolk'],
|
||||
'NG' => ['nigeria', 'nigerian', 'nigerians', 'nigérian', 'nigériane', 'nigérianes', 'nigérians'],
|
||||
'NI' => ['nicaragua', 'nicaraguan', 'nicaraguans', 'nicaraguayen', 'nicaraguayene', 'nicaraguayenes', 'nicaraguayenne', 'nicaraguayennes', 'nicaraguayens'],
|
||||
'NL' => ['dutch', 'holland', 'hollandais', 'hollandaise', 'hollandaises', 'hollande', 'netherlands', 'néerlandais', 'néerlandaise', 'néerlandaises', 'pays bas'],
|
||||
'NO' => ['norvège', 'norvégien', 'norvégienne', 'norvégiennes', 'norvégiens', 'norway', 'norwegian', 'norwegians'],
|
||||
'NP' => ['nepal', 'nepalese', 'nepali', 'népal', 'népalais', 'népalaise', 'népalaises'],
|
||||
'NR' => ['nauru', 'nauruan', 'nauruane', 'nauruanes', 'nauruans'],
|
||||
'NU' => ['niue', 'niuean', 'niueans'],
|
||||
'NZ' => ['new zealand', 'new zealander', 'nouvelle zélande', 'néo zélandais', 'néo zélandaise', 'néo zélandaises', 'néozélandais', 'néozélandaise', 'néozélandaises'],
|
||||
'OM' => ['oman', 'omanais', 'omanaise', 'omanaises', 'omani'],
|
||||
'PA' => ['panamanian', 'panamanians', 'panaméen', 'panaméenne', 'panaméennes', 'panaméens'],
|
||||
'PE' => ['peru', 'peruvian', 'peruvians', 'pérou', 'péruvien', 'péruvienne', 'péruviennes', 'péruviens'],
|
||||
'PF' => ['french polynesia', 'french polynesian', 'french polynesians', 'polynésie française', 'polynésien', 'polynésienne', 'polynésiennes', 'polynésiens'],
|
||||
'PG' => ['néoguinéen', 'néoguinéenne', 'néoguinéennes', 'néoguinéens', 'papouasie nouvelle guinée', 'papouasien', 'papouasienne', 'papouasiennes', 'papouasiens', 'papua new guinea', 'papua new guinean', 'papua new guineans'],
|
||||
'PH' => ['filipina', 'filipino', 'philippin', 'philippine', 'philippines', 'philippins'],
|
||||
'PK' => ['pakistan', 'pakistanais', 'pakistanaise', 'pakistanaises', 'pakistani'],
|
||||
'PL' => ['poland', 'pologne', 'polonais', 'polonaise', 'polonaises'],
|
||||
'PM' => ['miquelonais', 'miquelonaise', 'miquelonaises', 'saint pierrais', 'saint pierraise', 'saint pierraises', 'saint pierre et miquelon', 'st. pierre & miquelon'],
|
||||
'PN' => ['pitcairn islander', 'pitcairn islands', 'îles pitcairn'],
|
||||
'PR' => ['porto rico', 'portoricain', 'portoricaine', 'portoricaines', 'portoricains', 'puerto rican', 'puerto ricans', 'puerto rico'],
|
||||
'PS' => ['palestinian', 'palestinian territories', 'palestinians', 'palestinien', 'palestinienne', 'palestiniennes', 'palestiniens', 'territoires palestiniens'],
|
||||
'PT' => ['portugais', 'portugaise', 'portugaises', 'portugal', 'portuguese'],
|
||||
'PW' => ['palaois', 'palaoise', 'palaoises', 'palaos', 'palau', 'palauan', 'palauans'],
|
||||
'PY' => ['paraguay', 'paraguayan', 'paraguayans', 'paraguayen', 'paraguayene', 'paraguayenes', 'paraguayenne', 'paraguayennes', 'paraguayens'],
|
||||
'QA' => ['qatar', 'qatari', 'qatarien', 'qatarienne', 'qatariennes', 'qatariens'],
|
||||
'QO' => ['océanie éloignée', 'outlying oceania'],
|
||||
'RE' => ['réunion', 'réunionnais', 'réunionnaise', 'réunionnaises'],
|
||||
'RO' => ['romania', 'romanian', 'romanians', 'roumain', 'roumaine', 'roumaines', 'roumains', 'roumanie'],
|
||||
'RS' => ['serbe', 'serbes', 'serbia', 'serbian', 'serbians', 'serbie'],
|
||||
'RU' => ['russe', 'russes', 'russia', 'russian', 'russians', 'russie'],
|
||||
'RW' => ['rwanda', 'rwandais', 'rwandaise', 'rwandaises', 'rwandan', 'rwandans', 'rwandese'],
|
||||
'SA' => ['arabie saoudite', 'saoudien', 'saoudienne', 'saoudiennes', 'saoudiens', 'saudi', 'saudi arabia', 'saudi arabian', 'saudi arabians'],
|
||||
'SB' => ['salomonais', 'salomonaise', 'salomonaises', 'salomonien', 'salomonienne', 'salomoniennes', 'salomoniens', 'solomon islander', 'solomon islands', 'îles salomon'],
|
||||
'SC' => ['seychelles', 'seychellois', 'seychelloise', 'seychelloises'],
|
||||
'SD' => ['soudan', 'soudanais', 'soudanaise', 'soudanaises', 'sudan', 'sudanese'],
|
||||
'SE' => ['suédois', 'suédoise', 'suédoises', 'sweden', 'swedish'],
|
||||
'SG' => ['singapore', 'singaporean', 'singaporeans', 'singapour', 'singapourien', 'singapourienne', 'singapouriennes', 'singapouriens'],
|
||||
'SH' => ['sainte hélène', 'st. helena'],
|
||||
'SI' => ['slovene', 'slovenia', 'slovenian', 'slovenians', 'slovène', 'slovènes', 'slovénie'],
|
||||
'SJ' => ['svalbard & jan mayen', 'svalbard et jan mayen'],
|
||||
'SK' => ['slovak', 'slovakia', 'slovaque', 'slovaques', 'slovaquie'],
|
||||
'SL' => ['sierra leone', 'sierra leonean', 'sierra leoneans', 'sierraléonais', 'sierraléonaise', 'sierraléonaises'],
|
||||
'SM' => ['saint marin', 'saint marinais', 'saint marinaise', 'saint marinaises', 'sammarinese', 'san marino'],
|
||||
'SN' => ['senegal', 'senegalese', 'sénégal', 'sénégalais', 'sénégalaise', 'sénégalaises', 'sénégalien', 'sénégalienne', 'sénégaliennes', 'sénégaliens'],
|
||||
'SO' => ['somali', 'somalia', 'somalian', 'somalians', 'somalie', 'somalien', 'somalienne', 'somaliennes', 'somaliens'],
|
||||
'SR' => ['suriname', 'surinamese', 'surinamien', 'surinamienne', 'surinamiennes', 'surinamiens'],
|
||||
'SS' => ['soudan du sud', 'south sudan', 'south sudanese', 'sud soudanais', 'sud soudanaise', 'sud soudanaises', 'sudsoudanais', 'sudsoudanaise', 'sudsoudanaises'],
|
||||
'ST' => ['santomean', 'santomeans', 'santoméen', 'santoméenne', 'santoméennes', 'santoméens', 'sao tomean', 'sao tomeans', 'sao tomé et principe', 'são tomé & príncipe', 'são toméan', 'são toméans'],
|
||||
'SV' => ['el salvador', 'salvador', 'salvadoran', 'salvadorans', 'salvadorien', 'salvadorienne', 'salvadoriennes', 'salvadoriens'],
|
||||
'SX' => ['sint maarten', 'st. maartener'],
|
||||
'SY' => ['syria', 'syrian', 'syrians', 'syrie', 'syrien', 'syrienne', 'syriennes', 'syriens'],
|
||||
'SZ' => ['emaswati', 'eswatini', 'eswatinien', 'eswatinienne', 'eswatiniennes', 'eswatiniens', 'liswati', 'swazi', 'swazis'],
|
||||
'TA' => ['tristan da cunha'],
|
||||
'TC' => ['turks & caicos islands', 'turks and caicos islander', 'îles turques et caïques'],
|
||||
'TD' => ['chad', 'chadian', 'chadians', 'tchad', 'tchadien', 'tchadienne', 'tchadiennes', 'tchadiens'],
|
||||
'TF' => ['french', 'french southern territories', 'terres australes françaises'],
|
||||
'TG' => ['togo', 'togolais', 'togolaise', 'togolaises', 'togolese'],
|
||||
'TH' => ['thai', 'thailand', 'thaïlandais', 'thaïlandaise', 'thaïlandaises', 'thaïlande'],
|
||||
'TJ' => ['tadjik', 'tadjike', 'tadjikes', 'tadjikistan', 'tadjiks', 'tajikistan', 'tajikistani'],
|
||||
'TK' => ['tokelau', 'tokelauan', 'tokelauans'],
|
||||
'TL' => ['east timorese', 'timor leste', 'timor oriental', 'timorais', 'timoraise', 'timoraises'],
|
||||
'TM' => ['turkmen', 'turkmenistan', 'turkmenistani', 'turkmens', 'turkmène', 'turkmènes', 'turkménistan'],
|
||||
'TN' => ['tunisia', 'tunisian', 'tunisians', 'tunisie', 'tunisien', 'tunisienne', 'tunisiennes', 'tunisiens'],
|
||||
'TO' => ['tonga', 'tongan', 'tongans', 'tongien', 'tongienne', 'tongiennes', 'tongiens'],
|
||||
'TR' => ['turc', 'turcs', 'turkey', 'turkish', 'turque', 'turques', 'turquie', 'türkiye'],
|
||||
'TT' => ['trinibagonien', 'trinibagonienne', 'trinibagoniennes', 'trinibagoniens', 'trinidad & tobago', 'trinidadian', 'trinidadians', 'trinidadien', 'trinidadienne', 'trinidadiennes', 'trinidadiens', 'trinité et tobago'],
|
||||
'TV' => ['tuvalais', 'tuvalaise', 'tuvalaises', 'tuvalu', 'tuvaluan', 'tuvaluans'],
|
||||
'TW' => ['taiwan', 'taiwanese', 'taiwans', 'taïwan', 'taïwanais', 'taïwanaise', 'taïwanaises'],
|
||||
'TZ' => ['tanzania', 'tanzanian', 'tanzanians', 'tanzanie', 'tanzanien', 'tanzanienne', 'tanzaniennes', 'tanzaniens'],
|
||||
'UA' => ['ukraine', 'ukrainian', 'ukrainians', 'ukrainien', 'ukrainienne', 'ukrainiennes', 'ukrainiens'],
|
||||
'UG' => ['ouganda', 'ougandais', 'ougandaise', 'ougandaises', 'uganda', 'ugandan', 'ugandans'],
|
||||
'UM' => ['u.s. outlying islands', 'îles éloignées des états unis'],
|
||||
'US' => ['american', 'americans', 'américain', 'américaine', 'américaines', 'américains', 'etats unis', 'united states', 'united states of america', 'usa', 'états unien', 'états unienne', 'états uniennes', 'états uniens', 'états unis', 'états unis d amérique'],
|
||||
'UY' => ['uruguay', 'uruguayan', 'uruguayans', 'uruguayen', 'uruguayene', 'uruguayenes', 'uruguayenne', 'uruguayennes', 'uruguayens'],
|
||||
'UZ' => ['ouzbek', 'ouzbeke', 'ouzbekes', 'ouzbeks', 'ouzbekèke', 'ouzbekèkes', 'ouzbékistan', 'uzbek', 'uzbekistan', 'uzbekistani'],
|
||||
'VA' => ['cité du vatican', 'vatican', 'vatican city', 'vaticans'],
|
||||
'VC' => ['saint vincent et les grenadines', 'saint vincentian', 'saint vincentians', 'st. vincent & grenadines', 'vincentais', 'vincentaise', 'vincentaises', 'vincentian', 'vincentians', 'vincy'],
|
||||
'VE' => ['venezuela', 'venezuelan', 'venezuelans', 'vénézuélien', 'vénézuélienne', 'vénézuéliennes', 'vénézuéliens'],
|
||||
'VG' => ['britannique', 'britanniques', 'british virgin islands', 'insulaire des îles vierges britanniques', 'insulaire des îles vierges britanniquese', 'insulaire des îles vierges britanniqueses', 'îles vierges britanniques'],
|
||||
'VI' => ['u.s. virgin islands', 'îles vierges américaines'],
|
||||
'VN' => ['vietnam', 'vietnamese', 'vietnamien', 'vietnamienne', 'vietnamiennes', 'vietnamiens'],
|
||||
'VU' => ['ni vanuatu', 'vanouatais', 'vanouataise', 'vanouataises', 'vanuatu', 'vanuatuan', 'vanuatuans'],
|
||||
'WF' => ['futunan', 'futunans', 'wallis & futuna', 'wallis et futuna', 'wallisian', 'wallisians'],
|
||||
'WS' => ['samoa', 'samoan', 'samoans', 'samoen', 'samoene', 'samoenes', 'samoenne', 'samoennes', 'samoens'],
|
||||
'XK' => ['kosovan', 'kosovans', 'kosovar', 'kosovare', 'kosovares', 'kosovars', 'kosovo', 'kossovien', 'kossovienne', 'kossoviennes', 'kossoviens'],
|
||||
'YE' => ['yemen', 'yemeni', 'yémen', 'yéménite', 'yéménites'],
|
||||
'YT' => ['mahorais', 'mahoraise', 'mahoraises', 'mayotte'],
|
||||
'ZA' => ['afrique du sud', 'south africa', 'south african', 'south africans', 'sud africain', 'sud africaine', 'sud africaines', 'sud africains'],
|
||||
'ZM' => ['zambia', 'zambian', 'zambians', 'zambie', 'zambien', 'zambienne', 'zambiennes', 'zambiens'],
|
||||
'ZW' => ['zimbabwe', 'zimbabwean', 'zimbabweans', 'zimbabwéen', 'zimbabwéenne', 'zimbabwéennes', 'zimbabwéens'],
|
||||
];
|
||||
|
||||
}
|
||||
@@ -30,11 +30,13 @@ final class RankFusion {
|
||||
* Ranked lists of node IDs (keyword OR query, kNN neighbours…).
|
||||
* @param int $k
|
||||
* RRF constant.
|
||||
* @param array<float> $weights
|
||||
* Weight of each ranking, same keys; 1 when missing (Q8).
|
||||
*
|
||||
* @return array<int|string>
|
||||
* Node IDs, each once.
|
||||
*/
|
||||
public static function fuse(array $exact, array $rankings, int $k = self::K): array {
|
||||
public static function fuse(array $exact, array $rankings, int $k = self::K, array $weights = []): array {
|
||||
$merged = [];
|
||||
foreach ($exact as $nid) {
|
||||
$merged[$nid] ??= $nid;
|
||||
@@ -42,7 +44,8 @@ final class RankFusion {
|
||||
$scores = [];
|
||||
$first = [];
|
||||
$position = 0;
|
||||
foreach ($rankings as $ranking) {
|
||||
foreach ($rankings as $key => $ranking) {
|
||||
$weight = $weights[$key] ?? 1.0;
|
||||
$rank = 0;
|
||||
foreach ($ranking as $nid) {
|
||||
$rank++;
|
||||
@@ -53,7 +56,7 @@ final class RankFusion {
|
||||
$scores[$nid] = 0.0;
|
||||
$first[$nid] = [$position++, $nid];
|
||||
}
|
||||
$scores[$nid] += 1 / ($k + $rank);
|
||||
$scores[$nid] += $weight / ($k + $rank);
|
||||
}
|
||||
}
|
||||
uksort($scores, static fn ($a, $b): int => [$scores[$b], $first[$a][0]] <=> [$scores[$a], $first[$b][0]]);
|
||||
|
||||
@@ -41,4 +41,29 @@ final class ScoreCut {
|
||||
return array_filter($scores, static fn ($score) => $score > $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scores within $margin of the best one, in their order (Q9).
|
||||
*
|
||||
* For a single word the model has almost no meaning to compare: after
|
||||
* the few records that hold it, a plateau of records that only look alike
|
||||
* (« datte »: DATEFORM 0.772, Datecrete 0.758, then Damasteel, DalMagnetic
|
||||
* around 0.72). A meaningful word keeps a slow decline (« liège »: 37
|
||||
* records within 0.04).
|
||||
*
|
||||
* @param array<int, float> $scores
|
||||
* Scores keyed by nid.
|
||||
* @param float $margin
|
||||
* Largest gap to the best score.
|
||||
*
|
||||
* @return array<int, float>
|
||||
* The kept scores, keyed by nid.
|
||||
*/
|
||||
public static function nearBest(array $scores, float $margin): array {
|
||||
if (!$scores) {
|
||||
return $scores;
|
||||
}
|
||||
$limit = max($scores) - $margin;
|
||||
return array_filter($scores, static fn ($score) => $score >= $limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,12 @@ final class SearchMessage {
|
||||
|
||||
/**
|
||||
* Message of a search: exact matches out of all the results shown.
|
||||
*
|
||||
* @param string[] $filters
|
||||
* What makes a result exact, when it is not every word: terms chosen in
|
||||
* the autocomplete (Q7), countries as typed (Q6). Named in the message.
|
||||
*/
|
||||
public function results(int $exact, int $total, string $keys, string $lang): TranslatableMarkup {
|
||||
public function results(int $exact, int $total, string $keys, string $lang, array $filters = []): TranslatableMarkup {
|
||||
$args = [
|
||||
'@n' => self::number($exact, $lang),
|
||||
'@total' => self::number($total, $lang),
|
||||
@@ -37,6 +41,19 @@ final class SearchMessage {
|
||||
if ($total === 0) {
|
||||
return $this->translation->translate('No results for “@keys”. Try other words or a broader description.', $args);
|
||||
}
|
||||
$named = self::listing($filters, $lang);
|
||||
// « italien » alone: naming it twice says nothing more.
|
||||
if ($named !== '' && mb_strtolower($named) !== mb_strtolower($keys)) {
|
||||
$args['@filters'] = $named;
|
||||
if ($exact === 0) {
|
||||
$args['@n'] = $args['@total'];
|
||||
return $this->translation->formatPlural($total, 'No exact result for @filters, @n close result for “@keys”', 'No exact result for @filters, @n close results for “@keys”', $args);
|
||||
}
|
||||
if ($total === 1) {
|
||||
return $this->translation->translate('1 exact result for @filters: “@keys”', $args);
|
||||
}
|
||||
return $this->translation->formatPlural($exact, '@n exact result for @filters, out of @total relevant results for “@keys”', '@n exact results for @filters, out of @total relevant results for “@keys”', $args);
|
||||
}
|
||||
if ($exact === 0) {
|
||||
$args['@n'] = $args['@total'];
|
||||
return $this->translation->formatPlural($total, 'No exact result, @n close result for “@keys”', 'No exact result, @n close results for “@keys”', $args);
|
||||
@@ -59,6 +76,21 @@ final class SearchMessage {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* « a », « a et b », « a, b et c » (English: and).
|
||||
*
|
||||
* @param string[] $items
|
||||
* Names.
|
||||
*/
|
||||
public static function listing(array $items, string $lang): string {
|
||||
$items = array_values(array_filter(array_map('trim', $items), 'strlen'));
|
||||
if (count($items) < 2) {
|
||||
return $items[0] ?? '';
|
||||
}
|
||||
$last = array_pop($items);
|
||||
return implode(', ', $items) . ($lang === 'fr' ? ' et ' : ' and ') . $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* A number with the thousands separator of the language.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\materio_sapi\Unit;
|
||||
|
||||
use Drupal\materio_sapi\CountryDetector;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
/**
|
||||
* Tests the countries found in a search phrase (Q6).
|
||||
*/
|
||||
#[CoversClass(CountryDetector::class)]
|
||||
#[Group('materio_sapi')]
|
||||
final class CountryDetectorTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Phrases, countries found and the rest.
|
||||
*/
|
||||
public static function phrases(): array {
|
||||
return [
|
||||
'country name' => ['pigment Italie', ['IT'], 'pigment'],
|
||||
'demonym alone' => ['italien', ['IT'], ''],
|
||||
'feminine plural' => ['céramiques italiennes', ['IT'], 'céramiques'],
|
||||
'english' => ['Italian marble', ['IT'], 'marble'],
|
||||
'longest form first' => ['verre Corée du Sud', ['KR'], 'verre'],
|
||||
'hyphenated' => ['vase Royaume-Uni', ['GB'], 'vase'],
|
||||
'typed without accents' => ['bois bresil', ['BR'], 'bois'],
|
||||
'accent must match' => ['tissu chiné', [], 'tissu chiné'],
|
||||
'word of a country name' => ['new wood', [], 'new wood'],
|
||||
'material, not a country' => ['cuir suède', [], 'cuir suède'],
|
||||
'alias' => ['Made in USA, acier', ['US'], 'Made in, acier'],
|
||||
'two countries' => ['papier japonais ou chinois', ['JP', 'CN'], 'papier ou'],
|
||||
'none' => ['plastique écologique', [], 'plastique écologique'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Countries are found, longest form first, and taken out of the phrase.
|
||||
*/
|
||||
#[DataProvider('phrases')]
|
||||
public function testDetect(string $phrase, array $codes, string $rest): void {
|
||||
$result = CountryDetector::detect($phrase);
|
||||
$this->assertSame($codes, $result['codes']);
|
||||
$this->assertSame($rest, $result['rest']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,6 +47,16 @@ final class RankFusionTest extends UnitTestCase {
|
||||
$this->assertSame([7, 8, 3, 4], RankFusion::fuse([], [[7, 3], [8, 4]]));
|
||||
}
|
||||
|
||||
/**
|
||||
* A lighter list counts less: its first node falls behind (Q8).
|
||||
*/
|
||||
public function testWeights(): void {
|
||||
// Equal weights: 7 and 8 tie, 7 seen first.
|
||||
$this->assertSame([7, 8], RankFusion::fuse([], [[7], [8]]));
|
||||
// Text list at 0.5: 8 (1/61) beats 7 (0.5/61).
|
||||
$this->assertSame([8, 7], RankFusion::fuse([], [[7], [8]], RankFusion::K, [0 => 0.5]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty lists: the exact matches alone, or nothing.
|
||||
*/
|
||||
|
||||
@@ -44,4 +44,14 @@ final class ScoreCutTest extends UnitTestCase {
|
||||
$this->assertSame([], ScoreCut::aboveMean([], 2.0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Near the best score only: the plateau after a gap goes (Q9).
|
||||
*/
|
||||
public function testNearBest(): void {
|
||||
$scores = [1 => 0.772, 2 => 0.758, 3 => 0.739, 4 => 0.729, 5 => 0.722];
|
||||
$this->assertSame([1, 2, 3], array_keys(ScoreCut::nearBest($scores, 0.04)));
|
||||
$this->assertSame([], ScoreCut::nearBest([], 0.04));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,37 @@ final class SearchMessageTest extends UnitTestCase {
|
||||
$this->assertSame($expected, (string) $message->results($exact, $total, 'bois', 'en'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cases with a filter: what makes a result exact is named (Q6, Q7).
|
||||
*/
|
||||
public static function filtersProvider(): array {
|
||||
return [
|
||||
'one term' => [30, 252, 'bois-résiné qui sent bon', ['bois-résiné'], '30 exact results for bois-résiné, out of 252 relevant results for “bois-résiné qui sent bon”'],
|
||||
'terms and country' => [3, 291, 'céramique translucide japon', ['céramique', 'translucide', 'japon'], '3 exact results for céramique, translucide and japon, out of 291 relevant results for “céramique translucide japon”'],
|
||||
'none exact' => [0, 40, 'bois-résiné bleu', ['bois-résiné'], 'No exact result for bois-résiné, 40 close results for “bois-résiné bleu”'],
|
||||
'one alone' => [1, 1, 'tissu Islande', ['Islande'], '1 exact result for Islande: “tissu Islande”'],
|
||||
'country alone' => [586, 586, 'italien', ['italien'], '586 exact results out of 586 relevant results for “italien”'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The filters are named, unless they are the whole phrase.
|
||||
*/
|
||||
#[DataProvider('filtersProvider')]
|
||||
public function testFilters(int $exact, int $total, string $keys, array $filters, string $expected): void {
|
||||
$message = new SearchMessage($this->getStringTranslationStub());
|
||||
$this->assertSame($expected, (string) $message->results($exact, $total, $keys, 'en', $filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* French list: « a, b et c ».
|
||||
*/
|
||||
public function testListing(): void {
|
||||
$this->assertSame('céramique, translucide et Japon', SearchMessage::listing(['céramique', 'translucide', 'Japon'], 'fr'));
|
||||
$this->assertSame('a and b', SearchMessage::listing(['a', 'b'], 'en'));
|
||||
$this->assertSame('', SearchMessage::listing([], 'fr'));
|
||||
}
|
||||
|
||||
/**
|
||||
* The help before any search gives the size of the catalogue.
|
||||
*/
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
+2
-2
File diff suppressed because one or more lines are too long
Binary file not shown.
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -520,9 +520,10 @@ header[role="banner"]{
|
||||
#block-materiosapisearchblock{
|
||||
align-self: flex-end;
|
||||
flex-shrink: 0;
|
||||
// Long enough for a phrase and for the placeholder (F4).
|
||||
width: 30em;
|
||||
max-width: 50%;
|
||||
// Long enough for a phrase and for the placeholder (F4), and for a
|
||||
// few chosen terms as labels next to the text (Q7).
|
||||
width: 40em;
|
||||
max-width: 60%;
|
||||
}
|
||||
// Tablet and mobile: the field on its own line, full width (F5).
|
||||
@include col-mediaquery-max(4){
|
||||
@@ -654,6 +655,32 @@ header[role="banner"]{
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
// Terms chosen in the suggestions, as labels in the field (Q7):
|
||||
// the border goes to the whole line, labels then text.
|
||||
&.has-terms{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.2em;
|
||||
border: 1px #BBB solid;
|
||||
border-radius: 14px;
|
||||
padding: 0.15em 0.3em;
|
||||
box-sizing: border-box;
|
||||
background-color: #fff;
|
||||
&:focus-within{
|
||||
outline: 2px solid #666;
|
||||
outline-offset: 1px;
|
||||
}
|
||||
#edit-search{
|
||||
flex: 1 1 6em;
|
||||
width: auto;
|
||||
min-width: 6em;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
padding: 0.15em;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.button.form-submit{
|
||||
@@ -744,6 +771,37 @@ header[role="banner"]{
|
||||
}
|
||||
|
||||
|
||||
#materio-sapi-search-form ul.search-terms {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.2em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
li {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-radius: 10px;
|
||||
padding: 0 0.1em 0 0.5em;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
font-size: 0.85em;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.search-term-remove {
|
||||
border: 0;
|
||||
padding: 0 0.3em;
|
||||
background: transparent;
|
||||
color: #fff;
|
||||
font-size: 1.1em;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
&:hover, &:focus-visible {
|
||||
color: #ccc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Suggestions of the search field (SearchForm.vue, F7), same look as the
|
||||
// former jQuery UI autocomplete.
|
||||
#materio-sapi-search-form ul.search-suggestions {
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<!-- One field for a phrase in natural language, one button (F1), with
|
||||
suggestions of tags and thesaurus terms on the first two words (F7).
|
||||
Same ids and classes as the former Drupal form, so main.scss applies.
|
||||
Suggestions follow the ARIA combobox pattern (list autocomplete). -->
|
||||
Suggestions follow the ARIA combobox pattern (list autocomplete).
|
||||
A suggestion chosen becomes a label in the field, removable, and the
|
||||
search starts with Enter or the button only (Q7): several terms add
|
||||
up, and the phrase sent keeps their names next to the text typed. -->
|
||||
<form
|
||||
id="materio-sapi-search-form"
|
||||
class="materio-sapi-search-form"
|
||||
@@ -10,7 +13,18 @@
|
||||
@submit.prevent="submit"
|
||||
@keydown.esc="closeHelp"
|
||||
>
|
||||
<div class="form-item form-item-search">
|
||||
<div class="form-item form-item-search" :class="{ 'has-terms': chosen.length }">
|
||||
<ul v-if="chosen.length" class="search-terms" :aria-label="text.termsLabel">
|
||||
<li v-for="(term, i) in chosen" :key="term.value">
|
||||
<span class="search-term-label">{{ term.label }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="search-term-remove"
|
||||
:title="text.removeTerm(term.label)"
|
||||
@click="removeTerm(i)"
|
||||
><span aria-hidden="true">×</span><span class="visually-hidden">{{ text.removeTerm(term.label) }}</span></button>
|
||||
</li>
|
||||
</ul>
|
||||
<input
|
||||
id="edit-search"
|
||||
ref="input"
|
||||
@@ -24,7 +38,7 @@
|
||||
:aria-controls="listId"
|
||||
:aria-activedescendant="active >= 0 ? optionId(active) : null"
|
||||
:maxlength="maxLength"
|
||||
:placeholder="text.placeholder"
|
||||
:placeholder="chosen.length ? '' : text.placeholder"
|
||||
:aria-label="$t('default.Search')"
|
||||
enterkeyhint="search"
|
||||
autocomplete="off"
|
||||
@@ -104,6 +118,8 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
typed: '',
|
||||
// Terms chosen in the suggestions, { value: tid, label: name } (Q7).
|
||||
chosen: [],
|
||||
// Same limit as the backend (Base::MAX_PHRASE_LENGTH, H1).
|
||||
maxLength: 150,
|
||||
suggestions: [],
|
||||
@@ -119,7 +135,8 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
keys: state => state.Search.keys
|
||||
keys: state => state.Search.keys,
|
||||
terms: state => state.Search.terms
|
||||
}),
|
||||
text: searchTexts
|
||||
},
|
||||
@@ -152,7 +169,9 @@ export default {
|
||||
if (id !== this.requestId || !this.suggestible(this.typed)) {
|
||||
return
|
||||
}
|
||||
this.suggestions = Array.isArray(data) ? data : []
|
||||
// Terms already chosen are not suggested again.
|
||||
const chosen = this.chosen.map(t => String(t.value))
|
||||
this.suggestions = (Array.isArray(data) ? data : []).filter(s => !chosen.includes(String(s.value)))
|
||||
this.active = -1
|
||||
this.open = this.suggestions.length > 0
|
||||
const n = this.suggestions.length
|
||||
@@ -163,6 +182,12 @@ export default {
|
||||
})
|
||||
},
|
||||
onKeydown (e) {
|
||||
// Backspace at the start of the field removes the last term (Q7).
|
||||
if (e.key === 'Backspace' && this.chosen.length && e.target.selectionStart === 0 && e.target.selectionEnd === 0) {
|
||||
e.preventDefault()
|
||||
this.removeTerm(this.chosen.length - 1)
|
||||
return
|
||||
}
|
||||
if (!this.open) {
|
||||
return
|
||||
}
|
||||
@@ -199,25 +224,53 @@ export default {
|
||||
this.suggestions = []
|
||||
this.announce = ''
|
||||
},
|
||||
// A suggestion searches that term alone, nothing added (F7).
|
||||
// A suggestion becomes a label in place of the words typed for it; the
|
||||
// search waits for Enter or the button, so that terms add up (Q7).
|
||||
choose (item) {
|
||||
clearTimeout(this.timer)
|
||||
this.requestId++
|
||||
this.close()
|
||||
this.typed = item.label
|
||||
this.go({ keys: item.label, terms: JSON.stringify([{ value: item.value, label: item.label }]) })
|
||||
if (!this.chosen.some(t => String(t.value) === String(item.value))) {
|
||||
this.chosen.push({ value: item.value, label: item.label })
|
||||
}
|
||||
this.typed = ''
|
||||
this.$refs.input.focus()
|
||||
},
|
||||
removeTerm (i) {
|
||||
this.chosen.splice(i, 1)
|
||||
this.$refs.input.focus()
|
||||
},
|
||||
// The phrase: names of the terms, then the text typed. The IDs of the
|
||||
// terms go along, for the exact conditions (Q7).
|
||||
submit () {
|
||||
clearTimeout(this.timer)
|
||||
this.requestId++
|
||||
this.close()
|
||||
const phrase = this.typed.replace(/\s+/g, ' ').trim()
|
||||
// Only the phrase, no terms.
|
||||
this.go(phrase ? { keys: phrase } : {})
|
||||
const phrase = [...this.chosen.map(t => t.label), this.typed].join(' ').replace(/\s+/g, ' ').trim()
|
||||
if (!phrase) {
|
||||
this.go({})
|
||||
return
|
||||
}
|
||||
this.go(this.chosen.length ? { keys: phrase, terms: JSON.stringify(this.chosen) } : { keys: phrase })
|
||||
},
|
||||
// An example of the help runs as a typed phrase.
|
||||
// Labels and text from the search of the URL or of another link: the
|
||||
// text is the phrase without the names of the terms.
|
||||
fromStore () {
|
||||
const terms = Array.isArray(this.terms) ? this.terms.filter(t => t && t.value && t.label) : []
|
||||
let phrase = this.phraseFromKeys(this.keys)
|
||||
for (const t of terms) {
|
||||
const i = phrase.toLowerCase().indexOf(String(t.label).toLowerCase())
|
||||
if (i >= 0) {
|
||||
phrase = phrase.slice(0, i) + phrase.slice(i + String(t.label).length)
|
||||
}
|
||||
}
|
||||
this.chosen = terms.map(t => ({ value: t.value, label: t.label }))
|
||||
this.typed = phrase.replace(/\s+/g, ' ').replace(/^[\s,]+|[\s,]+$/g, '')
|
||||
},
|
||||
// An example of the help runs as a typed phrase, without terms.
|
||||
searchExample (example) {
|
||||
this.helpOpen = false
|
||||
this.chosen = []
|
||||
this.typed = example
|
||||
this.submit()
|
||||
},
|
||||
@@ -242,13 +295,16 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
// The store changes when a search starts from the URL or another link.
|
||||
keys (n) {
|
||||
this.typed = this.phraseFromKeys(n)
|
||||
keys () {
|
||||
this.fromStore()
|
||||
},
|
||||
terms () {
|
||||
this.fromStore()
|
||||
}
|
||||
},
|
||||
created () {
|
||||
// Direct page load: the store already holds the keys of the URL.
|
||||
this.typed = this.phraseFromKeys(this.keys)
|
||||
this.fromStore()
|
||||
},
|
||||
mounted () {
|
||||
document.addEventListener('click', this.onDocumentClick)
|
||||
|
||||
@@ -20,7 +20,10 @@ const TEXTS = {
|
||||
],
|
||||
suggestionsLabel: 'Suggestions',
|
||||
suggestionsOne: '1 suggestion, flèches haut et bas pour choisir',
|
||||
suggestionsMany: n => `${n} suggestions, flèches haut et bas pour choisir`
|
||||
suggestionsMany: n => `${n} suggestions, flèches haut et bas pour choisir`,
|
||||
// Terms chosen in the suggestions (Q7).
|
||||
termsLabel: 'Termes choisis',
|
||||
removeTerm: label => `Retirer ${label}`
|
||||
},
|
||||
en: {
|
||||
placeholder: 'Describe the material you are looking for',
|
||||
@@ -37,7 +40,9 @@ const TEXTS = {
|
||||
],
|
||||
suggestionsLabel: 'Suggestions',
|
||||
suggestionsOne: '1 suggestion, use up and down arrows to choose',
|
||||
suggestionsMany: n => `${n} suggestions, use up and down arrows to choose`
|
||||
suggestionsMany: n => `${n} suggestions, use up and down arrows to choose`,
|
||||
termsLabel: 'Chosen terms',
|
||||
removeTerm: label => `Remove ${label}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user