0.0.9 • Published 10 years ago

regex-trigram v0.0.9

Weekly downloads
7
License
BSD New
Repository
github
Last release
10 years ago

Build Status NPM version

regex-trigram-js

This project ports some ideas Russ Cox shared on how Google Code Search works — in particular the RegexpQuery and related functions — from Go to JavaScript. Since JavaScript doesn't have an equivalent to Go's regexp/syntax, use PEG.js to introduce a simplified regular expression grammar and obtain a parse tree.

The goal is to query trigram indexes from JS clients.

Usage

Include the library.

var regex = require('regex-trigram');

Parse a regular expression.

var re = regex.parse("a[bc]d");
console.log(JSON.stringify(re, null, 2));

Which should look like:

{
  "type": "concat",
  "value": [
    {
      "type": "literal",
      "value": "a"
    },
    {
      "type": "concat",
      "value": [
        {
          "type": "char_class",
          "value": "bc"
        },
        {
          "type": "literal",
          "value": "d"
        }
      ]
    }
  ]
}

Convert the parsed regular expression into a trigram query.

var q = regex.query(re);
console.log(JSON.stringify(q, null, 2));

Which should look like:

{
  "op": "OR",
  "trigram": [
    "abd",
    "acd"
  ],
  "sub": []
}
0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago