Skip to content

Commit a5f8a64

Browse files
committed
JM and CC PR fixes 1
1 parent fee1259 commit a5f8a64

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

docs/fundamentals/read-operations.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ Use the following syntax to run a find operation that matches all documents:
181181
Search Text Fields
182182
------------------
183183

184-
You can perform a text search by using the :manual:`$text
185-
</reference/operator/query/text>` operator followed
186-
by the ``$search`` field in your query filter that you pass to the
187-
``where()`` method. The ``$text`` operator performs a text search on the
188-
text-indexed fields. The ``$search`` field specifies the text to search for.
189-
190184
A text search retrieves documents that contain a **term** or a **phrase** in the
191185
text-indexed fields. A term is a sequence of characters that excludes
192186
whitespace characters. A phrase is a sequence of terms with any number
@@ -200,12 +194,19 @@ of whitespace characters.
200194
indexes, see the :ref:`laravel-eloquent-indexes` section of the
201195
Schema Builder guide.
202196

197+
You can perform a text search by using the :manual:`$text
198+
</reference/operator/query/text>` operator followed
199+
by the ``$search`` field in your query filter that you pass to the
200+
``where()`` method. The ``$text`` operator performs a text search on the
201+
text-indexed fields. The ``$search`` field specifies the text to search for.
202+
203203
After building your query with the ``where()`` method, chain the ``get()``
204204
method to retrieve the query results.
205205

206206
This example calls the ``where()`` method on the ``Movie`` Eloquent model to
207207
retrieve documents in which the ``plot`` field contains the phrase
208-
``"love story"``:
208+
``"love story"``. To perform this text search, the collection must have
209+
a text index on the ``plot`` field.
209210

210211
.. tabs::
211212

@@ -271,16 +272,12 @@ retrieve documents in which the ``plot`` field contains the phrase
271272
Plot: A girl. A boy. A love story ...
272273

273274
...
274-
275-
.. note::
276-
277-
To specify a phrase as the text search criteria, you must include it
278-
with escaped quotes in the query filter.
279275

280-
A text search assigns a numerical text score to indicate how closely
276+
A text search assigns a numerical :manual:`text score </reference/operator/query/text/#text-score>` to indicate how closely
281277
each result matches the string in your query filter. You can sort the
282278
results by relevance by using the ``orderBy()`` method to sort on the
283-
``textScore`` metadata:
279+
``textScore`` metadata field. You can access this metadata by using the
280+
:manual:`$meta </reference/operator/aggregation/meta/>` operator:
284281

285282
.. literalinclude:: /includes/fundamentals/read-operations/ReadOperationsTest.php
286283
:language: php

docs/includes/fundamentals/read-operations/ReadOperationsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testFirst(): void
105105
public function testText(): void
106106
{
107107
// start-text
108-
$movies = Movie::where('$text', ['$search' => "\"" . 'love story' . "\""])
108+
$movies = Movie::where('$text', ['$search' => '"love story"'])
109109
->get();
110110
// end-text
111111

@@ -125,7 +125,7 @@ public function testTextRelevance(): void
125125
$collection->createIndex($index);
126126

127127
// start-text-relevance
128-
$movies = Movie::where('$text', ['$search' => "\"" . 'love story' . "\""])
128+
$movies = Movie::where('$text', ['$search' => '"love story"'])
129129
->orderBy('score', ['$meta' => 'textScore'])
130130
->get();
131131
// end-text-relevance

0 commit comments

Comments
 (0)