Skip to content

Commit

Permalink
Merge pull request #1930 from reebhub/PHP_sessionBatch3_query
Browse files Browse the repository at this point in the history
[PHP] Client API session batch 3 (querying) [Replace C# samples]
  • Loading branch information
ppekrol authored Oct 15, 2024
2 parents 26cb7ab + 6afad58 commit 2625a31
Show file tree
Hide file tree
Showing 28 changed files with 2,761 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Include Query Explanations

---

{NOTE: }

* When making a query, each document in the query results is assigned a **score**.
This score determines the order by which the documents come back in the results when requesting
to [order by score](../../../../client-api/session/querying/sort-query-results#order-by-score).

* Each document in the results includes this score under the `@index-score` property in its metadata.

* Use `includeExplanations` to get the score details and see how it was calculated.

* In this page:
* [Include explanations in a query](../../../../client-api/session/querying/debugging/include-explanations#include-explanations-in-a-query)
* [View explanations](../../../../client-api/session/querying/debugging/include-explanations#view-explanations)
* [Syntax](../../../../client-api/session/querying/debugging/include-explanations#syntax)
{NOTE/}

---

{PANEL: Include explanations in a query}

{CODE-TABS}
{CODE-TAB:php:query explain@ClientApi\Session\Querying\Debugging\IncludeExplanations.php /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
include explanations()
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{NOTE: }
Please note that the First parameter is optional.
If you intend to use the default options, just paste `null` instead of the options object.
{NOTE/}

{PANEL/}

{PANEL: View explanations}

* The detailed explanations can be viewed from the **Query view** in Studio.

* Running a query with `includeExplanations` will show an additional **Explanations Tab**.

![Figure 1. Explanations in the Studio](images/include-explanations-1.png "Include explanations")

* Sample score details:

![Figure 2. View explanations](images/include-explanations-2.png "View explanation")

{PANEL/}

{PANEL: Syntax}

{CODE:php syntax@ClientApi\Session\Querying\Debugging\IncludeExplanations.php /}

| Parameters | Data type | Description |
| - | - | - |
| **$options** | `?ExplanationOptions` | This object is optional.<br>If you intend to use the default options, place `null` here. |
| **&$explanations** | `Explanations` | <ul><li>A callback function (action) that takes `Explanations` as an argument. It will be called by the client with the resulting `Explanations`.</li> <li>You can interact with resulting Explanations inside your callback.</li></ul> |

{PANEL/}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

* Each document in the results includes this score under the `@index-score` property in its metadata.

* **To get the score details** and see how it was calculated,
you can use `include_explanations` when querying with a [document_query](../../../../client-api/session/querying/document-query/what-is-document-query).
* Use `include_explanations` to get the score details** and see how it was calculated.

* In this page:
* [Include explanations in a query](../../../../client-api/session/querying/debugging/include-explanations#include-explanations-in-a-query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

* By default, the timings stats are Not included in the query results, to avoid the measuring overhead.

* __To include the query timings__ in the query results:
* **To include the query timings** in the query results:
add a call to `Timings()` in your query code, or add `include timings()` to an RQL query.
See examples below.

Expand Down Expand Up @@ -41,9 +41,9 @@ include timings()

{PANEL: View timings}

* The detailed timings can be viewed from the [Query view](../../../../studio/database/queries/query-view) in the Studio.
* The detailed timings can be viewed from Studio's [Query view](../../../../studio/database/queries/query-view).

* Running an RQL query with `include timings()` will show an additional __Timings Tab__
* Running an RQL query with `include timings()` will show an additional **Timings Tab**
with a graphical representation of the time spent in each query part.

![Figure 1. Include timings graphical results](images/include-timings.png "Include timings results")
Expand All @@ -56,11 +56,11 @@ include timings()

| Parameter | Type | Description |
|-------------|----------------|-------------------------------------------------------------|
| __timings__ | `QueryTimings` | An _out_ param that will be filled with the timings results |
| ****timings** | `QueryTimings` | An _out_ param that will be filled with the timings results |

| `QueryTimings` | | |
|------------------|-------------------------------------|---------------------------------------------------|
| __DurationInMs__ | `long` | Total duration |
| __Timings__ | `IDictionary<string, QueryTimings>` | Dictionary with `QueryTimings` info per time part |
| **DurationInMs** | `long` | Total duration |
| **Timings** | `IDictionary<string, QueryTimings>` | Dictionary with `QueryTimings` info per time part |

{PANEL/}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

* By default, the timings stats are Not included in the query results, to avoid the measuring overhead.

* __To include the query timings__ in the query results:
* **To include the query timings** in the query results:
add a call to `timings()` in your query code, or add `include timings()` to an RQL query.
See examples below.

Expand Down Expand Up @@ -38,9 +38,9 @@ include timings()

{PANEL: View timings}

* The detailed timings can be viewed from the [Query view](../../../../studio/database/queries/query-view) in the Studio.
* The detailed timings can be viewed from Studio's [Query view](../../../../studio/database/queries/query-view).

* Running an RQL query with `include timings()` will show an additional __Timings Tab__
* Running an RQL query with `include timings()` will show an additional **Timings Tab**
with a graphical representation of the time spent in each query part.

![Figure 1. Include timings graphical results](images/include-timings.png "Include timings results")
Expand All @@ -53,11 +53,11 @@ include timings()

| Parameter | Type | Description |
|---------------------|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| __timingsCallback__ | `(timingsCallback) => void` | <ul><li>A callback function with an output parameter.</li><li>The parameter passed to the callback will be filled with the `QueryTimings` object when query returns.</li></ul> |
| **timingsCallback** | `(timingsCallback) => void` | <ul><li>A callback function with an output parameter.</li><li>The parameter passed to the callback will be filled with the `QueryTimings` object when query returns.</li></ul> |

| `QueryTimings` | | |
|------------------|--------------------------------|---------------------------------------------------|
| __durationInMs__ | `number` | Total duration |
| __timings__ | `Record<string, QueryTimings>` | Dictionary with `QueryTimings` info per time part |
| **durationInMs** | `number` | Total duration |
| **timings** | `Record<string, QueryTimings>` | Dictionary with `QueryTimings` info per time part |

{PANEL/}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Include Query Timings

---

{NOTE: }

* When making a query,
you can request to get detailed stats of the time spent by RavenDB on each part of the query.
E.g. duration of search, loading documents, transforming results, total duration, etc.

* By default, the timings stats are Not included in the query results, to avoid the measuring overhead.

* **To include the query timings** in the query results:
add a call to the `timings()` method in your query code, or add `include timings()` to an RQL query.
See examples below.

* In this page:
* [Include timings in a query](../../../../client-api/session/querying/debugging/query-timings#include-timings-in-a-query)
* [View timings](../../../../client-api/session/querying/debugging/query-timings#view-timings)
* [Syntax](../../../../client-api/session/querying/debugging/query-timings#syntax)

{NOTE/}

---

{PANEL: Include timings in a query}

{CODE-TABS}
{CODE-TAB:php:query timing_2@ClientApi\Session\Querying\Debugging\IncludeQueryTimings.php /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
include timings()
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: View timings}

* The detailed timings can be viewed from Studio's [Query view](../../../../studio/database/queries/query-view).

* Running an RQL query with `include timings()` will show an additional **Timings Tab**
with a graphical representation of the time spent in each query part.

![Figure 1. Include timings graphical results](images/include-timings.png "Include timings results")

{PANEL/}

{PANEL: Syntax}

{CODE:php syntax@ClientApi\Session\Querying\Debugging\IncludeQueryTimings.php /}

| Parameter | Type | Description |
|-------------|----------------|---------------|
| **&$timings** | `QueryTimings` | A callback function (action) that takes `QueryTimings` as an argument. It will be called by the client with the resulting `QueryTimings`. You can interact with the resulting `QueryTimings` inside your callback. |

{PANEL/}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include timings()

{PANEL: View timings}

* The detailed timings can be viewed from the [Query view](../../../../studio/database/queries/query-view) in the Studio.
* The detailed timings can be viewed from Studio's [Query view](../../../../studio/database/queries/query-view).

* Running an RQL query with `include timings()` will show an additional **Timings Tab**
with a graphical representation of the time spent in each query part.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Boost Search Results

---

{NOTE: }

* When querying with some filtering conditions,
a basic score is calculated for each document in the results by the underlying engine.

* Providing a boost value to some fields allows you to prioritize the resulting documents.
The boost value is integrated with the basic score, making the document rank higher.

* Boosting can be achieved in the following ways:

* **At query time**:
Apply a boost factor to searched terms at query time - as described in this article.

* **Via index definition**:
Apply a boost factor in your index definition - see this [boosting](../../../../indexes/boosting) indexing article.

* The automatic ordering of the results by the score is configurable.
Learn more here: [automatic score-based ordering](../../../../indexes/boosting#automatic-score-based-ordering)

* The calculated score details of the results can be retrieved if needed.
Learn more here: [get resulting score](../../../../client-api/session/querying/sort-query-results#get-resulting-score)

* In this page:

* [Boost results - when making a full-text search](../../../../client-api/session/querying/text-search/boost-search-results#boost-results---when-making-a-full-text-search)
* [Boost results - when querying with where clause](../../../../client-api/session/querying/text-search/boost-search-results#boost-results---when-querying-with-where-clause)

{NOTE/}

---

{PANEL: Boost results - when making a full-text search}

To apply boosting while running a full-text search, use the
`boost()` method to prioritize the preceding `search()` results.

{CODE-TABS}
{CODE-TAB:php:query boost_1@ClientApi\Session\Querying\TextSearch\BoostResults.php /}
{CODE-TAB:csharp:documentQuery boost_3@ClientApi\Session\Querying\TextSearch\BoostResults.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from "Employees" where
search(Notes, "English") or boost(search(Notes, "Italian"), 10)
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Boost results - when querying with where clause}

`boost()` can be used to give different priorities to the results
returned by different `where` clauses.

{CODE-TABS}
{CODE-TAB:php:query boost_4@ClientApi\Session\Querying\TextSearch\BoostResults.php /}
{CODE-TAB-BLOCK:sql:RQL}
from "Companies" where
boost(startsWith(Name, "O"), 10) or
boost(startsWith(Name, "P"), 50) or
boost(endsWith(Name, "OP"), 90)
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

## Related Articles

### Session

- [Query overview](../../../../client-api/session/querying/how-to-query)
- [Full-text search](../../../../client-api/session/querying/text-search/full-text-search)

### Indexes

- [Full-text search with index](../../../../indexes/querying/searching)
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# where_ends_with Query

---

{NOTE: }

* You can query for documents having a field that ends with some specified string.

* Unless explicitly specified, the string comparisons are case-insensitive by default.

* **Note**:
This postfix search causes the server to perform a full index scan.
Instead, consider using a static index that indexes the field in reverse order
and then query with a [prefix search](../../../../client-api/session/querying/text-search/starts-with-query), which is much faster.

* In this page:
* [where_ends_with](../../../../client-api/session/querying/text-search/ends-with-query#where_ends_with)
* [where_ends_with (case-sensitive)](../../../../client-api/session/querying/text-search/ends-with-query#where_ends_with-(case-sensitive))
* [Negate where_ends_with](../../../../client-api/session/querying/text-search/ends-with-query#negate-where_ends_with)

{NOTE/}

---

{PANEL: where_ends_with}

{CODE-TABS}
{CODE-TAB:php:query endsWith_1@ClientApi\Session\Querying\TextSearch\EndsWith.php /}
{CODE-TAB:csharp:documentQuery endsWith_3@ClientApi\Session\Querying\TextSearch\EndsWith.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where endsWith(Name, "Lager")
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: where_ends_with (case-sensitive)}

{CODE-TABS}
{CODE-TAB:php:query endsWith_4@ClientApi\Session\Querying\TextSearch\EndsWith.php /}
{CODE-TAB:csharp:documentQuery endsWith_6@ClientApi\Session\Querying\TextSearch\EndsWith.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where exact(endsWith(Name, "Lager"))
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Negate where_ends_with}

{CODE-TABS}
{CODE-TAB:php:query endsWith_7@ClientApi\Session\Querying\TextSearch\EndsWith.php /}
{CODE-TAB:csharp:documentQuery endsWith_9@ClientApi\Session\Querying\TextSearch\EndsWith.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where (true and not endsWith(Name, "Lager"))
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

## Related Articles

### Session

- [Query overview](../../../../client-api/session/querying/how-to-query)
- [Starts-With query](../../../../client-api/session/querying/text-search/starts-with-query)
- [Full-text search](../../../../client-api/session/querying/text-search/full-text-search)

### Indexes

- [map indexes](../../../../indexes/map-indexes)
Loading

0 comments on commit 2625a31

Please sign in to comment.