Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -107,7 +109,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy {
// Methods returning (observable of) suggestions from different sources
const dataSources: Observable<AutocompleteItem[]>[] = 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));
Expand Down Expand Up @@ -161,8 +163,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";
}


Expand All @@ -177,7 +181,7 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy {
this.recentQueriesService.recentqueries,
(query) => query.query.text || "",
undefined,
"msg#searchForm.recentQuery");
"msg#autocomplete.recentQuery");
}

/**
Expand All @@ -191,7 +195,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");
}

/**
Expand All @@ -205,7 +209,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");
}

/**
Expand All @@ -219,9 +223,29 @@ export class AutocompleteComponent implements OnInit, OnChanges, OnDestroy {
this.basketsService.baskets,
(bsk) => bsk.name,
(bsk) => [bsk.description || ""],
"msg#editBasket.title");
"msg#autocomplete.basket");
}

/**
* 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<ScoredAutocompleteItem<undefined,string>[]> {
return this.suggestService.get(this.suggestQuery, text).pipe(
map(items => items
.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}))
)
)
}

// Keyboard navigation and actions

Expand Down
9 changes: 9 additions & 0 deletions projects/vanilla-search/src/locales/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"recentDocument": "Letztes Dokument"
},

"autocomplete": {
"recentQuery": "Letzte Suche",
"savedQuery": "Gespeicherte Suchanfrage",
"recentDocument": "Letztes Dokument",
"basket": "Ablagekorb",
"concepts": "Konzept",
"textlexicon": "Lexikon"
},

"facet": {
"preview": {
"title": "Vorschau"
Expand Down
9 changes: 9 additions & 0 deletions projects/vanilla-search/src/locales/messages/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"recentDocument": "Recent document"
},

"autocomplete": {
"recentQuery": "Recent query",
"savedQuery": "Saved query",
"recentDocument": "Recent document",
"basket": "Collection",
"concepts": "Concept",
"textlexicon": "Lexicon"
},

"baskets": {
"baskets": "Collections",
"addToBasket": "Add to collection",
Expand Down
9 changes: 9 additions & 0 deletions projects/vanilla-search/src/locales/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"recentDocument": "Recent document"
},

"autocomplete": {
"recentQuery": "Recent query",
"savedQuery": "Saved query",
"recentDocument": "Recent document",
"basket": "Collection",
"concepts": "Concept",
"textlexicon": "Lexicon"
},

"baskets": {
"baskets": "Collections",
"addToBasket": "Add to collection",
Expand Down
9 changes: 9 additions & 0 deletions projects/vanilla-search/src/locales/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"recentDocument": "Document récent"
},

"autocomplete": {
"recentQuery": "Requête récente",
"savedQuery": "Requête sauvegardée",
"recentDocument": "Document récent",
"basket": "Collection",
"concepts": "Concept",
"textlexicon": "Lexique"
},

"baskets": {
"baskets": "Collections",
"addToBasket": "Ajouter à la collection",
Expand Down