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

[PHP] Indexing pages batch [Replace C# samples] #1985

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Indexes: Boosting
---

{NOTE: }

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

* Providing a **boost value** to selected fields allows prioritization of the resulting documents.
The boos value is integrated with the basic score, increasing the document rank.

* The automatic ordering of results by their score is [configurable](../indexes/boosting#automatic-score-based-ordering).

* Boosting can be achieved in the following ways:

* **At query time**:
By applying a boost factor to searched terms at query time (see [Boost search results](../client-api/session/querying/text-search/boost-search-results)).

* **Via index definition**:
By applying a boost factor in the index definition, as described in this article.

* In this page:
* [Assign a boost factor to an index-field](../indexes/boosting#assign-a-boost-factor-to-an-index-field)
* [Assign a boost factor to the index-entry](../indexes/boosting#assign-a-boost-factor-to-the-index-entry)
* [Automatic score-based ordering](../indexes/boosting#automatic-score-based-ordering)

{NOTE/}

---

{PANEL: Assign a boost factor to an index-field}

Applying a boost value to an index-field allows prioritization of matching documents based on an index-field.

---


##### The index:

{CODE-TABS}
{CODE-TAB:php:LINQ_index index_1@Indexes\Boosting.php /}
{CODE-TAB:php:JavaScript_index index_1_js@Indexes\Boosting.php /}
{CODE-TABS/}

##### The query:

{CODE-TABS}
{CODE-TAB:php:Query query_1@Indexes\Boosting.php /}
{CODE-TAB:php:DocumentQuery query_3@Indexes\Boosting.php /}
{CODE-TAB-BLOCK:sql:RQL}
from index "Orders/ByCountries/BoostByField"
where ShipToCountry == "poland" or CompanyCountry == "portugal"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Assign a boost factor to the index-entry}

Applying a boost value to the whole index-entry allows prioritization of matching documents by content from the document.

---

##### The index:

{CODE-TABS}
{CODE-TAB:php:LINQ_index index_2@Indexes\Boosting.php /}
{CODE-TAB:php:JavaScript_index index_2_js@Indexes\Boosting.php /}
{CODE-TABS/}

##### The query:

{CODE-TABS}
{CODE-TAB:php:Query query_4@Indexes\Boosting.php /}
{CODE-TAB:php:DocumentQuery query_6@Indexes\Boosting.php /}
{CODE-TAB-BLOCK:sql:RQL}
from index "Orders/ByCountries/BoostByIndexEntry"
where ShipToCountry == "poland" or CompanyCountry == "portugal"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

{PANEL/}

{PANEL: Automatic score-based ordering}

* By default, whenever boosting is applied, either via dynamic querying or when querying an index
that has a boosting factor in its definition, the results will be automatically ordered by the score.

* This behavior can be modified using the [OrderByScoreAutomaticallyWhenBoostingIsInvolved](../server/configuration/indexing-configuration#indexing.orderbyscoreautomaticallywhenboostingisinvolved)
configuration key.

* Refer to the [Get resulting score](../client-api/session/querying/sort-query-results#get-resulting-score)
section to learn how to retrieve the calculated score of each result.

{PANEL/}

## Related Articles

### Querying

- [Full-text search](../client-api/session/querying/text-search/full-text-search)
- [Boost search results](../client-api/session/querying/text-search/boost-search-results)

### Indexes

- [Analyzers](../indexes/using-analyzers)
- [Storing Data in Index](../indexes/storing-data-in-index)
- [Term Vectors](../indexes/using-term-vectors)
- [Dynamic Fields](../indexes/using-dynamic-fields)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Indexes: Converting to JSON and Accessing Metadata

---
{NOTE: }

Entities passed to an index can be converted to JSON using the `AsJson` method.
It is also possible to access metadata for a specified object using the `MetadataFor` method.

* In this Page:
* [AsJson - Converting to JSON](../indexes/converting-to-json-and-accessing-metadata#asjson---converting-to-json)
* [MetadataFor - Accessing Metadata](../indexes/converting-to-json-and-accessing-metadata#metadatafor---accessing-metadata)

{NOTE/}

---

{PANEL: AsJson - Converting to JSON}

{CODE:php indexes_1@Indexes/Metadata.php /}

{CODE:php indexes_2@Indexes/Metadata.php /}

{PANEL/}

{PANEL: MetadataFor - Accessing Metadata}

{CODE:php indexes_3@Indexes/Metadata.php /}

{CODE:php indexes_4@Indexes/Metadata.php /}

{PANEL/}

## Related articles

### Indexes

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

### Client API

- [How to Get and Modify Entity Metadata](../client-api/session/how-to/get-and-modify-entity-metadata)
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where Authors == "Moon"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

**Query the index using the Studio**:
**Query the index using Studio**:

* Query the index from the Studio's [List of Indexes](../studio/database/indexes/indexes-list-view#indexes-list-view) view:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where authors == "Moon"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

**Query the index using the Studio**:
**Query the index using Studio**:

* Query the index from the Studio's [List of Indexes](../studio/database/indexes/indexes-list-view#indexes-list-view) view:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Indexing Hierarchical Data
---

{NOTE: }

* Use the `Recurse` method to traverse the layers of a hierarchical document and index its fields.

* In this Page:
* [Hierarchical data](../indexes/indexing-hierarchical-data#hierarchical-data)
* [Index hierarchical data](../indexes/indexing-hierarchical-data#index-hierarchical-data)
* [Query the index](../indexes/indexing-hierarchical-data#query-the-index)

{NOTE/}

---

{PANEL: Hierarchical data}

One significant advantage of document databases is their tendency not to impose limits on data structuring.
**Hierarchical data structures** exemplify this quality well; for example, consider the commonly used comment thread, implemented using objects such as:

{CODE:php indexes_1@Indexes\IndexingHierarchicalData.php /}

Readers of a post created using the above `BlogPost` structure can add `BlogPostComment` entries to the post's _comments_ field,
and readers of these comments can reply with comments of their own, creating a recursive hierarchical structure.

For example, the following document, `BlogPosts/1-A`, represents a blog post by John that contains multiple layers of comments from various authors.

`BlogPosts/1-A`:

{CODE-BLOCK:JSON}
{
"Author": "John",
"Title": "Post title..",
"Text": "Post text..",
"Comments": [
{
"Author": "Moon",
"Text": "Comment text..",
"Comments": [
{
"Author": "Bob",
"Text": "Comment text.."
},
{
"Author": "Adel",
"Text": "Comment text..",
"Comments": {
"Author": "Moon",
"Text": "Comment text.."
}
}
]
}
],
"@metadata": {
"@collection": "BlogPosts"
}
}
{CODE-BLOCK/}

{PANEL/}

{PANEL: Index hierarchical data}

To index the elements of a hierarchical structure like the one above, use RavenDB's `Recurse` method.

The sample index below shows how to use `Recurse` to traverse the comments in the post thread and index them by their authors.
We can then [query the index](../indexes/indexing-hierarchical-data#query-the-index) for all blog posts that contain comments by specific authors.

{CODE-TABS}
{CODE-TAB:php:AbstractIndexCreationTask indexes_2@Indexes\IndexingHierarchicalData.php /}
{CODE-TAB:php:Operation indexes_3@Indexes\IndexingHierarchicalData.php /}
{CODE-TABS/}

{PANEL/}

{PANEL: Query the index}

The index can be queried for all blog posts that contain comments made by specific authors.

**Query the index using code**:

{CODE-TABS}
{CODE-TAB:php:Query indexes_4@Indexes\IndexingHierarchicalData.php /}
{CODE-TAB:php:documentQuery indexes_5@Indexes\IndexingHierarchicalData.php /}
{CODE-TAB-BLOCK:sql:RQL}
from index "BlogPosts/ByCommentAuthor"
where Authors == "Moon"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

**Query the index using Studio**:

* Query the index from Studio's [List of Indexes](../studio/database/indexes/indexes-list-view#indexes-list-view) view:

!["List of Indexes view"](images/list-of-indexes-view.png "List of Indexes view")

* View the query results in the [Query](../studio/database/queries/query-view) view:

!["Query View"](images/query-view.png "Query view")

* View the list of terms indexed by the `Recurse` method:

!["Click to View Index Terms"](images/click-to-view-terms.png "Click to view index terms")

!["Index Terms"](images/index-terms.png "Index terms")

{PANEL/}

## Related articles

### Indexes

- [Indexing Basics](../indexes/indexing-basics)
- [Indexing Related Documents](../indexes/indexing-related-documents)
- [Indexing Spatial Data](../indexes/indexing-spatial-data)
- [Indexing Polymorphic Data](../indexes/indexing-polymorphic-data)

### Querying

- [Query Overview](../client-api/session/querying/how-to-query)
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ where Authors == "Moon"
{CODE-TAB-BLOCK/}
{CODE-TABS/}

**Query the index using the Studio**:
**Query the index using Studio**:

* Query the index from the Studio's [List of Indexes](../studio/database/indexes/indexes-list-view#indexes-list-view) view:
* Query the index from Studio's [List of Indexes](../studio/database/indexes/indexes-list-view#indexes-list-view) view:

!["List of Indexes view"](images/list-of-indexes-view.png "List of Indexes view")

Expand Down
Loading
Loading