Git Product home page Git Product logo

Comments (8)

caub avatar caub commented on August 24, 2024 1

Nice catch, I'll implement quoting, single or double quotes to search literal values

from pg-tsquery.

caub avatar caub commented on August 24, 2024 1

@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.

blasterpistol avatar blasterpistol commented on August 24, 2024

This will be good

from pg-tsquery.

caub avatar caub commented on August 24, 2024

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.

blasterpistol avatar blasterpistol commented on August 24, 2024

Can we just disable some options with this approach?

from pg-tsquery.

caub avatar caub commented on August 24, 2024

@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.

linojon avatar linojon commented on August 24, 2024

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.

caub avatar caub commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.