Skip to main content
Version: 11.14.0

Concepts

This module provides utility functions for parsing, rewriting, and manipulating search concepts in text. Concepts are represented using a pattern syntax (groups, adjacent, exact, regex, token) and are commonly used in advanced search query building.

Types

FullTextPattern

Represents a single parsed pattern from a text string.

type FullTextPattern = {
type: 'group' | 'adjacent' | 'exact' | 'regex' | 'token';
value: string;
op?: '+' | '-';
};
PropertyTypeDescription
typestringThe pattern type
valuestringThe content of the pattern
op'+' | '-'Optional operator: + (required) or - (excluded)

Functions

parseText()

Parses a text string into an array of FullTextPattern objects.

function parseText(text: string): FullTextPattern[]

Example

import { parseText } from '@sinequa/atomic';

parseText('+(foo) -[bar] "baz" /qux/ token');
// [
// { type: 'group', value: 'foo', op: '+' },
// { type: 'adjacent', value: 'bar', op: '-' },
// { type: 'exact', value: 'baz' },
// { type: 'regex', value: 'qux' },
// { type: 'token', value: 'token' }
// ]

rewriteText()

Serializes an array of FullTextPattern objects back into a text string.

function rewriteText(patterns: FullTextPattern[]): string

getConcepts()

Extracts all adjacent pattern values (concepts) from a text string.

function getConcepts(text: string): string[]

Example

import { getConcepts } from '@sinequa/atomic';

getConcepts('This is a +[test] +[sentence].');
// ['test', 'sentence']

addConcepts()

Adds one or more concepts to a text string.

function addConcepts(text: string, concepts: string[], op?: '+' | '-'): string

removeConcept()

Removes a single concept from a text string.

function removeConcept(concept: string, text: string): string

removeConcepts()

Removes all adjacent pattern concepts from a text string.

function removeConcepts(text: string): string
note

Concepts are represented as +[concept] in query text (adjacent group with a + operator).