GOOGLE ADS

mercredi 13 avril 2022

comment faire correspondre une donnée connexe si un mot-clé n'a pas été correctement saisi dans la recherche élastique

J'ai un document contenant un titre avec "Travail acharné et succès". Je dois faire une recherche sur ce document. Et si je tapais "Hardwork" (sans espacement), cela ne renvoyait aucune valeur. mais si j'ai tapé "travail acharné", il renvoie le document.

voici la requête que j'ai utilisée:

const search = qObject.search;
const payload = {
from: skip,
size: limit,
_source: [
"id",
"title",
"thumbnailUrl",
"youtubeUrl",
"speaker",
"standards",
"topics",
"schoolDetails",
"uploadTime",
"schoolName",
"description",
"studentDetails",
"studentId"
],
query: {
bool: {
must: {
multi_match: {
fields: [
"title^2",
"standards.standard^2",
"speaker^2",
"schoolDetails.schoolName^2",
"hashtags^2",
"topics.topic^2",
"studentDetails.studentName^2",
],
query: search,
fuzziness: "AUTO",
},
},
},
},
};

si je cherchais le titre "travail acharné" (espace inclus), il renvoie des données comme celle-ci :

"searchResults": [
{
"_id": "92",
"_score": 19.04531,
"_source": {
"standards": {
"standard": "3",
"categoryType": "STANDARD",
"categoryId": "S3"
},
"schoolDetails": {
"categoryType": "SCHOOL",
"schoolId": "TPS123",
"schoolType": "PUBLIC",
"logo": "91748922mn8bo9krcx71.png",
"schoolName": "Carmel CMI Public School"
},
"studentDetails": {
"studentId": 270,
"studentDp": "164646972124244.jpg",
"studentName": "Nelvin",
"about": "good student"
},
"topics": {
"categoryType": "TOPIC",
"topic": "Motivation",
"categoryId": "MY"
},
"youtubeUrl": "https://www.youtube.com/watch?v=wermQ",
"speaker": "Anna Maria Siby",
"description": "How hardwork leads to success - motivational talk by Anna",
"id": 92,
"uploadTime": "2022-03-17T10:59:59.400Z",
"title": "Hard work & Success",
}
},
]

Et si je recherche le mot clé "Hardwork" (sans espacement), il ne détectera pas ces données. J'ai besoin d'y faire un espace ou j'ai besoin de faire correspondre les données associées avec le mot-clé de recherche. Existe-t-il une solution à ce problème, pouvez-vous m'aider à m'en sortir.


Solution du problème

J'ai fait un exemple en utilisant un analyseur de bardeaux.

Cartographie :

 {
"settings": {
"analysis": {
"filter": {
"shingle_filter": {
"type": "shingle",
"max_shingle_size": 4,
"min_shingle_size": 2,
"output_unigrams": "true",
"token_separator": ""
}
},
"analyzer": {
"shingle_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"shingle_filter"
]
}
}
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "shingle_analyzer"
}
}
}
}

Maintenant, je l'ai testé avec votre terme. Notez que le jeton "travail acharné" a été généré mais que les autres ont également été générés ce qui peut vous poser problème.

GET idx-separator-words/_analyze
{
"analyzer": "shingle_analyzer",
"text": ["Hard work & Success"]
}

Résultats:

{
"tokens": [
{
"token": "hard",
"start_offset": 0,
"end_offset": 4,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "hardwork",
"start_offset": 0,
"end_offset": 9,
"type": "shingle",
"position": 0,
"positionLength": 2
},
{
"token": "hardworksuccess",
"start_offset": 0,
"end_offset": 19,
"type": "shingle",
"position": 0,
"positionLength": 3
},
{
"token": "work",
"start_offset": 5,
"end_offset": 9,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "worksuccess",
"start_offset": 5,
"end_offset": 19,
"type": "shingle",
"position": 1,
"positionLength": 2
},
{
"token": "success",
"start_offset": 12,
"end_offset": 19,
"type": "<ALPHANUM>",
"position": 2
}
]
}

Aucun commentaire:

Enregistrer un commentaire

Comment utiliseriez-vous .reduce() sur des arguments au lieu d'un tableau ou d'un objet spécifique&nbsp;?

Je veux définir une fonction.flatten qui aplatit plusieurs éléments en un seul tableau. Je sais que ce qui suit n'est pas possible, mais...