tango-core 0.3.0

The tango schema, entities, migrations, and search contract
Documentation
use sea_orm_migration::prelude::*;

/// Lets a search say which text it wants matched.
///
/// The searchable text was decided by the schema rather than by the caller: one
/// weighted `fts` vector over title and description, so the only options were
/// "all of it" or `exact_only`, which meant "title, literally". Tags were
/// stored by both backends and searched by nothing.
///
/// This splits that into two axes, because `exact_only` had a field and a mode
/// in one boolean and so could not be extended into either:
///
///   - `p_search_in` — which text may match: title, description, tags,
///     transcript. `include_transcripts` is gone, because
///     `'transcript' = ANY(p_search_in)` is the same question asked once.
///   - `substring_only` — literal matching over that same list, replacing
///     `exact_only`.
///
/// One vector per field replaces the weighted one. A mixed vector cannot answer
/// "which field matched?", which is the question a field list exists to ask, and
/// `in=title` cannot be filtered against it at all. The cost is a ranking
/// change: `ts_rank` no longer weights a description with many matches above a
/// title with one, because the field decides instead of the count.
///
/// A video whose title and description both match is one row reporting its
/// title, which is the same suppression the fuzzy and transcript tiers already
/// applied to full-text hits.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0018_search_fields.sql");

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager.get_connection().execute_unprepared(UP).await?;
        Ok(())
    }

    async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
        // A no-op, like 0010 through 0017. The reverse means dropping the new
        // functions, dropping the per-field columns, and reinstating the
        // combined `fts` — which is another copy of the search branches to
        // keep in step, the duplication 0014 exists to prevent. A revert leaves
        // search matching every field it is given, which is the same function
        // with a wider default rather than a broken one.
        Ok(())
    }
}