From c156dfa6c70a898de44fee7fe248ff10dced94e7 Mon Sep 17 00:00:00 2001 From: Sergei Bocharov Date: Tue, 22 Oct 2019 15:27:52 +0300 Subject: [PATCH] Fixes for DOCSUP --- .../functions/string_search_functions.md | 47 +++++----- .../functions/string_search_functions.md | 86 ++++++++++++++++++- 2 files changed, 106 insertions(+), 27 deletions(-) diff --git a/docs/en/query_language/functions/string_search_functions.md b/docs/en/query_language/functions/string_search_functions.md index 19acb29b36..1ff11def0f 100644 --- a/docs/en/query_language/functions/string_search_functions.md +++ b/docs/en/query_language/functions/string_search_functions.md @@ -15,13 +15,14 @@ The same as `position`, but the position is returned in Unicode code points. Wor For a case-insensitive search, use the function `positionCaseInsensitiveUTF8`. -## multiSearchAllPositions(haystack, [needle1, needle2, ..., needlen]) {#multiSearchAllPositions} +## multiSearchAllPositions {#multiSearchAllPositions} -The same as [position](#position) but returns the leftmost offset of the string haystack that is matched to some of the needles. -Returns the position (in bytes) of the found substring, starting from 1, or returns 0 if the substring was not found. -Works under the assumption that the string contains a set of bytes representing a single-byte encoded text. If this assumption is not met, it returns some result. +The same as [position](#position) but returns the array of positions (in bytes) of the found substrings in the string, starting from 1. + +Works under the assumption that the string contains a set of bytes representing a single-byte encoded text. If this assumption is not met and a character can't be represented using a single byte, the function doesn't throw an exception and returns some unexpected result. If character can be represented using two bytes, it will use two bytes and so on. -For a case-insensitive search or/and in UTF-8 format use functions [multiSearchFirstPositionCaseInsensitive](#multisearchfirstpositioncaseinsensitive), [multiSearchFirstPositionUTF8](#multisearchfirstpositionUTF8), [multiSearchFirstPositionCaseInsensitiveUTF8](#multiSearchFirstPositionCaseInsensitiveUTF8). +- For a case-insensitive search, use the function `multiSearchAllPositionsCaseInsensitive`. +- For search in UTF-8 format, use the function [multiSearchAllPositionsUTF8](#multiSearchAllPositionsUTF8). **Syntax** @@ -29,18 +30,17 @@ For a case-insensitive search or/and in UTF-8 format use functions [multiSearchF multiSearchAllPositions(haystack, [needle1, needle2, ..., needlen]) ``` -**Parameters** - -- `haystack` — string, from which substring is to be searched. +**Parameters** -- `needle` — substring, which is to be searched. +- `haystack` — string, in which substring will to be searched. [String](../syntax.md#syntax-string-literal). +- `needle` — substring to be searched. [String](../syntax.md#syntax-string-literal). **Returned values** +- Array of starting positions in bytes (counting from 1), if substrings were found. - 0, if the substring was not found. -- 1 and more, starting index of the first occurrence of the substring in string. -Type: `Integer`. +Type: `Integers[]`. **Example** @@ -58,12 +58,13 @@ Result: └───────────────────────────────────────────────────────────────────┘ ``` +## multiSearchAllPositionsUTF8 {#multiSearchAllPositionsUTF8} -## multiSearchAllPositionsUTF8(haystack, [needle1, needle2, ..., needlen]) {#multiSearchAllPositionsUTF8} +The same as [positionUTF8](#positionutf8), but returns the array of positions (in Unicode points) of the found substrings in the string, starting from 1. -The same as [position](#position) but returns the leftmost offset of the string haystack that is matched to some of the needles. -Works under the assumption that the string contains a set of bytes representing a UTF-8 encoded text. If this assumption is not met, it returns some result (it doesn't throw an exception). -For a case-insensitive search or/and in UTF-8 format use functions [multiSearchFirstPositionCaseInsensitive](#multisearchfirstpositioncaseinsensitive), [multiSearchFirstPosition](#multisearchfirstposition), [multiSearchFirstPositionCaseInsensitiveUTF8](#multisearchfirstpositioncaseinsensitiveUTF8). +Works under the assumption that the string contains a set of bytes representing a UTF-8 encoded text. If this assumption is not met, the function doesn't throw an exception and returns some unexpected result. If character can be represented using two Unicode points, it will use two and so on. + +For a case-insensitive search, use the function `multiSearchAllPositionsCaseInsensitiveUTF8`. **Syntax** @@ -73,31 +74,29 @@ multiSearchAllPositionsUTF8(haystack, [needle1, needle2, ..., needlen]) **Parameters** -- `haystack` — string, from which substring is to be searched. - -- `needle` — substring, which is to be searched. - +- `haystack` — string, in which substring will to be searched. [String](../syntax.md#syntax-string-literal). +- `needle` — substring to be searched. [String](../syntax.md#syntax-string-literal). **Returned values** +- Array of starting positions in Unicode points (counting from 1), if substrings were found. - 0, if the substring was not found. -- 1 and more, starting index of the first occurance of the substring in string. -Type: `Integer`. +Type: `Integers[]`. **Example** Query: ```sql -SELECT multiSearchAllPositionsUTF8('Hello* world!', ['hello', '!', '*']) +SELECT multiSearchAllPositionsUTF8('Привет, мир!', ['Привет', '!', ',']) ``` Result: ```text -┌─multiSearchAllPositionsUTF8('Hello* world!', ['hello', '!', '*'])─┐ -│ [0,13,6] │ +┌─multiSearchAllPositionsUTF8('Привет, мир!', ['Привет', '!', ','])─┐ +│ [1,12,7] │ └───────────────────────────────────────────────────────────────────┘ ``` diff --git a/docs/ru/query_language/functions/string_search_functions.md b/docs/ru/query_language/functions/string_search_functions.md index 1a35947811..c9aaea4358 100644 --- a/docs/ru/query_language/functions/string_search_functions.md +++ b/docs/ru/query_language/functions/string_search_functions.md @@ -13,10 +13,90 @@ Для поиска без учета регистра используйте функцию `positionCaseInsensitiveUTF8`. -## multiSearchAllPositions(haystack, [needle1, needle2, ..., needlen]) -Так же, как и `position`, только возвращает `Array` первых вхождений. +## multiSearchAllPositions {#multiSearchAllPositions} -Для поиска без учета регистра и/или в кодировке UTF-8 используйте функции `multiSearchAllPositionsCaseInsensitive, multiSearchAllPositionsUTF8, multiSearchAllPositionsCaseInsensitiveUTF8`. +Такая же, как и [position](#position), только возвращает массив позиций (в байтах) найденных подстрок в строке, начиная с 1. + +Работает при допущении, что строка содержит набор байт, представляющий текст в однобайтовой кодировке. Если допущение не выполнено — то возвращает неопределенный результат (не кидает исключение). Если символ может быть представлен с помощью двух байтов, он будет представлен двумя байтами и так далее. + +- Для поиска без учета регистра, используйте функцию `multiSearchAllPositionsCaseInsensitive`. +- Для поиска в кодировке UTF-8, используйте функцию [multiSearchAllPositionsUTF8](#multiSearchAllPositionsUTF8). + +**Синтаксис** + +```sql +multiSearchAllPositions(haystack, [needle1, needle2, ..., needlen]) +``` + +**Параметры** + +- `haystack` — строка, по которой выполняется поиск. [Строка](../syntax.md#syntax-string-literal). +- `needle` — подстрока, которую необходимо найти. [Строка](../syntax.md#syntax-string-literal). + +**Возвращаемые значения** + +- Массив начальных позиций в байтах (начиная с 1), если подстроки найдены. +- 0, если подстрока не найдена. + +Тип: `Integers[]`. + +**Пример** + +Запрос: + +```sql +SELECT multiSearchAllPositions('Hello, World!', ['hello', '!', 'world']) +``` + +Ответ: + +```text +┌─multiSearchAllPositions('Hello, World!', ['hello', '!', 'world'])─┐ +│ [0,13,0] │ +└───────────────────────────────────────────────────────────────────┘ +``` + +## multiSearchAllPositionsUTF8 {#multiSearchAllPositionsUTF8} + +Такая же, как и [positionUTF8](#positionutf8), но возвращает массив позиций (в кодовых точках Unicode) найденных подстрок в строке, начиная с 1. + +Работает при допущении, что строка содержит набор кодовых точек, представляющий текст в кодировке UTF-8. Если допущение не выполнено — то возвращает неопределенный результат (не кидает исключение). Если символ может быть представлен с помощью двух кодовых точек, он будет представлен двумя и так далее. + +Для поиска без учета регистра используйте функцию `multiSearchAllPositionsCaseInsensitiveUTF8`. + +**Синтаксис** + +```sql +multiSearchAllPositionsUTF8(haystack, [needle1, needle2, ..., needlen]) +``` + +**Параметры** + +- `haystack` — строка, по которой выполняется поиск. [Строка](../syntax.md#syntax-string-literal). +- `needle` — подстрока, которую необходимо найти. [Строка](../syntax.md#syntax-string-literal). + +**Возвращаемые значения** + +- Массив начальных позиций в кодовых точках Unicode (начиная с 1), если подстроки найдены. +- Массив 0, если подстроки не найдены. + +Тип: `Integers[]`. + +**Пример** + +Запрос: + +```sql +SELECT multiSearchAllPositionsUTF8('Привет, мир!', ['Привет', '!', ',']) +``` + +Ответ: + +```text +┌─multiSearchAllPositionsUTF8('Привет, мир!', ['Привет', '!', ','])─┐ +│ [1,12,7] │ +└───────────────────────────────────────────────────────────────────┘ +``` ## multiSearchFirstPosition(haystack, [needle1, needle2, ..., needlen]) -- GitLab