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

Add multi search #288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add multi search #288

wants to merge 1 commit into from

Conversation

norkunas
Copy link
Collaborator

@norkunas norkunas commented Aug 18, 2023

Pull Request

Related issue

Fixes #246

What does this PR do?

  • Add's multi search method

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Opening this PR to discuss the implementation, because not sure what are the expectations, so not ready to merge :)

@norkunas norkunas added the enhancement New feature or request label Aug 18, 2023
@norkunas norkunas force-pushed the multi-search branch 2 times, most recently from b57a67c to 350ad3f Compare August 22, 2023 03:45
/**
* @return class-string
*/
private function getClassNameFromIndex(string $index): string
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a common thing in the bundle, no? I'm wondering if this could be reused somewhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but I'd leave that for later :)

@norkunas
Copy link
Collaborator Author

@brunoocasali I'm not sure if we should have a totally separate SearchQuery that is converted to the client one or extend it.. which one you prefer? I chose former one because I thought there is not point to have a setIndexUid method, but then we must duplicate everything.

@brunoocasali
Copy link
Member

Why you don't think the setIndexUid is not useful for the multi-search? From what I saw in the code you're going to send a multi-search for all the configured indices right?

If yes, I'm not sure it is the right approach... Since I could have a lot of defined models but want to search in a subset, in this case I would have a lot of useless data being sent over the network.

@norkunas
Copy link
Collaborator Author

norkunas commented Sep 1, 2023

Why you don't think the setIndexUid is not useful for the multi-search?

That's because in bundle we operate on the class level, so you instantiate a SearchQuery with for example test fixture Post::class which will be later then converted to the real index name test_posts etc.
But sure, if you have the full index name at hand, maybe it could be useful 🤔

I followed the same approach as for the single index search $this->searchService->search($this->entityManager, Post::class, 'term')

@brunoocasali
Copy link
Member

Oh, okay I see it now!

Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

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

Just a comment + fixing the styling, and we're good to go!

Comment on lines +197 to +201
// $response = $this->engine->multiSearch(array_map(function (SearchQuery $query) use ($prefix, $indices) {
// $this->assertIsSearchable($query->getClassName());
//
// return $query->toEngineQuery($prefix, $indices);
// }, $queries));
Copy link
Member

Choose a reason for hiding this comment

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

👀

@norkunas
Copy link
Collaborator Author

norkunas commented Sep 4, 2023

Just a comment + fixing the styling, and we're good to go!

aggregator support needs to be added I think also, but first I need to understand it how to make it work :)

Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

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

👍 LGTM!

@SirMishaa
Copy link

SirMishaa commented Jan 23, 2024

Any up for this ? Really looking for it, would be really useful 👀

What's failing in the C.I ?

Comment on lines +197 to +201
// $response = $this->engine->multiSearch(array_map(function (SearchQuery $query) use ($prefix, $indices) {
// $this->assertIsSearchable($query->getClassName());
//
// return $query->toEngineQuery($prefix, $indices);
// }, $queries));

Choose a reason for hiding this comment

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

Suggested change
// $response = $this->engine->multiSearch(array_map(function (SearchQuery $query) use ($prefix, $indices) {
// $this->assertIsSearchable($query->getClassName());
//
// return $query->toEngineQuery($prefix, $indices);
// }, $queries));

@norkunas
Copy link
Collaborator Author

@brunoocasali do you have any suggestions how to make this work with aggregators?

For example if you define Post index and then an aggregator that is also uses Post then there is an ambiguity where to search.
Do we need to return for both indexes? What if I want to really only search in Post index and avoid searching in aggregated index?

@brunoocasali
Copy link
Member

For example if you define Post index and then an aggregator that is also uses Post then there is an ambiguity where to search.

Can you remind me about what the "aggregators" should do in the first place? Is it the ability to map two models into the same index?

Because in any case, I think we could release without that and figure out that later, WDYT?

@norkunas
Copy link
Collaborator Author

Can you remind me about what the "aggregators" should do in the first place? Is it the ability to map two models into the same index?

I think so..

Because in any case, I think we could release without that and figure out that later, WDYT?

Okay maybe :) also I think it's possible to define same class as multiple indexes,so there would be same problem that it would search also in all of those 🤔

@brunoocasali
Copy link
Member

Okay maybe :) also I think it's possible to define same class as multiple indexes,so there would be same problem that it would search also in all of those 🤔

Do you mean, even without this PR? Because I think this could be a problem indeed, so we would not need to worry about that possibility here, right?

@brunoocasali
Copy link
Member

I think if you feel the code for the feature is good enough you can push forward and then grab some user feedback about the feature, WDYT?

I also encouraged the rails maintainer to do a similar approach, instead of waiting to have the best public API in town 😅.

@norkunas
Copy link
Collaborator Author

Yeah ok,just need to find some time to finish it:)

@czachor
Copy link

czachor commented May 22, 2024

Hi, do you need help here? Maybe I'll be able to do something. Multisearch is an important functionality for me :)

@norkunas
Copy link
Collaborator Author

Hi, if you want to continue the work of this then go ahead.

@mrmadhat
Copy link

mrmadhat commented Jul 9, 2024

What is the work required? Is it to remove the unnecessary comment and add getters to fix the code style issues?

@norkunas
Copy link
Collaborator Author

norkunas commented Jul 9, 2024

To decide properly how it should behave :)

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

Successfully merging this pull request may close these issues.

Perform multiple searches in one single HTTP request
5 participants