Skip to content

Commit

Permalink
Merge pull request #1956 from Danielle9897/RDoc-2307-addIncludeExplan…
Browse files Browse the repository at this point in the history
…ationsForIndexesQuerying

RDoc-2307 + RDoc-3138 Add include explanations when querying index
  • Loading branch information
ppekrol authored Dec 11, 2024
2 parents ae80991 + 56e5125 commit 093a9c9
Show file tree
Hide file tree
Showing 18 changed files with 788 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
* 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 `IncludeExplanations` when querying with a [DocumentQuery](../../../../client-api/session/querying/document-query/what-is-document-query).
use method `IncludeExplanations`, which is available in the [IDocumentQuery](../../../../client-api/session/querying/document-query/what-is-document-query) interface.

{INFO: }
* Including explanations is available only when using **Lucene** as the underlying search engine.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).
{INFO/}

---

* This article provides examples of including explanations when making a **dynamic-query**.
For including explanations when querying a **static-index** see [Include explanations in index query](../../../../indexes/querying/include-explanations).

* In this page:
* [Include explanations in a query](../../../../client-api/session/querying/debugging/include-explanations#include-explanations-in-a-query)
Expand All @@ -24,8 +34,10 @@
{PANEL: Include explanations in a query}

{CODE-TABS}
{CODE-TAB:csharp:DocumentQuery explain@ClientApi\Session\Querying\Debugging\IncludeExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery_async explain_async@ClientApi\Session\Querying\Debugging\IncludeExplanations.cs /}
{CODE-TAB:csharp:Query explain_1@ClientApi\Session\Querying\Debugging\IncludeExplanations.cs /}
{CODE-TAB:csharp:Query_async explain_1_async@ClientApi\Session\Querying\Debugging\IncludeExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery explain_2@ClientApi\Session\Querying\Debugging\IncludeExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery_async explain_2_async@ClientApi\Session\Querying\Debugging\IncludeExplanations.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
Expand Down Expand Up @@ -53,12 +65,12 @@ include explanations()

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

| Parameters | Data type | Description |
| - | - | - |
| Parameter | Type | Description |
|------------------|----------------|------------------------------------------------------------------|
| **explanations** | `Explanations` | An _out_ param that will be filled with the explanations results |

| `Explanations` | |
| - | - |
| `Explanations` | |
|------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `string[] GetExplanations(string docId)` | <ul><li>Pass the resulting document ID for which to get score details.</li><li>Returns a list with all explanations.</li></ul> |

{PANEL/}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

`includeExplanations` allows to investigate details related to score assigned for each query result.

{INFO: }

* Including explanations is available only when using **Lucene** as the underlying search engine.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).

{INFO/}

---

## Syntax


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

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

{INFO: }
* Including explanations is available only when using **Lucene** as the underlying search engine.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).
{INFO/}

---

* This article provides examples of including explanations when making a **dynamic-query**.
For including explanations when querying a **static-index** see [Include explanations in index query](../../../../indexes/querying/include-explanations).

* 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)
Expand All @@ -23,7 +33,7 @@
{PANEL: Include explanations in a query}

{CODE-TABS}
{CODE-TAB:nodejs:Query explain@client-api\session\Querying\Debugging\includeExplanations.js /}
{CODE-TAB:nodejs:Query explain@client-api\session\querying\debugging\includeExplanations.js /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
Expand All @@ -48,13 +58,12 @@ include explanations()

{PANEL: Syntax}

{CODE:nodejs syntax@client-api\session\Querying\Debugging\includeExplanations.js /}
{CODE:nodejs syntax@client-api\session\querying\debugging\includeExplanations.js /}

| Parameters | Data type | Description |
| - | - | - |
| Parameter | Type | Description |
|--------------------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **explanationsCallback** | `(explanationsResults) => void` | <ul><li>A callback function with an output parameter.</li><li>The parameter passed to the callback will be filled with the `Explanations` object when query returns.</li></ul> |

<small> **The Explanations object**: </small>
{CODE:nodejs syntax_2@client-api\session\Querying\Debugging\includeExplanations.js /}
{CODE:nodejs syntax_2@client-api\session\querying\debugging\includeExplanations.js /}

{PANEL/}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

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

{INFO: }
* Including explanations is available only when using **Lucene** as the underlying search engine.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).
{INFO/}

