meilisearch / meilisearch-symfony

Seamless integration of Meilisearch into your Symfony project.
https://www.meilisearch.com
MIT License
122 stars 28 forks source link

Indexing plain objects without entitymanager #302

Open ToshY opened 11 months ago

ToshY commented 11 months ago

Description I've been briefly looking through the Wiki and I cannot find an example that shows if it's possible to use plain objects/models/DTOs and index them with this bundle. I've found in the code that the SearchService can perform rawSearch, which I assume works for any non-entities as well (?), but I don't see a similar indexing method for this kind of "raw" indexing.

So my question follows: is indexing of plain objects supported?

Basic example

Other I'm new to Meilisearch 🙂

norkunas commented 11 months ago

Currently not, but I've plans to implement this in future

ToshY commented 11 months ago

Hey @norkunas 👋

Thanks for the quick response. I'll be eagerly waiting until then 👌

tacman commented 3 months ago

I, too, would like to see this bundle de-coupled from the EntityManager. I use the meilisearch-php library to index plain objects, as I'm working on a project to index csv files and it bypasses doctrine altogether.

tacman commented 3 months ago

https://symfony.com/blog/migrating-symfony-com-search-engine-to-meilisearch

There is a Meilisearch Symfony bundle, but we don't use it because ... it's mainly focused on indexing Doctrine entities/documents.

Symfony documentation is built with the symfony-tools/docs-builder, which parses RST documents and outputs JSON files with a certain structure (title, body, TOC, pagination, etc.) That's why we used the Meilisearch PHP integration [instead of the bundle]

I think this situation is very common, to want to index data without using Doctrine. While it's a cool feature of the bundle to have a listener and updating the meili index in the background when a doctrine entity has been changed, I don't think is should be the only way to update an index.

In fact, I would use this bundle just for the still-unmerged debug toolbar. Currently I use the Symfony HTTP client to update meili, so I can debug the HTTP requests, but a dedicated toolbar would rock.

norkunas commented 3 months ago

I still pursue it, just need more time

ToshY commented 3 months ago

@tacman You might be interested in checking out schranz-search/schranz-search, which also has a Meilisearch adapter. I've been using that bundle since I've created this issue, and with the addition of some custom code to make the Meilisearch Client able to use "filters", it works really well.

tacman commented 3 months ago

@ToshY Cool, thanks, I'll check it out.

I have a meilisearch service in a bundle that integrates datatables.net with api-platform, it works great but I now need the same functionality in another bundle. So I'm trying to extract my service which has no application-specific logic, just a wrapper around creating indexes including some async stuff. Like getting stats for the index, which obviously can't be done until the index is finished.

    public function waitUntilFinished(Indexes $index, SymfonyStyle $io = null): array
    {
        do {
            $index->fetchInfo();
            $info = $index->fetchInfo();
            $stats = $index->stats();
            $isIndexing = $stats['isIndexing'];
            $indexName = $index->getUid();
            if ($this->logger) {
                $this->logger->info(sprintf("\n%s is %s with %d documents",
                    $indexName, $isIndexing ? 'indexing' : 'ready', $stats['numberOfDocuments']));
            }
            if ($isIndexing) {
                sleep(1);
            }
        } while ($isIndexing);
        return $stats;
    }

Anyway, just brainstorming, I'd love to drop my service and use this bundle or the package you recommended.