import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import type EmailAddressName from "./EmailAddressName.js"; /** * Since set of names will intersect with set of tags very rarely. * We want to break names by spaces and save tokens with and without numbers. * We will save username @ domain.com separately for faster search. * * Why not store full text in EmailAddressName itself? * Since one name will be linked with many addresses. It will require less * storage and faster access compared to inbuilt FTS. * * And This is the most important part for Auto Complete. * * Why store suggest column? * In dropdown we will only display suggestion if the name token has more than * 2 chars. * * So why store less than 2 chars? * User should be able to search `akash.in` by searching for 'in' in the search bar * ignoring auto complete. */ @Table("NameTokens") @Index({ name: "UX_NameTokens_Unique_V2", dropNames: [ "UX_NameTokens_Unique"], unique: true, columns: [ { name: (x) => x.word, descending: false, operatorClass: "varchar_pattern" }, ] }) @Index({ name: "IX_NameTokens_Suggest", columns: [ { name: (x) => x.word, descending: false, operatorClass: "varchar_pattern" }], filter: (x) => x.suggest === true }) export default class NameToken { @Column({ dataType: "BigInt", key: true, generated: "identity"}) public nameTokenID: number; @Column({ dataType: "Char", length: 400 }) public word: string; @Column({ dataType:"Boolean", computed: (x) => Sql.text.length(x.word) > 2}) public suggest: boolean; emailAddressNames: EmailAddressName[]; }