Skip to content

Convert a line of string to machine understandable search query

Notifications You must be signed in to change notification settings

patarapolw/search-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search-query

Convert one line search query to machine-readable query, preferably on client-side.

Usage

Example

const sq = new MongoSearchQuery({
    any: ["x", "y", "z"]
});

console.log(inspect(sq.search(`a`), false, null, true));
console.log(inspect(sq.search(`1`), false, null, true));
console.log(inspect(sq.search(`"a":1 b`), false, null, true));
console.log(inspect(sq.search(`(a OR b>2) OR c=a`), false, null, true));

Output:

{ '$or':
   [ { x: { '$regexp': 'a' } },
     { y: { '$regexp': 'a' } },
     { z: { '$regexp': 'a' } },
     [length]: 3 ] }
{ '$or':
   [ { x: { '$regexp': '1' } },
     { y: { '$regexp': '1' } },
     { z: { '$regexp': '1' } },
     [length]: 3 ] }
{ '$and':
   [ { a: { '$regexp': '1' } },
     { '$or':
        [ { x: { '$regexp': 'b' } },
          { y: { '$regexp': 'b' } },
          { z: { '$regexp': 'b' } },
          [length]: 3 ] },
     [length]: 2 ] }
{ '$or':
   [ { '$or':
        [ { '$or':
             [ { x: { '$regexp': 'a' } },
               { y: { '$regexp': 'a' } },
               { z: { '$regexp': 'a' } },
               [length]: 3 ] },
          { b: { '$gt': 2 } },
          [length]: 2 ] },
     { c: 'a' },
     [length]: 2 ] }

About

Convert a line of string to machine understandable search query

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published