---

* 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)
Expand Down Expand Up @@ -56,9 +63,9 @@ If you intend to use the default options, just paste `null` instead of the optio

{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> |
| Parameter | 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 @@ -12,10 +12,18 @@

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

{INFO: }
* Including explanations is available only when using **Lucene** as the underlying search engine.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).
{INFO/}

---

* 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/}

---
Expand Down Expand Up @@ -51,13 +59,13 @@ include explanations()

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

| Parameters | Data type | Description |
| - | - | - |
| Parameter | Type | Description |
|---------------------------|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **explanations_callback** | `Callable[[Explanations], None]` | <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> |
| **options** (Optional) | `ExplanationOptions` | Can be a `group_key` string |
| **options** (Optional) | `ExplanationOptions` | Can be a `group_key` string |

| `Explanations` | |
| - | - |
| `Explanations` | |
|------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `Dict[str, List[str]]` | <ul><li>Pass the resulting document ID for which to get score details.</li><li>Returns a list with all explanations.</li></ul> |

{PANEL/}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{PANEL: Include timings in a query}

{CODE-TABS}
{CODE-TAB:nodejs:Query timing@client-api\session\Querying\Debugging\includeQueryTimings.js /}
{CODE-TAB:nodejs:Query timing@client-api\session\querying\debugging\includeQueryTimings.js /}
{CODE-TAB-BLOCK:sql:RQL}
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
Expand All @@ -49,7 +49,7 @@ include timings()

{PANEL: Syntax}

{CODE:nodejs syntax@client-api\session\Querying\Debugging\includeQueryTimings.js /}
{CODE:nodejs syntax@client-api\session\querying\debugging\includeQueryTimings.js /}

| Parameter | Type | Description |
|---------------------|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
}
]
},
{
"Path": "include-explanations.markdown",
"Name": "Include Explanations",
"DiscussionId": "1e87be90-10c0-4e10-ad2a-bcbe6c481751",
"Mappings": []
},
{
"Path": "/graph",
"Name": "Graph API",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Include Explanations in Index Query

---

{NOTE: }

* This article provides examples of including explanations when querying a static-index.

* **Prior to this article**, please refer to [Include Query Explanations](../../client-api/session/querying/debugging/include-explanations) for dynamic-query examples
and general knowledge about including explanations to retrieve the score of resulting documents.

{INFO: }
* Including explanations is available only when using **Lucene** as the underlying search engine for static-indexes.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).
{INFO/}

---

