Skip to content

Commit

Permalink
Merge pull request #46 from Meg528/patch-19
Browse files Browse the repository at this point in the history
Update 08-mix-and-match.mdx
  • Loading branch information
sis0k0 authored Sep 18, 2024
2 parents 6925a62 + eaf52c2 commit 75dd854
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 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

0 comments on commit 75dd854

Please sign in to comment.