Atomic Angular — Doc interne

Autocomplete

Suggestions as the user types — from configured suggest queries on the server, and from the user's own recent/saved searches and bookmarks.

Two independent sources feed a search box's suggestions: AutocompleteService asks the server's configured suggest queries, and separately reads the user's own history (recent/saved searches, bookmarks) client-side.

Minimal example

Server suggestions, as the user types
search-box.component.ts
import { Component, inject, signal } from "@angular/core";
import { AutocompleteService } from "@sinequa/atomic-angular";

@Component({
  selector: "search-box",
  template: `<input (input)="onInput($any($event.target).value)" aria-label="Search" />`,
})
export class SearchBoxComponent {
  private readonly autocomplete = inject(AutocompleteService);
  protected readonly suggestions = signal<string[]>([]);

  protected async onInput(text: string) {
    // One array per configured suggest query; flatten for a single list.
    const groups = await this.autocomplete.getFromSuggestQueriesForText(text);
    this.suggestions.set(groups.flat().map((suggestion) => suggestion.display ?? suggestion.normalized));
  }
}

Recipes

Mixing in the user's own history

Recent searches, saved searches and bookmarks, client-side
search-box.component.ts
import { Component, inject } from "@angular/core";
import { AutocompleteService } from "@sinequa/atomic-angular";

@Component({
  selector: "search-box",
  template: ``,
})
export class SearchBoxComponent {
  private readonly autocomplete = inject(AutocompleteService);

  protected onInput(text: string) {
    // Synchronous — no request, since the source is already in memory.
    const fromHistory = this.autocomplete.getFromUserSettingsForText(text, 5);
    console.log(fromHistory);
  }
}

getFromUserSettingsForText groups its results by recent-searches, saved-searches and bookmarks — enough to render each group under its own heading, or to merge and cap them, as the caller prefers.

Options

Prop

Type

What's next

On this page