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

Update 08-mix-and-match.mdx #46

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
16 changes: 7 additions & 9 deletions docs/5-search-operators/08-mix-and-match.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 📘 Mixing and matching
# 📘 Mixing and Matching

The whole value of using these operators comes from combining them to create search results that are more relevant to your users.

Expand All @@ -16,8 +16,7 @@ Using the `compound` operator, you can mix and match some of the operators you'v
}
```

`must`
Clauses that must match to for a document to be included in the results. The returned score is the sum of the scores of all the subqueries in the clause.
`must`: Clauses that must match for a document to be included in the results. The returned score is the sum of the scores of all the subqueries in the clause.

Maps to the AND boolean operator.

Expand All @@ -26,10 +25,9 @@ Clauses that must not match for a document to be included in the results. mustNo

Maps to the AND NOT boolean operator.

`should`
Clauses that you prefer to match in documents that are included in the results. Documents that contain a match for a should clause have higher scores than documents that don't contain a should clause. The returned score is the sum of the scores of all the subqueries in the clause.
`should`: Clauses that you prefer to match in documents that are included in the results. Documents that contain a match for a should clause have higher scores than documents that don't contain a should clause. The returned score is the sum of the scores of all the subqueries in the clause.

Say you wanted to search for a book that contains "cats" in the title, but you prefer having shorter books, you can use the following query:
Say you wanted to search for a book that contains "cats" in the title, but you prefer having shorter books. You can use the following query:

```js
{
Expand Down Expand Up @@ -58,11 +56,11 @@ Say you wanted to search for a book that contains "cats" in the title, but you p
}
```

This will return all books that contain "cats" in the title, but will prefer shorter books. It will still return longer books, but they will be scored lower than shorter books.
This will return all books that contain "cats" in the title but will prefer shorter books. It will still return longer books, but they will be scored lower than shorter books.

## Compound with scoring

You can also use the `compound` operator with the `score` option to control how the scores of the subqueries are combined. Say the library has a monthly theme, and they want to promote the books that have a specific word in the synopsis. This month, the theme is "bears". Try to write a search query that will return the books a user queried for, but those who contain the word "bear" in it will have a higher score and come at the top. Try to have a book about Winnie the Pooh come first when a user searches for "honey".
You can also use the `compound` operator with the `score` option to control how the scores of the subqueries are combined. Say the library has a monthly theme, and they want to promote the books that have a specific word in the synopsis. This month, the theme is bears. Try to write a search query that will return the books a user queried for, but those that contain the word "bear" will have a higher score and come at the top. Try to have a book about Winnie the Pooh come first when a user searches for "honey."

<details>
<summary>Click here to see the answer</summary>
Expand Down Expand Up @@ -96,4 +94,4 @@ You can also use the `compound` operator with the `score` option to control how
```

</div>
</details>
</details>