Skip to main content

Suggestions

Overview

This module provides functionality for retrieving and managing suggestions based on user input. It allows users to:

  • Fetch suggestions for given text input
  • Apply filters to refine suggestion results
  • Specify types of suggestions to include
  • Optionally retrieve the source of each suggestion

These operations enable efficient autocomplete functionality, enhancing user experience in search and input scenarios.

fetchSuggest()

Fetches suggestions based on the provided parameters.

ParameterTypeDescription
suggestQueryNamestringThe name of the suggest query to use.
textstringThe text to get suggestions for.
filterRecord<string, unknown>Optional. A filter to apply to the suggestions.

Contains a list of columns (key/value pairs) to filter.
The columns used within this parameter must be declared in the Filter columns section options of the suggestion lexicon.
example: { "columns": {"docformat": "*", "authors": "*"}, { "filter": { "docformat": "doc"}}}
kindsstring[]Optional. An array of suggestion kinds to include.

Allows overriding the types defined in the suggestion query that are used by default.
To specify several kinds, use the comma as a separator.
By default, all kinds defined in the suggestion lexicon are taken into account.
example "kinds": ["city", "name"]
showSourcesbooleanOptional. When set to true, returns the name of the index column from which the suggested term is extracted

Returns A promise that resolves to an array of Suggestion objects.

Suggestion Type
export interface Suggestion {
category: string;
display: string;
frequency?: string;
id?: string;
normalized?: string;
}

Example

example-fetch-suggest.js
import { fetchSuggest } from "@sinequa/atomic";

// the name of the suggest query to use can be found in autocomplete webservice
// defined in the Admin panel of Sinequa.
// Here, the suggest query name is `su-sba-suggest-query`
const suggestions = await fetchSuggest("su-sba-suggest-query", "tes");
console.log("suggestions", suggestions);
tip

You can retrieve the CCApp object using the fetchApp() function to dynamically find the suggest query associated to your autocomplete webservice.

extract from the CCApp object
{
"webServices": {
"training_autocomplete": {
"description": "default web service for auto-complete",
"webServiceType": "Autocomplete",
"revision": 2,
"enabled": true,
"suggestQueries": "su-sba-suggest-query",
"inputLengthTrigger": "",
"groupSuggestionsByCategory": true,
"useFieldedSearch": true,
"uncollapsedItemsPerCategory": "",
"name": "training_autocomplete"
},
...
}
}

fetchSuggestField()

Fetches suggestions for a specific field.

ParameterTypeDescription
textstringThe text to get suggestions for.
fieldsstring[]An array of field names to fetch suggestions from.
This parameter is required if you set action to suggests
info

Today the action default value is suggests and cannot be modified. So fields parameter is mandatory.

Returns A promise that resolves to an array of Suggestion objects.

Example

example-fetch-suggest-field.js
import { fetchSuggestField } from "@sinequa/atomic";

const suggestions = await fetchSuggestField("tesla", "['doctype', 'docformat']");
console.log("suggestions", suggestions);

fetchSuggestQuery()

Fetches suggestions based on the provided query parameters.

danger

This function is deprecated. Use fetchSuggest instead. This function exists for legacy reasons and could be removed in the futur.

ParameterTypeDescription
suggestQueryNamestringThe name of the suggest query to use.
textstringThe text to get suggestions for.
queryNamestringThe name of the query to use for fetching suggestions.
fieldsstring | string[]Optional array of kinds to filter the suggestions.

Allows overriding the types defined in the suggestion query that are used by default.
To specify several kinds, use the comma as a separator.
By default, all kinds defined in the suggestion lexicon are taken into account.
example "kinds": ["city", "name"]

Returns A promise that resolves to an array of Suggestion objects.

Example

example-fetch-suggest.js
import { fetchSuggestQuery } from "@sinequa/atomic";

// the name of the suggest query to use can be found in autocomplete webservice
// defined in the Admin panel of Sinequa.
// Here, the suggest query name is `su-sba-suggest-query`
const suggestions = await fetchSuggestQuery("su-sba-suggest-query", "tes");
console.log("suggestions", suggestions);