-
Notifications
You must be signed in to change notification settings - Fork 26
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
Perform multiple searches in one single HTTP request #379
Comments
@brunoocasali how do other compiler safe languages handle this API? It's proving exceptionally difficult to have a method which expects an array of generics with different document types. The best I've got (code below) is using message packs which syntaxically to the user looks nice but I'm unable to figure out how to zip up the pack of expected document types to an array of data from the API. I think this is because the feature is so new in Swift it lacks things like message pack iteration. Work in Progress
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) func multiSearch( _ searchParameters: [MultiSearchParameters] ) async throws -> (repeat Searchable) { The simple solution would be to return an array of undecoded types. So the usage would look like: let params: [MultiSearchParameters] = [
.init(indexUid: "indexA", parameters: .query("b")),
.init(indexUid: "indexB", parameters: .init(query: "b", limit: 5))
]
let results = try await search.multiSearch(params)
// notice the new `.decode()` function to move from the undecoded type to something they can use.
// this helps the compiler to know what the type is though simplifying the solution.
let firstResult: Searchable<Movie> = results[0].decode()
let secondResult: Searchable<Animal> = results[1].decode() This feels like an okay compromise. The API is still pretty clean and clear what's happening. It does lose the safety though where a user could do |
This will be an issue to be accomplished here indeed. I guess maybe you could take inspiration of those SDKS: Java (proposal), Rust and C# Does it helps? |
Unfortunately not, none of the three solutions above appear to demonstrate a compiler-safe and type-safe solution which allows for queries to different indexes with different document types. The Rust one for example seems to show that all documents across the multiple queries must be of type Movie. This would be an easy limitation for us to implement, but one which dramatically reduces the usefulness. Separating the decode step (my approach above) adds one extra step to the execution but allows for mixed result responses. Think it's what we need to go for, for now, until more language capabilities are added (message packs) |
I guess it is the way to go in this case @Sherlouk 😢. |
just to double check, multiSearch is not available in the Swift SDK? |
Not at this time, we've yet to identify a completely compile/type safe solution which works in Swift. |
Also, if you are a maintainer, feel free to add any clarification and instruction about this issue.
Sorry if this is already partially/completely implemented, feel free to let me know about the state of this issue in the repo.
Related to meilisearch/integration-guides#251
Related to:
Create a new client method called
multiSearch
/multi_search
, which will requestPOST /multi-search
with a body payload containing a structure similar to this:Each object is a simple search object sent in the
POST /indexes/:indexUid/search
request.Pay attention to the response, which will follow the order of the requests object and will look like this (note the new
indexUid
key in the response):TODO:
multiSearch
methodThe text was updated successfully, but these errors were encountered: