Skip to content

HaileabT/full-text-search-postgres-nodejs

Repository files navigation

This is a lightweight full text search library for nodejs postgres

Usage

  1. Clone it
git clone https://github.com/HaileabT/full-text-search-postgres-nodejs.git /your/desired/path
  1. Install dependencies
npm i
  1. Create postgres connection
const connectionObject = new PostgresConnection("postgres", "password@", 5432, "random_db", "localhost");
  1. Create a search manager
const searchManagerOptions: FullTextSearchManagerOptions = {
  mainEntity: "human",
  fieldsToBeSearched: [
    { entity: "skill", field: "title", relationField: "human_id", rank: "A" },
    { entity: "human", field: "name", relationField: "", rank: "A" },
  ],
};

const searchManager = FullTextSearchManager.init(connectionObject.conn, searchManagerOptions);

FullTextSearchManagerOptions

type FullTextSearchManagerOptions = {
  mainEntity: string;  // Entity to be searched
  fieldsToBeSearched?: EntityField[];  // Fields to be searched picked from all entities
};

EntityField

interface EntityField = {
  entity: string; // Entity where the might-be-searched field exists
  field: string; // Field name
  relationField?: string; // The foreign key with which the main entity relates to this field's entity
  rank?: "A" | "B" | "C" | "D"; // Rank of this field
}
  1. Search
const doSearch = async () => {
  if (!searchManager) return;
  const res = await searchManager.search("karate");

  console.log(res);
};

doSearch();

About

This is my trial to make a full text search library for postgres nodejs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published