Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing functions #849

Merged
merged 11 commits into from
Sep 16, 2024
14 changes: 14 additions & 0 deletions doc-surrealql_versioned_docs/version-latest/datamodel/casting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ In the SurrealDB type system, values can be converted to other values efficientl
</tr>
</thead>
<tbody>
<tr>
<td scope="row" data-label="Type"><a href="#array"><code>&lt;array&gt;</code></a></td>
<td scope="row" data-label="Description">Casts the subsequent value into an array</td>
</tr>
<tr>
<td scope="row" data-label="Type"><a href="#bool"><code>&lt;bool&gt;</code></a></td>
<td scope="row" data-label="Description">Casts the subsequent value into a boolean</td>
Expand Down Expand Up @@ -65,6 +69,16 @@ In the SurrealDB type system, values can be converted to other values efficientl
</tbody>
</table>

## `<array>`

The &lt;array&gt; casting function converts a range into an array.

```surql
SELECT * FROM <array> 1..=3;

[1, 2, 3]
```

## `<bool>`

The &lt;bool&gt; casting function converts a value into a boolean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ SurrealDB has many built-in functions designed to handle many common database ta
<td scope="row" data-label="Function"><a href="/docs/surrealql/functions/database/meta"><code>Meta</code></a></td>
<td scope="row" data-label="Description and Example">These functions can be used to retrieve specific metadata from a SurrealDB Record ID. As of version 2.0, these functions are deprecated and replaced with SurrealDB's <code>record</code> functions.</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="/docs/surrealql/functions/database/not"><code>Not</code></a></td>
<td scope="row" data-label="Description and Example">This function reverses the truthiness of a value.<br/>Example: <code>not(true)</code></td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="/docs/surrealql/functions/database/object"><code>Object</code></a></td>
<td scope="row" data-label="Description and Example">These functions can be used when working with, and manipulating data objects.<br/>Example: <code>object::from_entries([[ "a", 1 ],[ "b", true ]])</code></td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
sidebar_position: 12
sidebar_label: Not function
title: Count function | SurrealQL
description: This function can be used to reverse the truthiness of a value.
---

# Not function

This function can be used to reverse the truthiness of a value.

<table>
<thead>
<tr>
<th scope="col">Function</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row" data-label="Function"><a href="#not"><code>not()</code></a></td>
<td scope="row" data-label="Description">Reverses the truthiness of a value.</td>
</tr>
</tbody>
</table>

## `not`