* In this page:
* [Include explanations when querying Map index](../../indexes/querying/include-explanations#include-explanations-when-querying-map-index)
* [Include explanations when querying Map-Reduce index](../../indexes/querying/include-explanations#include-explanations-when-querying-map-reduce-index)
* [Syntax](../../indexes/querying/include-explanations#syntax)

{NOTE/}

---

{PANEL: Include explanations when querying Map index}

{CODE-TABS}
{CODE-TAB:csharp:Map_index index_1@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:Query inc_1@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:Query_async inc_1_async@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery inc_2@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery_async inc_2_async@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from index "Products/BySearchName"
where search(Name, "Syrup Lager")
include explanations()
// Or:
from index "Products/BySearchName"
where search(Name, "Syrup") or search(Name, "Lager")
include explanations()
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Include explanations when querying Map-Reduce index}

{CODE-TABS}
{CODE-TAB:csharp:Map_Reduce_index index_2@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:Query inc_3@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:Query_async inc_3_async@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery inc_4@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB:csharp:DocumentQuery_async inc_4_async@Indexes\Querying\IncludingExplanations.cs /}
{CODE-TAB-BLOCK:sql:RQL}
from index "NumberOfUnitsOrdered/PerCategory"
where NumberOfUnitsOrdered > 400
include explanations($p0)
{"p0" : { "GroupKey" : "Category" }}
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Syntax}

{CODE syntax_1@Indexes\Querying\IncludingExplanations.cs /}

| Parameter | Type | Description |
|-------------------|----------------------|-------------------------------------------------------------------------|
| **explanations** | `Explanations` | An _out_ param that will be filled with the explanations results. |
| **options** | `ExplanationOptions` | An object that specifies the GroupKey when querying a Map-Reduce index. |

{CODE syntax_2@Indexes\Querying\IncludingExplanations.cs /}
{CODE syntax_3@Indexes\Querying\IncludingExplanations.cs /}

{PANEL/}

## Related Articles

#### Client API

- [Query Overview](../../client-api/session/querying/how-to-query)

### Indexes

- [Indexing Basics](../../indexes/indexing-basics)

### Querying

- [Query an Index](../../indexes/querying/query-index)
- [Filtering](../../indexes/querying/filtering)
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Include Explanations in Index Query

---

{NOTE: }

* This article provides examples of including explanations when querying a static-index.

* **Prior to this article**, please refer to [Include Query Explanations](../../client-api/session/querying/debugging/include-explanations) for dynamic-query examples
and general knowledge about including explanations to retrieve the score of resulting documents.

{INFO: }
* Including explanations is available only when using **Lucene** as the underlying search engine for static-indexes.
* You can configure which search engine will be used. Learn how in [Selecting the search engine](../../indexes/search-engine/corax#selecting-the-search-engine).
{INFO/}

---

* In this page:
* [Include explanations when querying Map index](../../indexes/querying/include-explanations#include-explanations-when-querying-map-index)
* [Include explanations when querying Map-Reduce index](../../indexes/querying/include-explanations#include-explanations-when-querying-map-reduce-index)
* [Syntax](../../indexes/querying/include-explanations#syntax)

{NOTE/}

---

{PANEL: Include explanations when querying Map index}

{CODE-TABS}
{CODE-TAB:nodejs:Map_index index_1@indexes\querying\includingExplanations.js /}
{CODE-TAB:nodejs:Query inc_1@indexes\querying\includingExplanations.js /}
{CODE-TAB-BLOCK:sql:RQL}
from index "Products/BySearchName"
where search(name, "Syrup Lager")
include explanations()
// Or:
from index "Products/BySearchName"
where search(name, "Syrup") or search(name, "Lager")
include explanations()
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Include explanations when querying Map-Reduce index}

{CODE-TABS}
{CODE-TAB:nodejs:Map_Reduce_index index_2@indexes\querying\includingExplanations.js /}
{CODE-TAB:nodejs:Query inc_2@indexes\querying\includingExplanations.js /}
{CODE-TAB-BLOCK:sql:RQL}
from index "NumberOfUnitsOrdered/PerCategory"
where numberOfUnitsOrdered > 400
include explanations($p0)
{"p0" : { "GroupKey": "category" }}
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Syntax}

{CODE:nodejs syntax_1@indexes\querying\includingExplanations.js /}

| Parameter | Type | Description |
|--------------------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **explanationsCallback** | `(explanationsResults) => void` | <ul><li>A callback function with an output parameter.</li><li>The parameter passed to the callback will be filled with the `Explanations` object when query returns.</li></ul> |
| **options** | `object` | An object that specifies the group key when querying a Map-Reduce index. |

{CODE:nodejs syntax_2@indexes\querying\includingExplanations.js /}
{CODE:nodejs syntax_3@indexes\querying\includingExplanations.js /}

{PANEL/}

## Related Articles

#### Client API

- [Query Overview](../../client-api/session/querying/how-to-query)

### Indexes

- [Indexing Basics](../../indexes/indexing-basics)

### Querying

- [Query an Index](../../indexes/querying/query-index)
- [Filtering](../../indexes/querying/filtering)
Loading

0 comments on commit 093a9c9

Please sign in to comment.