Comments (4)
I let this issue opened since there is still some objectID
in the code, but you did most of the job, thank you very much 😁
from meilisearch-symfony.
Yes, for the objectId
I would create a new branch & PR to work on.
from meilisearch-symfony.
Why are we removing the objectID
usage? When objects get placed into Meilisearch the objectID
param is set to the primary keys of the entity (or just the single value if there aren't multiple primary keys). When we pull objects down out of MeiliSearch we can just parse the objectID
field to figure out how to query for the entity.
I sort of like how it works now because it keeps the config to a minimum (don't have to define the primary key in config) and also doesn't require running two http requests for every search (to figure out the primary key). It would be cool to override the objectID
field with your own way if you really want but how it is currently setup is easiest for users to get started with IMO.
I just updated the MeiliSearchService::search
function to the following and it works really well (handles multiple primary keys and entities that don't use id
as their primary key):
public function search(
ObjectManager $objectManager,
string $className,
string $query = '',
array $requestOptions = []
): array {
$this->assertIsSearchable($className);
$ids = $this->engine->search($query, $this->searchableAs($className), $requestOptions);
$results = [];
// Check if the engine returns results in "hits" key
if (!isset($ids['hits'])) {
throw new SearchHitsNotFoundException('There is no "hits" key in the search results.');
}
foreach ($ids['hits'] as $objectID) {
if (in_array($className, $this->aggregators, true)) {
$entityClass = $className::getEntityClassFromObjectID($objectID);
$id = $className::getEntityIdFromObjectID($objectID);
} else {
$multipleIds = explode('__', $objectID['objectID']);
$entityClass = $className;
if (0 === count($ids)) {
throw new Exception('Entity has no primary key');
} else if(count($multipleIds) === 1) {
$id = $multipleIds[0];
$idFieldName = $objectManager->getClassMetadata($entityClass)->getSingleIdentifierFieldName();
$repo = $objectManager->getRepository($entityClass);
$entity = $repo->findOneBy([$idFieldName => $id]);
} else {
$idFieldNames = $objectManager->getClassMetadata($entityClass)->getIdentifierFieldNames();
$searchIdFields = [];
foreach($multipleIds as $idPart) {
list($idFieldName, $idFieldValue) = explode("-", $idPart);
if(!in_array($idFieldName, $idFieldNames)) {
continue;
}
$searchIdFields[$idFieldName] = $idFieldValue;
}
$repo = $objectManager->getRepository($entityClass);
$entity = $repo->findOneBy($searchIdFields);
}
}
$repo = $objectManager->getRepository($entityClass);
$entity = $repo->findOneBy(['id' => $id]);
if (null !== $entity) {
$results[] = $entity;
}
}
return $results;
}
```
from meilisearch-symfony.
So the second tasks is fixed as well (#70). The objectId
stuff is done in #66 - I would also start taking care of that but first let's crush #76 (little reminder @curquiza ) 😉
from meilisearch-symfony.
Related Issues (20)
- setting: "distinctAttribute" type inconsistency HOT 5
- Working with facets HOT 2
- Enable re-indexation with `indexSwap`
- Autowiring should not be used
- Commands should use `meilisearch:` prefix instead of `meili:`
- Parameters should use `meilisearch.` prefix HOT 1
- Authorization fails
- Add CodeCov HOT 2
- Page fixture in tests uses deprecated Doctrine type `Object`
- Broken links in README
- Support Symfony 7 HOT 1
- Indexing plain objects without entitymanager HOT 2
- DateTime objects are serialized as strings HOT 7
- `nbResults` is not set / ignored
- Import of Mongo ODM entities fails HOT 4
- Ability to use filters on index for additional searchparams/options HOT 5
- Use PUT operation to update existing document(s) HOT 12
- Add timeout option on search requests HOT 1
- Test CI is now failing without any merge into the repo HOT 5
- CI is broken without changing anything HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meilisearch-symfony.