Skip to content
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

Refacto and fix search method #57

Closed
wants to merge 3 commits into from
Closed

Refacto and fix search method #57

wants to merge 3 commits into from

Conversation

curquiza
Copy link
Member

No description provided.

@curquiza curquiza marked this pull request as draft February 25, 2021 16:27
@curquiza curquiza marked this pull request as ready for review February 25, 2021 16:43
@curquiza curquiza linked an issue Feb 25, 2021 that may be closed by this pull request
@curquiza
Copy link
Member Author

Hello @althaus
Here is the PR, tell if it seems ok for you :)

@curquiza curquiza changed the title Refacto search method Refacto and fix search method Feb 25, 2021
Copy link
Contributor

@althaus althaus left a comment

Choose a reason for hiding this comment

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

Found some issues.

@@ -209,24 +208,18 @@ public function search(
ObjectManager $objectManager,
string $className,
string $query = '',
array $requestOptions = []
array $searchParams = []
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is not reflected in the SearchService interface.

Copy link
Member Author

@curquiza curquiza Mar 20, 2021

Choose a reason for hiding this comment

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

We should indeed do this change everywhere instead of just here in this PR.
Related to #58

*
* @return array<string, int|string|array>
*/
public function searchIds(string $query, string $indexName, array $searchParams)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public function searchIds(string $query, string $indexName, array $searchParams)
public function searchIds(string $query, string $indexName, array $searchParams): array

public function searchIds(string $query, string $indexName, array $searchParams)
{
$primaryKey = $this->client->index($indexName)->fetchPrimaryKey();
$result = $this->search($query, $indexName, $searchParams);
Copy link
Contributor

Choose a reason for hiding this comment

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

As I'm a fresh MS user: Would it improve performance or something to limit the search to only fetch the $primaryKey attribute?

https://docs.meilisearch.com/reference/features/search_parameters.html#attributes-to-retrieve

Something like this:

if (!isset($searchParams['attributesToRetrieve'])) {
    $searchParams['attributesToRetrieve'] = [$primaryKey];
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This is indeed not optimized! Unfortunately, the primary key is not accessible in the search response so we cannot use your suggestion, except if I missed something. I need to find another way.

Copy link
Member Author

@curquiza curquiza Mar 20, 2021

Choose a reason for hiding this comment

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

I've realized it's more complicated than I thought. The search() method was badly adapted for MeiliSearch (first coming from Algolia search bundle).
We indeed don't use objectID with MeiliSearch but your primary key (so the unique field of your documents) is inferred because containing id, so often, the primary key is the simple id field.

But, according to the way of handling the unique field, it means we are not able to know the primary key (= the unique field) during the search. And we clearly need to know it according to our code base!

Two possibilities:

  • we are doing 2 HTTP calls during the search() as I've already done in my PR: this is a quick fix and your PR (Added raw search (fixes #17) #60) is a temporary workaround for users having performance issues. I don't really like this solution if the second point can be applied.
  • removing objectID from our code base, I mean, in terms of usage. Related to Renaming some variables #58. It looks like being a big task to do and I don't have the time to do it, unfortunately, but this would be a good step in this package. I'm opening an issue.

* @param string $indexName
* @param array<string, int|string|array> $searchParams
*
* @return array<string, int|string|array>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this method return an array<string, array> ? This would mean the ID itself would be an array.

@curquiza
Copy link
Member Author

curquiza commented Mar 2, 2021

Hello Matthias! I saw all your involvement in the meilisearch-symfony repository (issues, PR review and PR). I don't have the time to work on it at the moment, but I don't forget all of those and I will come back as soon as possible 🙂

@curquiza curquiza closed this Jun 9, 2021
@curquiza
Copy link
Member Author

curquiza commented Jun 9, 2021

Closing this due to obsolete code (a refactor was done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Service returns bad entities for correct search
2 participants