MultiSearch increase
Closed this issue · 10 comments
Default multi-search limit is 50, would be nice to have this implemented.
https://typesense.org/docs/0.24.1/api/federated-multi-search.html#multi-search-parameters
Hi @jveto,
I can implement it, but I'll have to make the return type a collection of object
type, so you will have to type-cast each returned document collection yourself.
// Rune
@jveto, is it something you're still interested in, even if the response are untyped?
Hi @jveto,
What do you think of this API?
private static async Task ExampleMultiSearchNonTypedResponse(ITypesenseClient typesenseClient)
{
var searchResults = await typesenseClient.MultiSearch(
new()
{
// You would never do the same query so many times, it would be different queries
// and the type might also be different, this is just done for easy showcase of how the api works.
(new MultiSearchParameters("companies", "Sul", "accessAddress"), typeof(Address)),
(new MultiSearchParameters("companies", "24", "accessAddress"), typeof(Address)),
});
// We can do a for loop here and cast each search result document into `Address` because all responses are the same.
// In case that they are not the same, we would have to cast each search result seperately.
foreach (var searchResult in searchResults)
{
if (searchResult.Error is null)
{
var searchResultDocuments = searchResult.Hits.Select(x => (Address)x.Document);
Console.WriteLine($"Multi-search non-typed response documents: {JsonSerializer.Serialize(searchResultDocuments)}");
}
else
{
// Handle error
}
}
}
Also one question, what is the usecase for doing 50 searches at the same time, are you bulk sending search queries or
The reason I am asking, is because I'm thinking of creating an overloaded method that takes in a generic type T
, but takes a list of MultiSearchParameters
instead of a single one. The reason for this would be if you mainly only search in the same collection, then it could be handled in a more clean way using that implementation.
Having a generic type overload would be nice, especially since I would be doing bulk searches on one collection to sample responses
Ok, makes sense, I'll do that instead. 👍
HI @jveto,
I've now implemented it. The API looks like this, what do you think? #147
var responses = await _client.MultiSearch<Company>(
new List<MultiSearchParameters>
{
new MultiSearchParameters("companies", "Stark", "company_name"),
new MultiSearchParameters("companies", "Mjolner", "company_name"),
new MultiSearchParameters("companies", "Dax", "company_name"),
new MultiSearchParameters("companies", "Saxo", "company_name"),
new MultiSearchParameters("companies", "Borsen", "company_name"),
new MultiSearchParameters("companies", "Komplett", "company_name")
});
It can also be called with limitMultiSearches
if you desire to increase or decrease the max amount of searches.
var responses = await _client.MultiSearch<Company>(
new List<MultiSearchParameters>
{
new MultiSearchParameters("companies", "Stark", "company_name"),
new MultiSearchParameters("companies", "Mjolner", "company_name"),
new MultiSearchParameters("companies", "Dax", "company_name"),
new MultiSearchParameters("companies", "Saxo", "company_name"),
new MultiSearchParameters("companies", "Borsen", "company_name"),
new MultiSearchParameters("companies", "Komplett", "company_name")
},
100);
Hi @jveto , thanks for the contributions, I've released a new version 6.4.0 that contains the changes. :)