Skip to content

DOCSP-35959: search text #2889

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

Merged
merged 9 commits into from
Apr 22, 2024
Merged

Conversation

rustagir
Copy link
Contributor

@rustagir rustagir commented Apr 19, 2024

JIRA

STAGING

docs PR

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@rustagir rustagir requested a review from a team as a code owner April 19, 2024 17:32
Copy link
Contributor

@ccho-mongodb ccho-mongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A couple suggestions and one issue, but I think it can be resolved without another review. Feel free to reach out if you want me to take another look!

Search Text Fields
------------------

You can perform a text search by using the :manual:`$text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

I think it could be better to swap this paragraph (describes how to perform one) with the one following it (describes what a text search is). The first paragraph also seems more connected to the third paragraph ("After building your query...").

Comment on lines 206 to 208
This example calls the ``where()`` method on the ``Movie`` Eloquent model to
retrieve documents in which the ``plot`` field contains the phrase
``"love story"``:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue:

I think the creation of the index needs to be mentioned or shown to understand that "plot" is the indexed field.

Suggestion:
I think either mentioning that the text index was created on the "plot" field or showing an example of creating the index similar to this Java documentation would help a reader understand the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this in the note, but I can also add a sentence that explains that the example assumes a text index on the plot field

Comment on lines 275 to 278
.. note::

To specify a phrase as the text search criteria, you must include it
with escaped quotes in the query filter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:
Perhaps a question for the technical reviewer, but is it possible to use single quotes instead of double quotes to represent the value of the $search key (which would hopefully avoid having to escape the quotes and concatenate strings)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use single quote everywhere, unless I want to use variable injection with double quotes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested this improvement and it works! removing the admonition

{
public function show()
{
$movies = Movie::where('$text', ['$search' => "\"" . 'love story' . "\""])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure it's better like this. The doubles quotes will probably come from user input.

Suggested change
$movies = Movie::where('$text', ['$search' => "\"" . 'love story' . "\""])
$movies = Movie::where('$text', ['$search' => '"love story"'])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this improvement! Was struggling to make this work, didnt realize the solution was so simple.

@rustagir rustagir requested a review from GromNaN April 19, 2024 19:07
@GromNaN GromNaN force-pushed the DOCSP-35959-search-text branch from 461bef2 to 802f50e Compare April 22, 2024 15:16
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I updated the test and examples.

@rustagir rustagir merged commit 0f8474e into mongodb:4.1 Apr 22, 2024
This was referenced Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants