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

Missing GROUP_BY support in Multisearch requests #247

Closed
jarto666 opened this issue Sep 25, 2024 · 8 comments
Closed

Missing GROUP_BY support in Multisearch requests #247

jarto666 opened this issue Sep 25, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@jarto666
Copy link
Contributor

Can support for group_by parameter in multisearch requests be implemented?

@runeanielsen runeanielsen self-assigned this Sep 25, 2024
@Spaggel
Copy link

Spaggel commented Sep 25, 2024

I was also trying to get grouped results. You can do something like this:

var query = new GroupedSearchParameters("search term", "query_field", "GROUP_BY_FIELD"); # GROUP_BY_FIELD must be a facet field
var searchResult = await client.SearchGrouped<Product>("collection_name", query);
foreach (var result in searchResult.GroupedHits)
{
    foreach (var resultHit in result.Hits)
    {
        Console.WriteLine(resultHit.Document.Id + ": " + resultHit.Document.Title);   
    }
}

@jarto666
Copy link
Contributor Author

Just for clarification: ideally it should be flexible to support making both - regular and grouped requests in the same scope of multisearch.

Thanks!

@jarto666
Copy link
Contributor Author

@Spaggel I need not only grouped results, but also make a couple of other ones in the scope of a single multisearch request.

See: https://typesense.org/docs/27.0/api/federated-multi-search.html

@Spaggel
Copy link

Spaggel commented Sep 25, 2024

@jarto666
Copy link
Contributor Author

@Spaggel Yes, but current MultiSearchParameters implementation does not support GroupBy

@jarto666
Copy link
Contributor Author

jarto666 commented Sep 25, 2024

@runeanielsen please give your thoughts on implementation.

So, we could add those to MultiSearchParameters or try to inherit those 3 from GroupedSearchParameters (notice group_missing_values which is also missing from current codebase). Though, inheritance would also require revision of GroupedSearchParameters constructors, since groupBy in this case would become optional.

[JsonPropertyName("group_by")]
public string GroupBy { get; set; }

[JsonPropertyName("group_limit")]
public int? GroupLimit { get; set; }

[JsonPropertyName("group_missing_values")]
public bool? GroupMissingValues { get; set; }

And this would allow us to simply extend MultiSearchResult with GroupedHits:

public record MultiSearchResult
{
// ...
[JsonPropertyName("grouped_hits")]
public IReadOnlyList<GroupedHit> GroupedHits { get; init; }
}

Not the cleanest solution architecturally, the main issue with those parameters duplication, but up for you to consider it. Tested and it's working.

Thanks!

jarto666 pushed a commit to jarto666/typesense-dotnet that referenced this issue Sep 25, 2024
@runeanielsen
Copy link
Member

Hi @jarto666,

I'll take a look as soon as possible, I am a bit busy right now.

@runeanielsen
Copy link
Member

@jarto666 I've released a new version (7.19.0). Thank you for you contribution. :)

// Rune

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

No branches or pull requests

3 participants