Skip to content

Effects Composition

The SearchModule is an [EffectsModule(typeof(ISearchIndex<>))] that generates Eff<RT, T> effect methods for full-text search operations.

Capability Interface

public interface IHasSearchIndex<T>
{
    ISearchIndex<T> SearchIndex { get; }
}

Effect Methods

public static partial class SearchModule
{
    public static partial class Search<T>
    {
        public static Eff<RT, SearchResult<T>> SearchAsync<RT>(
            string query, SearchOptions? options = null)
            where RT : IHasSearchIndex<T> => ...

        public static Eff<RT, Unit> IndexAsync<RT>(string id, T document)
            where RT : IHasSearchIndex<T> => ...

        public static Eff<RT, Unit> IndexManyAsync<RT>(
            IReadOnlyDictionary<string, T> documents)
            where RT : IHasSearchIndex<T> => ...

        public static Eff<RT, Unit> RemoveAsync<RT>(string id)
            where RT : IHasSearchIndex<T> => ...

        public static Eff<RT, Unit> ClearAsync<RT>()
            where RT : IHasSearchIndex<T> => ...
    }
}

Effect Pipeline Examples

Index a document after creation

var createAndIndex =
    from product in AppStore.Products.Save<AppRuntime>(newProduct)
    from _ in SearchModule.Search<Product>.IndexAsync<AppRuntime>(
        product.Id.ToString(), product)
    select product;

Search with options

var searchProducts =
    from results in SearchModule.Search<Product>.SearchAsync<AppRuntime>(
        "wireless headphones",
        new SearchOptions { Limit = 20, Offset = 0 })
    select results;

Bulk index

var reindexAll =
    from products in AppStore.Products.GetAll<AppRuntime>()
    from _ in SearchModule.Search<Product>.IndexManyAsync<AppRuntime>(
        products.ToDictionary(p => p.Id.ToString(), p => p))
    select unit;