Interfaces
Orleans.Search provides several interfaces for search functionality.
IClusterClient Extensions
Orleans.Search adds the Search<TGrain>() extension method to Orleans’s IClusterClient, allowing you to query grains by their state properties using the standard cluster client.
Namespace
TGHarker.Orleans.SearchExtension Method
public static class ClusterClientExtensions
{
public static IOrleansQueryable<TGrain> Search<TGrain>(this IClusterClient client)
where TGrain : IGrain;
}Methods
| Method | Returns | Description |
|---|---|---|
Search<TGrain>() | IOrleansQueryable<TGrain> | Start a query for a specific grain type |
Registration
The extension method is available after calling AddOrleansSearch():
builder.Services.AddOrleansSearch()
.UsePostgreSql(connectionString);Usage
public class MyService
{
private readonly IClusterClient _client;
public MyService(IClusterClient client)
{
_client = client;
}
public async Task<IUserGrain?> FindUserAsync(string email)
{
return await _client.Search<IUserGrain>()
.Where(u => u.Email == email)
.FirstOrDefaultAsync();
}
}Standard IClusterClient
Since Search is an extension method on IClusterClient, you use the same client for both standard grain operations and search:
// Get grain by ID (standard Orleans)
var user = _client.GetGrain<IUserGrain>("user-123");
// Search grains by state (Orleans.Search)
var users = await _client.Search<IUserGrain>()
.Where(u => u.IsActive == true)
.ToListAsync();ISearchProvider
Interface for search index operations. Implemented by generated providers.
Namespace
TGHarker.Orleans.SearchSignature
public interface ISearchProvider<TGrain, TState>
where TGrain : IGrain
{
Task UpsertAsync(string grainId, TState state, int version);
Task DeleteAsync(string grainId);
Task<List<string>> QueryAsync();
Task<List<string>> QueryWithFilterAsync(Expression<Func<TState, bool>> predicate);
Task<int> CountAsync(Expression<Func<TState, bool>>? predicate = null);
Task<bool> AnyAsync(Expression<Func<TState, bool>>? predicate = null);
}Methods
| Method | Description |
|---|---|
UpsertAsync | Insert or update a grain’s state in the search index |
DeleteAsync | Remove a grain from the search index |
QueryAsync | Get all grain IDs |
QueryWithFilterAsync | Get grain IDs matching a predicate |
CountAsync | Count grains matching a predicate |
AnyAsync | Check if any grains match a predicate |
Generated Implementation
The source generator creates an implementation for each [Searchable] state class:
// Generated for UserState
public class UserStateSearchProvider : SearchProviderBase<IUserGrain, UserState, UserStateEntity>,
ISearchProvider<IUserGrain, UserState>
{
// Implementation generated at compile time
}ISearchEntity
Base interface for generated entity classes.
Namespace
TGHarker.Orleans.SearchSignature
public interface ISearchEntity
{
string GrainId { get; set; }
int Version { get; set; }
DateTime LastUpdated { get; set; }
}Properties
| Property | Type | Description |
|---|---|---|
GrainId | string | The Orleans grain ID |
Version | int | Version number for optimistic concurrency |
LastUpdated | DateTime | Timestamp of last update |
Generated Implementation
// Generated for UserState
public class UserStateEntity : ISearchEntity
{
public string GrainId { get; set; }
public int Version { get; set; }
public DateTime LastUpdated { get; set; }
// Queryable properties from UserState
public string Email { get; set; }
public string DisplayName { get; set; }
public bool IsActive { get; set; }
}ISearchModel
Marker interface linking search models to grain types.
Namespace
TGHarker.Orleans.SearchSignature
public interface ISearchModel<TGrain> where TGrain : IGrain
{
}Generated Implementation
// Generated for UserState
public class UserStateSearchModel : ISearchModel<IUserGrain>
{
public string Email { get; set; }
public string DisplayName { get; set; }
public bool IsActive { get; set; }
}IOrleansQueryable
Queryable interface for Orleans grain queries.
Namespace
TGHarker.Orleans.SearchSignature
public interface IOrleansQueryable<TGrain> where TGrain : IGrain
{
// Query methods added via extension methods
}Extension Methods
See Extension Methods for available methods.