0.1.1 • Published 7 years ago

@sql-extra/matchtsquery v0.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

@sql-extra/matchtsquery

sql-extra

Generate SQL query for matching words with tsquery.

const matchTsquery = require('@sql-extra/matchtsquery');
// matchTsquery(<table>, <words>, [tsvector], [options])
// -> sql command

// options: {
//   columns: '*',  // select columns: all
//   order: false,  // order rows: no
//   limit: 0,      // limit rows: no
//   normalization: 0,  // rank normalization: ignores the document length
// }


matchTsquery('columns', ['total', 'fat']);
// SELECT *, '2'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') UNION ALL
// SELECT *, '1'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total');

matchTsquery('columns', ['total', 'fat'], '"tsvector"', {columns: '"code"'});
// SELECT "code", '2'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') UNION ALL
// SELECT "code", '1'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total');

matchTsquery('columns', ['total', 'fat'], '"tsvector"', {order: true, limit: 1, normalization: 2});
// SELECT *, '2'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') ORDER BY ts_rank("tsvector", plainto_tsquery('total fat'), 2) DESC UNION ALL
// SELECT *, '1'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total') ORDER BY ts_rank("tsvector", plainto_tsquery('total'), 2) DESC LIMIT 1;
0.1.1

7 years ago

0.1.0

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago