Search Implementation
Overview
Section titled “Overview”Formation implements a two-phase search architecture combining SQL Server full-text search with application-level ranking.
Architecture
Section titled “Architecture”sequenceDiagram participant Client participant Controller participant SearchService participant SQLServer
Client->>Controller: GET Schemes with $search Controller->>SearchService: Parse query + extract fields SearchService->>SQLServer: Phase 1 — CONTAINS full-text search SQLServer-->>SearchService: Filtered results SearchService->>SearchService: Phase 2 — rank by relevance SearchService-->>Controller: Ranked, paged results Controller-->>Client: OData responseQuery Syntax
Section titled “Query Syntax”The search query supports two types of terms:
Field-specific filters
Section titled “Field-specific filters”Prefix with a field name and colon:
status:complete name:"Tower A"Free-text search
Section titled “Free-text search”Terms without a field prefix search across all enabled fields:
london residentialCombined
Section titled “Combined”status:complete name:"Tower A" londonSearch Options
Section titled “Search Options”Each entity defines searchable fields in a *SearchOptions.cs class:
public class SchemeSearchOptions{ public bool SchemeName { get; set; } public bool Address { get; set; } public bool Companies { get; set; }}Ranking
Section titled “Ranking”Results are ranked by relevance using a scoring algorithm that considers:
- Exact matches score highest
- Prefix matches score next
- Contains matches score lowest
- Matches in primary fields (e.g., Name) score higher than secondary fields