Facet.Search.Generators 0.1.5

dotnet add package Facet.Search.Generators --version 0.1.5
                    
NuGet\Install-Package Facet.Search.Generators -Version 0.1.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Facet.Search.Generators" Version="0.1.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Facet.Search.Generators" Version="0.1.5" />
                    
Directory.Packages.props
<PackageReference Include="Facet.Search.Generators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Facet.Search.Generators --version 0.1.5
                    
#r "nuget: Facet.Search.Generators, 0.1.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Facet.Search.Generators@0.1.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Facet.Search.Generators&version=0.1.5
                    
Install as a Cake Addin
#tool nuget:?package=Facet.Search.Generators&version=0.1.5
                    
Install as a Cake Tool

Facet.Search.Generators

NuGet License

Source generators for Facet.Search � Automatically generates faceted search infrastructure from your domain models at compile time.

Note: This package is included automatically when you install Facet.Search. You only need to install this package directly if you want to use the generators without the main package.

What Gets Generated

When you decorate your models with [FacetedSearch] and [SearchFacet] attributes, this generator creates:

Generated Class Description
{Model}SearchFilter Strongly-typed filter class with properties for each facet
{Model}SearchExtensions LINQ extension methods (ApplyFacetedSearch, GetFacetAggregations)
{Model}FacetAggregations Aggregation results class for facet counts and ranges
{Model}SearchMetadata Static metadata for building dynamic UIs

Generated Code Example

For this model:

[FacetedSearch]
public class Product
{
    [FullTextSearch]
    public string Name { get; set; }

    [SearchFacet(Type = FacetType.Categorical)]
    public string Brand { get; set; }

    [SearchFacet(Type = FacetType.Range)]
    public decimal Price { get; set; }

    [SearchFacet(Type = FacetType.Boolean)]
    public bool InStock { get; set; }
}

The generator creates:

ProductSearchFilter.g.cs

public class ProductSearchFilter
{
    public string? SearchText { get; set; }
    public string[]? Brand { get; set; }
    public decimal? MinPrice { get; set; }
    public decimal? MaxPrice { get; set; }
    public bool? InStock { get; set; }
}

ProductSearchExtensions.g.cs

public static class ProductSearchExtensions
{
    public static IQueryable<Product> ApplyFacetedSearch(
        this IQueryable<Product> query,
        ProductSearchFilter filter)
    {
        // All filter logic translates to SQL
        if (filter.Brand?.Any() == true)
            query = query.Where(x => filter.Brand.Contains(x.Brand));
        
        if (filter.MinPrice.HasValue)
            query = query.Where(x => x.Price >= filter.MinPrice.Value);
        
        // ... etc
        return query;
    }
}

How It Works

  1. The generator scans your compilation for classes marked with [FacetedSearch]
  2. It analyzes properties with [SearchFacet], [FullTextSearch], and [Searchable] attributes
  3. At compile time, it emits .g.cs files with all the search infrastructure
  4. All generated LINQ expressions are translated to SQL by EF Core

SQL Translation

The generated code uses standard LINQ expressions that EF Core translates to SQL:

Filter Type Generated Code SQL Translation
Categorical filter.Brand.Contains(x.Brand) WHERE Brand IN (...)
Range x.Price >= min WHERE Price >= @min
Boolean x.InStock == true WHERE InStock = 1
Full-Text x.Name.Contains(term) WHERE Name LIKE '%term%'

Generated Code Location

Generated files appear in your project's obj folder:

obj/Debug/net8.0/generated/Facet.Search.Generators/
??? ProductSearchFilter.g.cs
??? ProductSearchExtensions.g.cs
??? ProductFacetAggregations.g.cs
??? ProductSearchMetadata.g.cs

Viewing Generated Code

In Visual Studio:

  1. Expand your project in Solution Explorer
  2. Expand Dependencies ? Analyzers ? Facet.Search.Generators
  3. View the generated .g.cs files

Or check the obj folder directly.

Requirements

  • .NET Standard 2.0+
  • C# 9.0+

Installation

Typically, you should install the main package which bundles this generator:

dotnet add package Facet.Search

For standalone generator installation:

dotnet add package Facet.Search.Generators

Troubleshooting

Generator not running?

dotnet clean
dotnet build --no-incremental

Can't see generated code?

Check obj/Debug/net8.0/generated/Facet.Search.Generators/

IntelliSense not working?

Restart Visual Studio or run dotnet build

License

MIT License � see LICENSE for details.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.5 168 12/24/2025
0.1.1 260 12/15/2025
0.1.0 234 12/15/2025
0.0.4 415 12/11/2025
0.0.3 405 12/11/2025
0.0.1 407 12/11/2025