From 7a11c7aad71789490af3a89f14d65e651069f85d Mon Sep 17 00:00:00 2001 From: jletouze Date: Fri, 12 Jan 2024 20:08:16 +0100 Subject: [PATCH 1/5] translates label for concept and textlexicon suggestion type in autocomplete component --- .../app/search-form/autocomplete.component.ts | 16 ++++++++++++++-- .../vanilla-search/src/locales/messages/de.json | 5 +++++ .../src/locales/messages/en-gb.json | 5 +++++ .../vanilla-search/src/locales/messages/en.json | 5 +++++ .../vanilla-search/src/locales/messages/fr.json | 5 +++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts index 4e70156d5..7723a4ab8 100644 --- a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts +++ b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts @@ -1,5 +1,5 @@ import { Input, Output, Component, EventEmitter, OnInit, OnChanges, SimpleChanges, ChangeDetectionStrategy, ChangeDetectorRef, OnDestroy } from "@angular/core"; -import { AutocompleteItem, SuggestService } from "@sinequa/components/autocomplete"; +import { AutocompleteItem, SuggestService, ScoredAutocompleteItem } from "@sinequa/components/autocomplete"; import { BasketsService } from "@sinequa/components/baskets"; import { PreviewService } from "@sinequa/components/preview"; import { RecentDocumentsService, RecentQueriesService, SavedQueriesService } from "@sinequa/components/saved-queries"; @@ -107,7 +107,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { // Methods returning (observable of) suggestions from different sources const dataSources: Observable[] = this.suggestTypes.map(source => { switch(source) { - case 'suggests': return this.suggestService.get(this.suggestQuery, value); + case 'suggests': return from(this.searchSuggestServices(value)); case 'baskets': return from(this.searchBaskets(value)); case 'recent-documents': return from(this.searchRecentDocuments(value)); case 'recent-queries': return from(this.searchRecentQueries(value)); @@ -222,6 +222,18 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { "msg#editBasket.title"); } + /** + * Search for the input text with app suggest service and return autocomplete items asynchronously + * expects that locales/messages files contains "autocomplete.[item.category]" entry. + * @param text + */ + searchSuggestServices(text: string): Observable[]> { + return this.suggestService.get(this.suggestQuery, text).pipe( + map(items => items + .map(item => ({...item, label:"msg#autocomplete." + item.category})) + ) + ) + } // Keyboard navigation and actions diff --git a/projects/vanilla-search/src/locales/messages/de.json b/projects/vanilla-search/src/locales/messages/de.json index ec0248e32..e21b78b0d 100644 --- a/projects/vanilla-search/src/locales/messages/de.json +++ b/projects/vanilla-search/src/locales/messages/de.json @@ -16,6 +16,11 @@ "recentDocument": "Letztes Dokument" }, + "autocomplete": { + "concept": "Konzept", + "textlexicon": "Lexikon" + }, + "facet": { "preview": { "title": "Vorschau" diff --git a/projects/vanilla-search/src/locales/messages/en-gb.json b/projects/vanilla-search/src/locales/messages/en-gb.json index 53b1b6a8c..226d2d931 100644 --- a/projects/vanilla-search/src/locales/messages/en-gb.json +++ b/projects/vanilla-search/src/locales/messages/en-gb.json @@ -16,6 +16,11 @@ "recentDocument": "Recent document" }, + "autocomplete": { + "concept": "Concept", + "textlexicon": "Lexicon" + }, + "baskets": { "baskets": "Collections", "addToBasket": "Add to collection", diff --git a/projects/vanilla-search/src/locales/messages/en.json b/projects/vanilla-search/src/locales/messages/en.json index 6994363c1..7e9a34da6 100644 --- a/projects/vanilla-search/src/locales/messages/en.json +++ b/projects/vanilla-search/src/locales/messages/en.json @@ -16,6 +16,11 @@ "recentDocument": "Recent document" }, + "autocomplete": { + "concept": "Concept", + "textlexicon": "Lexicon" + }, + "baskets": { "baskets": "Collections", "addToBasket": "Add to collection", diff --git a/projects/vanilla-search/src/locales/messages/fr.json b/projects/vanilla-search/src/locales/messages/fr.json index 4d0162959..0e676da5f 100644 --- a/projects/vanilla-search/src/locales/messages/fr.json +++ b/projects/vanilla-search/src/locales/messages/fr.json @@ -16,6 +16,11 @@ "recentDocument": "Document récent" }, + "autocomplete": { + "concept": "Concept", + "textlexicon": "Lexique" + }, + "baskets": { "baskets": "Collections", "addToBasket": "Ajouter à la collection", From 96057defae7447bc886111d305bcf86e027ac220 Mon Sep 17 00:00:00 2001 From: jletouze Date: Fri, 12 Jan 2024 20:09:01 +0100 Subject: [PATCH 2/5] icons for concept and textlexicon suggestion type in autocomplete component --- .../src/app/search-form/autocomplete.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts index 7723a4ab8..238d7fb8e 100644 --- a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts +++ b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts @@ -161,8 +161,10 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { case "recent-query": return "fas fa-history fa-fw"; case "basket": return "fas fa-inbox fa-fw"; case "saved-query": return "fas fa-save fa-fw"; + case "concept": return "far fa-lightbulb fa-fw"; + case "textlexicon": return "fas fa-feather-alt fa-fw"; } - return "far fa-lightbulb fa-fw"; + return "fas fa-lightbulb fa-fw"; } From 23ca775a6071f5e13803a861f8e6679fe186d9c7 Mon Sep 17 00:00:00 2001 From: jletouze Date: Fri, 12 Jan 2024 20:11:24 +0100 Subject: [PATCH 3/5] message source uniformisation in autocomplete component --- .../src/app/search-form/autocomplete.component.ts | 8 ++++---- projects/vanilla-search/src/locales/messages/de.json | 4 ++++ projects/vanilla-search/src/locales/messages/en-gb.json | 4 ++++ projects/vanilla-search/src/locales/messages/en.json | 4 ++++ projects/vanilla-search/src/locales/messages/fr.json | 4 ++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts index 238d7fb8e..b18a206e4 100644 --- a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts +++ b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts @@ -179,7 +179,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { this.recentQueriesService.recentqueries, (query) => query.query.text || "", undefined, - "msg#searchForm.recentQuery"); + "msg#autocomplete.recentQuery"); } /** @@ -193,7 +193,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { this.recentDocumentsService.recentdocuments, doc => doc.title, doc => ([] as string[]).concat(doc.url1, doc.treepath, doc.authors), - "msg#searchForm.recentDocument"); + "msg#autocomplete.recentDocument"); } /** @@ -207,7 +207,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { this.savedQueriesService.savedqueries, (query) => query.name, (query) => [query.description || "", query.query.text || ""], - "msg#editSavedQuery.title"); + "msg#autocomplete.savedQuery"); } /** @@ -221,7 +221,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { this.basketsService.baskets, (bsk) => bsk.name, (bsk) => [bsk.description || ""], - "msg#editBasket.title"); + "msg#autocomplete.basket"); } /** diff --git a/projects/vanilla-search/src/locales/messages/de.json b/projects/vanilla-search/src/locales/messages/de.json index e21b78b0d..d730cfb24 100644 --- a/projects/vanilla-search/src/locales/messages/de.json +++ b/projects/vanilla-search/src/locales/messages/de.json @@ -17,6 +17,10 @@ }, "autocomplete": { + "recentQuery": "Letzte Suche", + "savedQuery": "Gespeicherte Suchanfrage", + "recentDocument": "Letztes Dokument", + "basket": "Ablagekorb", "concept": "Konzept", "textlexicon": "Lexikon" }, diff --git a/projects/vanilla-search/src/locales/messages/en-gb.json b/projects/vanilla-search/src/locales/messages/en-gb.json index 226d2d931..1a45fb409 100644 --- a/projects/vanilla-search/src/locales/messages/en-gb.json +++ b/projects/vanilla-search/src/locales/messages/en-gb.json @@ -17,6 +17,10 @@ }, "autocomplete": { + "recentQuery": "Recent query", + "savedQuery": "Saved query", + "recentDocument": "Recent document", + "basket": "Collection", "concept": "Concept", "textlexicon": "Lexicon" }, diff --git a/projects/vanilla-search/src/locales/messages/en.json b/projects/vanilla-search/src/locales/messages/en.json index 7e9a34da6..0c79ff3d7 100644 --- a/projects/vanilla-search/src/locales/messages/en.json +++ b/projects/vanilla-search/src/locales/messages/en.json @@ -17,6 +17,10 @@ }, "autocomplete": { + "recentQuery": "Recent query", + "savedQuery": "Saved query", + "recentDocument": "Recent document", + "basket": "Collection", "concept": "Concept", "textlexicon": "Lexicon" }, diff --git a/projects/vanilla-search/src/locales/messages/fr.json b/projects/vanilla-search/src/locales/messages/fr.json index 0e676da5f..7390275be 100644 --- a/projects/vanilla-search/src/locales/messages/fr.json +++ b/projects/vanilla-search/src/locales/messages/fr.json @@ -17,6 +17,10 @@ }, "autocomplete": { + "recentQuery": "Recherche récente", + "savedQuery": "Requête sauvegardée", + "recentDocument": "Document récent", + "basket": "Collection", "concept": "Concept", "textlexicon": "Lexique" }, From 5766fefc73ddfc79d258179f7bddcde98b678bfe Mon Sep 17 00:00:00 2001 From: jletouze Date: Fri, 19 Jan 2024 13:11:00 +0100 Subject: [PATCH 4/5] message source uniformisation in autocomplete component --- projects/vanilla-search/src/locales/messages/de.json | 2 +- projects/vanilla-search/src/locales/messages/en-gb.json | 2 +- projects/vanilla-search/src/locales/messages/en.json | 2 +- projects/vanilla-search/src/locales/messages/fr.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/vanilla-search/src/locales/messages/de.json b/projects/vanilla-search/src/locales/messages/de.json index d730cfb24..68d75ab23 100644 --- a/projects/vanilla-search/src/locales/messages/de.json +++ b/projects/vanilla-search/src/locales/messages/de.json @@ -21,7 +21,7 @@ "savedQuery": "Gespeicherte Suchanfrage", "recentDocument": "Letztes Dokument", "basket": "Ablagekorb", - "concept": "Konzept", + "concepts": "Konzept", "textlexicon": "Lexikon" }, diff --git a/projects/vanilla-search/src/locales/messages/en-gb.json b/projects/vanilla-search/src/locales/messages/en-gb.json index 1a45fb409..54025dd50 100644 --- a/projects/vanilla-search/src/locales/messages/en-gb.json +++ b/projects/vanilla-search/src/locales/messages/en-gb.json @@ -21,7 +21,7 @@ "savedQuery": "Saved query", "recentDocument": "Recent document", "basket": "Collection", - "concept": "Concept", + "concepts": "Concept", "textlexicon": "Lexicon" }, diff --git a/projects/vanilla-search/src/locales/messages/en.json b/projects/vanilla-search/src/locales/messages/en.json index 0c79ff3d7..c9d7dd407 100644 --- a/projects/vanilla-search/src/locales/messages/en.json +++ b/projects/vanilla-search/src/locales/messages/en.json @@ -21,7 +21,7 @@ "savedQuery": "Saved query", "recentDocument": "Recent document", "basket": "Collection", - "concept": "Concept", + "concepts": "Concept", "textlexicon": "Lexicon" }, diff --git a/projects/vanilla-search/src/locales/messages/fr.json b/projects/vanilla-search/src/locales/messages/fr.json index 7390275be..5d8ac6c9f 100644 --- a/projects/vanilla-search/src/locales/messages/fr.json +++ b/projects/vanilla-search/src/locales/messages/fr.json @@ -17,11 +17,11 @@ }, "autocomplete": { - "recentQuery": "Recherche récente", + "recentQuery": "Requête récente", "savedQuery": "Requête sauvegardée", "recentDocument": "Document récent", "basket": "Collection", - "concept": "Concept", + "concepts": "Concept", "textlexicon": "Lexique" }, From b5246c13e6a79f69ab4496a82950bae6bde21fa9 Mon Sep 17 00:00:00 2001 From: jletouze Date: Fri, 19 Jan 2024 13:12:35 +0100 Subject: [PATCH 5/5] don't add label for suggestion type if no locale message --- .../src/app/search-form/autocomplete.component.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts index b18a206e4..757f97f4d 100644 --- a/projects/vanilla-search/src/app/search-form/autocomplete.component.ts +++ b/projects/vanilla-search/src/app/search-form/autocomplete.component.ts @@ -8,6 +8,7 @@ import { AppService } from "@sinequa/core/app-utils"; import { AuditEventType, AuditWebService } from "@sinequa/core/web-services"; import { fromEvent, merge, of, Observable, from, forkJoin, ReplaySubject, Subscription } from "rxjs"; import { debounceTime, map, switchMap } from "rxjs/operators"; +import { IntlService } from "@sinequa/core/intl"; @Component({ @@ -47,6 +48,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { subscription: Subscription; constructor( + public intlService: IntlService, public suggestService: SuggestService, public appService: AppService, public previewService: PreviewService, @@ -232,7 +234,15 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy { searchSuggestServices(text: string): Observable[]> { return this.suggestService.get(this.suggestQuery, text).pipe( map(items => items - .map(item => ({...item, label:"msg#autocomplete." + item.category})) + .map(item => { + const localeMsg = "msg#autocomplete." + item.category; + if (this.intlService.formatMessage(localeMsg) === localeMsg) + return item; + else return ({...item, label:"msg#autocomplete." + item.category}); + } + ) + +// .map(item => ({...item, label:"msg#autocomplete." + item.category})) ) ) }