Skip to content

Search Implementation

Formation implements a two-phase search architecture combining SQL Server full-text search with application-level ranking.

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 response

The search query supports two types of terms:

Prefix with a field name and colon:

status:complete name:"Tower A"

Terms without a field prefix search across all enabled fields:

london residential
status:complete name:"Tower A" london

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; }
}

Results are ranked by relevance using a scoring algorithm that considers:

  1. Exact matches score highest
  2. Prefix matches score next
  3. Contains matches score lowest
  4. Matches in primary fields (e.g., Name) score higher than secondary fields