Comments (8)
Nice catch, I'll implement quoting, single or double quotes to search literal values
from pg-tsquery.
@testarossaaaaa I've pushed an update, now you can use quotes: https://github.com/caub/pg-tsquery/blob/master/test/data-default.json#L105-L106
the returned string is then transformed as:
postgres=# select to_tsquery('Test&\"quoted<->text<->G1-ABC<->+37544<->\"');
to_tsquery
-------------------------------------------------------------------------
'test' & 'quot' <-> 'text' <-> ( 'g1-abc' & 'g1' & 'abc' ) <-> '+37544'
from pg-tsquery.
This will be good
from pg-tsquery.
I pushed a configurable version
const tsquery = require('pg-tsquery')();
console.log(tsquery('G1-ABC'));
console.log(tsquery('+a37544:*'));
/*
G1&!ABC
a37544:*
*/
const tsquery2 = require('pg-tsquery')({
OR: /^\s*(?:[|,]|or)/i,
AND: /^(?!\s*(?:[|,]|or))(?:[\s&:|,!]|and)*/i,
FOLLOWED_BY: /^\s*<(?:(?:(\d+)|-)?>)?/,
WORD: /^[\s*&<:,|]*([\s!]*)[\s*&<:,|]*([^\s,|&<:*()[\]!]+)/,
PAR_START: /^\s*!*[([]/,
PAR_END: /^[)\]]/,
NEGATED: /!$/,
PREFIX: /^(\*|:\*)*/,
TAIL_OP: '&',
});
console.log(tsquery2('G1-ABC'));
console.log(tsquery2('+37544:*'));
/*
G1-ABC
+37544:*
*/
The options are still a bit complex maybe, and also I need to have tests with different configurations than the default one, feel free to participate
from pg-tsquery.
Can we just disable some options with this approach?
from pg-tsquery.
@testarossaaaaa This is what the configuration above does, I know it's a bit scary, but this config is simpler than the default one, +
, -
are not parsed
An even simpler one (no or
, and
, [
, ]
parsing, but make sure to test it with enough inputs, and see if it pg never throws
const tsquery3 = require('pg-tsquery')({
OR: /^\s*[|,]/,
AND: /^(?!\s*[|,])[\s&:|,!]*/,
FOLLOWED_BY: /^\s*<(?:(?:(\d+)|-)?>)?/,
WORD: /^[\s*&<:,|]*([\s!]*)[\s*&<:,|]*([^\s,|&<:*()!]+)/,
PAR_START: /^\s*!*[(]/,
PAR_END: /^[)]/,
NEGATED: /!$/,
PREFIX: /^(\*|:\*)*/,
TAIL_OP: '&',
});
console.log(tsquery3('G1-ABC'));
console.log(tsquery3('+37544:*'));
/*
G1-ABC
+37544:*
*/
from pg-tsquery.
Apparently now the keys are camel case and you can override just the negate rule in the constructor, eg
const tsParser = new Tsquery({
negated: /!$/
})
from pg-tsquery.
Yes correct, settings fields are camel cased now as of version 8 c68a36e
Here are the settings: https://github.com/caub/pg-tsquery/blob/master/index.js#L56-L66
from pg-tsquery.
Related Issues (19)
- Refactor as a class
- Words with dashes assume negation HOT 2
- Do not work well with Postgres 13 HOT 2
- Wrap quotes text in parenthesis
- "it's" changing to "its" HOT 4
- Negation should not be applied in some cases HOT 4
- License HOT 1
- Support followed-by operator HOT 1
- Negated wildcard phrase produces invalid syntax HOT 5
- Ending or starting query in `'` character produces invalid syntax HOT 3
- Documentation issue HOT 2
- types don't match module format HOT 6
- interpret 'or' as |
- rollup packaging (for client usage) + docs
- Cannot read property 'negated' of undefined HOT 5
- TypeScript definitions HOT 5
- Phrase searching HOT 4
- Regex error? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pg-tsquery.