The `not` function reverses the truthiness of a value. It is functionally identical to `!`, the [NOT](/docs/surrealql/operators#not) operator.

```surql title="API DEFINITION"
not(any) -> bool
```

```surql
RETURN not("I speak the truth");

false
```

A value is not [truthy](/docs/surrealql/datamodel/values#values-and-truthiness) if it is NONE, NULL, false, empty, or has a value of 0. As such, all the following return `true`.

```surql
RETURN [
not(""),
not(false),
not([]),
not({}),
not(0)
];
```

Similarly, the function can be used twice to determine whether a value is truthy or not. As each item in the example below is truthy, calling `not()` twice will return the value `true` for each.

```surql
RETURN [
not(not("I have value")),
not(not(true)),
not(not(["value!"])),
not(not({i_have: "value"})),
not(not(100))
];
```

Doubling the `!` operator is functionally identical to the above and is a more commonly seen pattern.

```surql
RETURN [
!!"I have value",
!!true,
!!["value!"],
!!{i_have: "value"},
!!100
];
```

<br /><br />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 12
sidebar_position: 13
sidebar_label: Object functions
title: Object functions | SurrealQL
description: These functions can be used when working with, and manipulating data objects.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 13
sidebar_position: 14
sidebar_label: Parse functions
title: Parse functions | SurrealQL
description: These functions can be used when parsing email addresses and URL web addresses.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 14
sidebar_position: 15
sidebar_label: Rand functions
title: Rand functions | SurrealQL
description: These functions can be used when generating random data values.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 15
sidebar_position: 16
sidebar_label: Record functions
title: Record functions | SurrealQL
description: These functions can be used to retrieve specific metadata from a SurrealDB Record ID.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 16
sidebar_position: 17
sidebar_label: Search functions
title: Search functions | SurrealQL
description: These functions are used in conjunction with the 'matches' operator to either collect the relevance score or highlight the searched keywords within the content.
Expand All @@ -18,20 +18,23 @@ These functions are used in conjunction with the [`@@` operator (the 'matches' o
</thead>
<tbody>
<tr>
<td scope="row" data-label="Function"><a href="#searchscore"><code>search::score()</code></a></td>
<td scope="row" data-label="Description">Returns the relevance score</td>
<td scope="row" data-label="Function"><a href="#searchanalyze"><code>search::analyze()</code></a></td>
<td scope="row" data-label="Description">Returns the output of a defined search analyzer</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#searchhighlight"><code>search::highlight()</code></a></td>
<td scope="row" data-label="Description">Highlights the matching keywords</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#searchoffsets"><code>search::offsets()</code></a></td>
<td scope="row" data-label="Description">Returns the position of the matching keywords</td>
</tr>
<tr>
<td scope="row" data-label="Function"><a href="#searchscore"><code>search::score()</code></a></td>
<td scope="row" data-label="Description">Returns the relevance score</td>
</tr>
</tbody>
</table>

<br/>
The examples below assume the following queries:

```surql
Expand All @@ -40,21 +43,65 @@ DEFINE ANALYZER book_analyzer TOKENIZERS blank, class, camel, punct FILTERS snow
DEFINE INDEX book_title ON book FIELDS title SEARCH ANALYZER book_analyzer BM25;
```

## `search::analyze`

The `search_analyze` function returns the outut of a defined search analyzer on an input string.

```surql title="API DEFINITION"
search::analyze(analyzer, string) -> array<string>
```

First define the analyzer using the [`DEFINE ANALYZER`](/docs/surrealql/statements/define/analyzer) statement

```surql title="Define book analyzer"
DEFINE ANALYZER book_analyzer TOKENIZERS blank, class, camel, punct FILTERS snowball(english);
```

Next you can pass the analyzer to the `search::analyze`function. The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealql/statements/return) statement:

```surql
RETURN search::analyze("book_analyzer", "A hands-on guide to developing, packaging, and deploying fully functional Rust web applications");
```

```bash title="Output"
[
'a',
'hand',
'-',
'on',
'guid',
'to',
'develop',
',',
'packag',
',',
'and',
'deploy',
'fulli',
'function',
'rust',
'web',
'applic'
]
```

## `search::score`

The `search::score` returns the relevance score corresponding to the given 'matches' predicate reference numbers.
The `search::score` function returns the relevance score corresponding to the given 'matches' predicate reference numbers.

```surql title="API DEFINITION"
search::score(number) -> number
```

The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealql/statements/return) statement:

```surql
SELECT id, title, search::score(1) AS score FROM book
WHERE title @1@ 'rust web'
ORDER BY score DESC;
```


```bash title="Output"
[
{
id: book:1,
Expand All @@ -68,7 +115,7 @@ SELECT id, title, search::score(1) AS score FROM book

## `search::highlight`

The `search::highlight` highlights the matching keywords for the predicate reference number.
The `search::highlight` function highlights the matching keywords for the predicate reference number.

```surql title="API DEFINITION"
search::highlight(string, string, number, [boolean]) -> string | string[]
Expand All @@ -78,8 +125,9 @@ The following example shows this function, and its output, when used in a [`RETU
```surql
SELECT id, search::highlight('<b>', '</b>', 1) AS title
FROM book WHERE title @1@ 'rust web';
```


```bash title="Output"
[
{
id: book:1,
Expand All @@ -96,7 +144,7 @@ The default value is true.

## `search::offsets`

The `search::offsets` returns the position of the matching keywords for the predicate reference number.
The `search::offsets` function returns the position of the matching keywords for the predicate reference number.

```surql title="API DEFINITION"
search::offsets(number, [boolean]) -> object
Expand All @@ -106,8 +154,9 @@ The following example shows this function, and its output, when used in a [`RETU
```surql
SELECT id, title, search::offsets(1) AS title_offsets
FROM book WHERE title @1@ 'rust web';
```


```bash title="Output"
[
{
id: book:1,
Expand All @@ -121,6 +170,7 @@ SELECT id, title, search::offsets(1) AS title_offsets
}
]
```

The output returns the start `s` and end `e` positions of each matched term found within the original field.

The full-text index is capable of indexing both single strings and arrays of strings. In this example, the key `0` indicates that we're highlighting the first string within the `title` field, which contains an array of strings.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 17
sidebar_position: 18
sidebar_label: Session functions
title: Session functions | SurrealQL
description: These functions return information about the current SurrealDB session.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 18
sidebar_position: 19
sidebar_label: Sleep function
title: Sleep function | SurrealQL
description: This function can be used to introduce a delay or pause in the execution of a query or a batch of queries for a specific amount of time.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 19
sidebar_position: 20
sidebar_label: String functions
title: String functions | SurrealQL
description: These functions can be used when working with and manipulating text and string values.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 20
sidebar_position: 21
sidebar_label: Time functions
title: Time functions | SurrealQL
description: These functions can be used when working with and manipulating datetime values.
Expand Down
Loading