Skip to content

Add landing_getting_started_1 code samples #180

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 2 commits into from
Apr 20, 2022
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
43 changes: 43 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
landing_getting_started_1: |-
```yml
# Configure your entities by adding them in config/packages/meili_search.yaml
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this file has two different languages, I must use markdown here, or the landing page will understand it?

CC: @bidoubiwa @mdubus

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey! It will not unfortunately :/ We have the same issue in angular. We settled for this with morgane: https://github.com/meilisearch/meilisearch-angular/blob/main/.code-samples.meilisearch.yaml

We are not sure how ugly it will look, when we now more we can potentially try things out.

meili_search:
url: 'http://127.0.0.1:7700'
api_key: 'masterKey'
indices:
- name: movies
class: App\Entity\Movie
```

```php
<?php
// src/Controller/MoviesController.php
namespace App\Controller;

use App\Entity\Movie;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Response;

class MoviesController extends AbstractController
{
#[Route('/add-movies', name: 'addMovies')]
public function addMovies(ManagerRegistry $doctrine): Response
{
$entityManager = $doctrine->getManager();
Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to just call the persistence and say this will be automatically indexed, but I don't know if this would be clear for symfony users. WDYT @curquiza & @gmourier ?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure to understand, for me you already said it will be automatically updated some line below right?

// Inserting data in your DB table will automatically update your Meilisearch index

Copy link
Member Author

@brunoocasali brunoocasali Apr 19, 2022

Choose a reason for hiding this comment

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

Yeah, but do you think the comment // Inserting data in your DB table will automatically update your Meilisearch index is necessary?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see any problem to have it on a sample code to remind this information. Will the content of this comment be mentioned before or after the sample code?

If not, it seems useful to me because there is a bit of magic with the ORM hooks here, it also helps someone who doesn't necessarily read the surrounding text and copy and paste the sample code directly.

Copy link
Member

Choose a reason for hiding this comment

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

It's ok from my POV to let it. We added it to Rails as well, and I agree with guillaume: it's a little bit magic and not obvious, from my POV


$movies = ['Carol', 'Wonder Woman', 'Life of Pi', 'Mad Max: Fury Road', 'Moana', 'Philadelphia'];

foreach ($movies as $title) {
$movie = new Movie();
$movie->setTitle($title);

$entityManager->persist($movie);
}

// Inserting data in your DB table will automatically update your Meilisearch index
$entityManager->flush();

//...
}
}
```