import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; export const searchWordStatues = ["begin", "ready", "deleted"] as const; export type searchWordStatusType = typeof searchWordStatues[number]; /** * Search word represents a single word that appears in any document. * The search runs through the documents when requested first time. * Index will start building from the recent to the first document. * * The reason this exists is, this will only index what was searched. * And cache will remain in the system for couple of days. And it will * also be updated daily. * * If no body searches for this item again, this keyword will be removed * to make up extra space. */ @Table("SearchWords") export default class SearchWord { @Column({ dataType: "BigInt", generated: "identity", key: true }) wordID: number; @Column({ dataType: "Char" }) word: string; @Column({}) dateCreated: DateTime; @Column({}) dateUpdated: DateTime; @Column({ nullable: true }) expires?: DateTime; @Column({ dataType: "Char", length: 10, enum: searchWordStatues}) status: searchWordStatusType; @Column({ dataType: "BigInt", nullable: true }) recentID: number; @Column({ dataType: "BigInt", nullable: true}) firstID: number; indexes: SearchWordIndex[]; } @Table("SearchWordIndex") export class SearchWordIndex { @Column({ dataType: "BigInt", key: true }) @RelateTo(SearchWord, { property: (i) => i.word, inverseProperty: (w) => w.indexes, foreignKeyConstraint: { onDelete: "cascade" } }) wordID: number; @Column({ dataType: "BigInt", key: true }) fileContentID: number; /** * First two bytes represents the first word occurrence (not character index) in the document. * Last two bytes represents how many times it occurs in the document. * This is based on the fact that import words will appear in the title or the first paragraph * of the document. */ @Column({ dataType: "Int"}) rank: number; word: SearchWord; }