Skip to content

Commit

Permalink
Merge pull request #1927 from reebhub/PHP_sessionBatch2_query
Browse files Browse the repository at this point in the history
[PHP] Client API session batch 2 (querying) [Replace C# samples]
  • Loading branch information
ppekrol authored Oct 15, 2024
2 parents 2625a31 + 7140794 commit dddcea6
Show file tree
Hide file tree
Showing 62 changed files with 6,496 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

{PANEL: API support}

__Query__:
**Query**:

* The `Query` API supports LINQ, the essential data access solution in .NET.

Expand All @@ -35,7 +35,7 @@ __Query__:

---

__DocumentQuery__:
**DocumentQuery**:

* `DocumentQuery` does Not support LINQ.

Expand All @@ -49,7 +49,7 @@ __DocumentQuery__:

{NOTE: }

__Note__:
**Note**:

`Query` and `DocumentQuery` can be converted to one another.
This enables you to take advantage of all available API methods & extensions.
Expand All @@ -61,7 +61,7 @@ See [Convert between DocumentQuery and Query](../../../../client-api/session/que

{PANEL: Immutability}

* `Query` is __immutable__ while `DocumentQuery` is __mutable__.
* `Query` is **immutable** while `DocumentQuery` is **mutable**.
You might get different results if you try to *reuse* a query.

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{NOTE: }

* The Node.js client provides a __unified API__ for querying documents via the `session.query()` method.
* The Node.js client provides a **unified API** for querying documents via the `session.query()` method.
All available methods for the session's _query_ method are listed [here](../../../../client-api/session/querying/how-to-query#query-api).

* The `query` method is essentially a shorthand for invoking the `documentQuery` method.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Query vs DocumentQuery

---

{NOTE: }

* RavenDB Queries can be executed using `query` or `document_query`, or by passing
[RQL](../../../../client-api/session/querying/what-is-rql) directly to the server
via `raw_query`.
Learn more in [Query Overview](../../../../client-api/session/querying/how-to-query).

* In the PHP client API, `query` methods and their equivalent `documentQuery` methods
provide the same functionality. (This is different from the C# client implementation,
which often provides different functionality for `Query` methods and their `DocumentQuery`
counterparts.)
The PHP documentation therefore often provides `query` usage samples without adding
`documentQuery` examples as well.

* In this page:
* [API support](../../../../client-api/session/querying/document-query/query-vs-document-query#api-support)
* [`query `and `documentQuery` equivalents](../../../../client-api/session/querying/document-query/query-vs-document-query#queryand-documentquery-equivalents)

{NOTE/}

---

{PANEL: API support}

* `query` and `documentQquery` queries are translated to RQL and sent to the server.
* Available _query_ methods are listed [here](../../../../client-api/session/querying/how-to-query#custom-methods).
* Available _documentQuery_ methods and extensions are listed [here](../../../../client-api/session/querying/document-query/what-is-document-query#custom-methods-and-extensions).

{PANEL/}

{PANEL: `query `and `documentQuery` equivalents}

#### 1.

{CODE:php query_1a@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

is equivalent to:

{CODE:php query_1b@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

---

#### 2.

{CODE:php query_2a@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

is equivalent to:

{CODE:php query_2b@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

---

#### 3.

{CODE:php query_3a@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

is equivalent to:

{CODE:php query_3b@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

---

#### 4.

{CODE:php query_4a@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

is equivalent to:

{CODE:php query_4b@ClientApi\Session\Querying\DocumentQuery\QueryVsDocumentQuery.php /}

{PANEL/}

## Related Articles

### Session

- [Query Overview](../../../../client-api/session/querying/how-to-query)
- [What is a Document Query](../../../../client-api/session/querying/document-query/what-is-document-query)
- [How to use Lucene](../../../../client-api/session/querying/document-query/how-to-use-lucene)

### Indexes

- [Querying an Index](../../../../indexes/querying/query-index)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
provide the same functionality. (This is different from the C# client implementation,
which often provides different functionality for `Query` methods and their `DocumentQuery`
counterparts.)
Therefore the Python documentation often provides `query` usage samples without adding
The Python documentation therefore often provides `query` usage samples without adding
`document_query` examples as well.

* In this page:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{NOTE: }

* In contrast to the .NET client,
the Node.js client provides a __unified API__ for querying documents via the `session.query()` method.
the Node.js client provides a **unified API** for querying documents via the `session.query()` method.

* The `query` method is essentially a shorthand for invoking the `documentQuery` method.
See examples of those equivalent calls in [query vs documentQuery](../../../../client-api/session/querying/document-query/query-vs-document-query).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# What is a Document Query?

---

{NOTE: }

* RavenDB queries can be executed via `query`, `documentQuery` or directly using `RQL`.
Learn more in [Query Overview](../../../../client-api/session/querying/how-to-query).

* See [Query -vs- documentQuery](../../../../client-api/session/querying/document-query/query-vs-document-query)
for additional details.

* In this page:
* [documentQuery examples](../../../../client-api/session/querying/document-query/what-is-document-query#documentquery-examples)
* [Custom methods](../../../../client-api/session/querying/document-query/what-is-document-query#custom-methods)
* [Syntax](../../../../client-api/session/querying/document-query/what-is-document-query#syntax)

{NOTE/}

---

{PANEL: documentQuery examples}

#### Query collection - no filtering

{CODE-TABS}
{CODE-TAB:php:documentQuery documentQuery_2@ClientApi\Session\Querying\DocumentQuery\WhatIsDocumentQuery.php /})
{CODE-TAB-BLOCK:sql:RQL}
from "Employees"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

---

#### Query collection - with filtering

{CODE-TABS}
{CODE-TAB:php:documentQuery documentQuery_3@ClientApi\Session\Querying\DocumentQuery\WhatIsDocumentQuery.php /})
{CODE-TAB-BLOCK:sql:RQL}
from "Employees" where FirstName == "Robert"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

---

#### Query an index

* Using a Path string
{CODE:php documentQuery_4@ClientApi\Session\Querying\DocumentQuery\WhatIsDocumentQuery.php /})

* Using an index Class
{CODE:php documentQuery_5@ClientApi\Session\Querying\DocumentQuery\WhatIsDocumentQuery.php /})

{NOTE: }
Please refer to [Querying an index](../../../../indexes/querying/query-index#session.advanced.documentquery) for examples of querying an index using a documentQuery.
{NOTE/}

{PANEL/}

{PANEL: Custom Methods}

{NOTE: }

Several methods share the same functionality as their `query` counterparts.
Refer to the corresponding documentation articles, marked with links starting with "[Query]" in the list below.

{NOTE/}

Available custom methods:

- AddOrder
- [query] [afterQueryExecuted](../../../../client-api/session/querying/how-to-customize-query#afterqueryexecuted)
- [query] [afterStreamExecuted](../../../../client-api/session/querying/how-to-customize-query#afterstreamexecuted)
- [query] [aggregateBy](../../../../client-api/session/querying/how-to-perform-a-faceted-search)
- [query] [aggregateUsing](../../../../client-api/session/querying/how-to-perform-a-faceted-search)
- andAlso
- [query] [beforeQueryExecuted](../../../../client-api/session/querying/how-to-customize-query#beforequeryexecuted)
- [boost](../../../../client-api/session/querying/text-search/boost-search-results)
- closeSubclause
- cmpXchg
- containsAll
- containsAny
- [count](../../../../client-api/session/querying/how-to-count-query-results)
- [countLazily](../../../../client-api/session/querying/how-to-perform-queries-lazily#lazy-count-query)
- distinct
- explainScores
- first
- firstOrDefault
- fuzzy
- getIndexQuery
- getQueryResult
- [groupBy](../../../../client-api/session/querying/how-to-perform-group-by-query)
- [groupByArrayValues](../../../../client-api/session/querying/how-to-perform-group-by-query#by-array-values)
- [groupByArrayContent](../../../../client-api/session/querying/how-to-perform-group-by-query#by-array-content)
- [query] [Highlight](../../../../client-api/session/querying/text-search/highlight-query-results)
- include
- includeExplanations
- intersect
- invokeAfterQueryExecuted
- invokeAfterStreamExecuted
- [query] [lazily](../../../../client-api/session/querying/how-to-perform-queries-lazily)
- [longCount](../../../../client-api/session/querying/how-to-count-query-results)
- moreLikeThis
- negateNext
- [not](../../../../client-api/session/querying/document-query/how-to-use-not-operator)
- [query] [noCaching](../../../../client-api/session/querying/how-to-customize-query#nocaching)
- [query] [noTracking](../../../../client-api/session/querying/how-to-customize-query#notracking)
- ofType
- openSubclause
- [orderBy](../../../../client-api/session/querying/sort-query-results)
- [orderByDescending](../../../../client-api/session/querying/sort-query-results)
- [query] [orderByDistance](../../../../client-api/session/querying/how-to-make-a-spatial-query#orderByDistance)
- [query] [orderByDistanceDescending](../../../../client-api/session/querying/how-to-make-a-spatial-query#orderByDistanceDesc)
- [orderByScore](../../../../client-api/session/querying/sort-query-results#order-by-score)
- [orderByScoreDescending](../../../../client-api/session/querying/sort-query-results#order-by-score)
- orElse
- [query] [projection](../../../../client-api/session/querying/how-to-customize-query#projection)
- proximity
- [query] [randomOrdering](../../../../client-api/session/querying/how-to-customize-query#randomordering)
- [query] [relatesToShape](../../../../client-api/session/querying/how-to-make-a-spatial-query#search-by-shape)
- [search](../../../../client-api/session/querying/text-search/full-text-search)
- selectFields
- selectTimeSeries
- single
- singleOrDefault
- skip
- [query] [spatial](../../../../client-api/session/querying/how-to-make-a-spatial-query)
- statistics
- [suggestUsing](../../../../client-api/session/querying/how-to-work-with-suggestions)
- take
- [query] [timings](../../../../client-api/session/querying/how-to-customize-query#timings)
- usingDefaultOperator
- [query] [waitForNonStaleResults](../../../../client-api/session/querying/how-to-customize-query#waitfornonstaleresults)
- where
- whereBetween
- [whereEndsWith](../../../../client-api/session/querying/text-search/ends-with-query)
- whereEquals
- [whereExists](../../../../client-api/session/querying/how-to-filter-by-field)
- whereGreaterThan
- whereGreaterThanOrEqual
- whereIn
- whereLessThan
- whereLessThanOrEqual
- [whereLucene](../../../../client-api/session/querying/document-query/how-to-use-lucene)
- whereNotEquals
- [whereRegex](../../../../client-api/session/querying/text-search/using-regex)
- [whereStartsWith](../../../../client-api/session/querying/text-search/starts-with-query)
- withinRadiusOf

{PANEL/}

{PANEL: Syntax}

The definition for `documentQuery` is listed in the [Syntax section](../../../../client-api/session/querying/how-to-query#syntax)
of the [Query Overview](../../../../client-api/session/querying/how-to-query).

{PANEL/}

## Related Articles

### Session

- [Query overview](../../../../client-api/session/querying/how-to-query)
- [How to Use Lucene](../../../../client-api/session/querying/document-query/how-to-use-lucene)

### Querying

- [Query vs documentQuery](../../../../client-api/session/querying/document-query/query-vs-document-query)
- [Projections](../../../../indexes/querying/projections)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{NOTE: }

* The following options are available to __count query results__:
* The following options are available to **count query results**:

* [Count](../../../client-api/session/querying/how-to-count-query-results#count)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{NOTE: }

* The following options are available to __count query results__:
* The following options are available to **count query results**:

* [Count](../../../client-api/session/querying/how-to-count-query-results#count)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Count Query Results

---

{NOTE: }

* The following options are available to **count query results**:

* [`Count`](../../../client-api/session/querying/how-to-count-query-results#count)
* [Get number of results from query stats](../../../client-api/session/querying/how-to-count-query-results#get-count-from-query-stats)

{NOTE/}

---

{PANEL: `Count`}

Count query results using the `Count` method.

{CODE-TABS}
{CODE-TAB:php:documentQuery count_3@ClientApi\Session\Querying\CountQueryResults.php /}
{CODE-TAB-BLOCK:sql:RQL}
from "Orders"
where ShipTo.Country == "UK" limit 0, 0

// The RQL generated will trigger query execution
// however, no documents are returned (limit is set 0)
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Get count from query stats}

When executing a query, you can retrieve the query statistics that include the total number of results.
Learn more in [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics).

{PANEL/}

## Related Articles

### Client API

- [Query overview](../../../client-api/session/querying/how-to-query)
- [What is a Document Query](../../../client-api/session/querying/document-query/what-is-document-query)
- [Filter by Field Presence](../../../client-api/session/querying/how-to-filter-by-field)
- [Get Query Statistics](../../../client-api/session/querying/how-to-get-query-statistics)

### Querying

- [Filtering](../../../indexes/querying/filtering)
- [RQL - Raven Query Language](../../../client-api/session/querying/what-is-rql)
Loading

0 comments on commit dddcea6

Please sign in to comment.