> For the complete documentation index, see [llms.txt](https://docs.flexbase.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flexbase.in/data-and-providers/data-stores/search-store-full-text/sql-server-full-text-search.md).

# Sql Server Full Text Search

## Description

SQL Server full-text search can be used as the backing implementation for Flex search operations. Your application code should depend on `IFlexSearchStore`, while Flex provides the provider bridge and wiring.

## Important concepts

* **`IFlexSearchStore` is the contract**: app code performs searches and indexing through the shared interface.
* **Table + column configuration**: SQL Server full-text search requires a target table, an ID column, and searchable columns.
* **Provider bridge**: the SQL Server implementation is exposed via an `IFlexSearchStoreBridge` internally, but most consumers only need `IFlexSearchStore`.

## Configuration in DI

Add the provider in your DI composition root (commonly in `EndPoints/...CommonConfigs/OtherApplicationServicesConfig.cs` or wherever you centralize registrations).

```csharp
// using Sumeru.Flex; // IFlexSearchStore

public static class OtherApplicationServicesConfig
{
	public static IServiceCollection AddOtherApplicationServices(
		this IServiceCollection services,
		IConfiguration configuration)
	{
		// Registers SQL Server full-text search as the IFlexSearchStore bridge.
		// Flex auto-wires generated Queries/Plugins that *use* IFlexSearchStore.
		services.AddFlexSqlServerSearchStore(configuration);

		return services;
	}
}
```

## appsettings.json

Configuration is read from `FlexBase:DataStores:Search:SqlServer`.

```json
{
  "FlexBase": {
	"DataStores": {
	  "Search": {
		"SqlServer": {
		  "ConnectionString": "Server=...;Database=...;User Id=...;Password=...;TrustServerCertificate=True;",
		  "TableName": "dbo.Articles",
		  "IdColumn": "Id",
		  "SearchableColumns": [ "Title", "Body" ],
		  "FullTextCatalog": "FlexSearchCatalog",
		  "Language": "English"
		}
	  }
	}
  }
}
```

## Examples (template-based)

These examples mirror the generated Query and PostBus plugin templates. You do **not** register these types manually—Flex discovers and wires generated Queries/Handlers/Plugins automatically.

### Search a single document (Query)

```csharp
using Microsoft.Extensions.Logging;
using Sumeru.Flex;
using System.Linq;
using System.Threading.Tasks;

namespace {YourApplication}.Queries.Search;

public class SearchPoliciesGetSingle : FlexiQueryBridgeAsync<PolicyDto>
{
	protected readonly ILogger<SearchPoliciesGetSingle> _logger;
	protected readonly IFlexHost _flexHost;
	protected readonly IFlexSearchStore _searchStore;
	protected SearchPoliciesGetSingleParams _params;
	protected FlexAppContextBridge _flexAppContext;

	public SearchPoliciesGetSingle(ILogger<SearchPoliciesGetSingle> logger, IFlexHost flexHost, IFlexSearchStore searchStore)
	{
		_logger = logger;
		_flexHost = flexHost;
		_searchStore = searchStore;
	}

	public virtual SearchPoliciesGetSingle AssignParameters(SearchPoliciesGetSingleParams @params)
	{
		_params = @params;
		return this;
	}

	public virtual async Task<PolicyDto?> Fetch()
	{
		_flexAppContext = _params.GetAppContext();

		var results = await _searchStore.SearchAsync<PolicySearchDocument>(
			_params.Query,
			take: 1);

		var first = results.FirstOrDefault();
		// TODO: map PolicySearchDocument -> PolicyDto
		return first as PolicyDto;
	}
}

public class SearchPoliciesGetSingleParams : DtoBridge
{
	public string Query { get; set; }
}

public class PolicySearchDocument
{
	public string Id { get; set; }
}
```

## SQL Server considerations

* Ensure SQL Server Full-Text Search is installed/enabled for the instance.
* The configured database identity must be able to query the full-text catalog and underlying table(s).
