{"_id":"boolean-parser","_rev":"7-78b52603b682719f9f204b719055fde7","name":"boolean-parser","description":"Script that parses a boolean query to an array with all the possibilities. IE: (a AND (b OR c)) -> [[a, b],[a, c]]","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.0":{"name":"boolean-parser","version":"0.0.0","description":"Script that parses a boolean query to an array with all the possibilities. IE: (a AND (b OR c)) -> [[a, b],[a, c]]","main":"index.js","scripts":{"test":"./node_modules/mocha/bin/mocha"},"repository":{"type":"git","url":"https://github.com/riichard/boolean-parser-js.git"},"keywords":["boolean","keywords","parser","query","parser","lucene"],"author":{"name":"Richard Kraaijenhagen","email":"stdin@riichard.com"},"license":"MIT","bugs":{"url":"https://github.com/riichard/boolean-parser-js/issues"},"homepage":"https://github.com/riichard/boolean-parser-js","dependencies":{"mocha":"^2.3.4"},"gitHead":"f59e77806ddee1e9685416041b609b52877bac62","_id":"boolean-parser@0.0.0","_shasum":"7a2a988b8074916da8e1796aa2bd704d86782bb7","_from":".","_npmVersion":"1.4.16","_npmUser":{"name":"riichard","email":"stdin@riichard.com"},"maintainers":[{"name":"riichard","email":"stdin@riichard.com"}],"dist":{"shasum":"7a2a988b8074916da8e1796aa2bd704d86782bb7","tarball":"https://registry.npmjs.org/boolean-parser/-/boolean-parser-0.0.0.tgz","integrity":"sha512-uGKzh7XWqp+gwLQT2TvqeJNHh6prWob1rFnC5ePkgcBxhIPTdv3LM9s6CdmpCHMyXaelna6mpR3pKZqLRN5RPg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChr/k8Vgybh8zy0wtPh05sCldIpZ6v1wtIedF1J08GQgIgX5g4bU/7Jix36ztln5aQJ2FvAltFWBLa/ffnsZogRtg="}]}},"0.0.1":{"name":"boolean-parser","version":"0.0.1","description":"Script that parses a boolean query to an array with all the possibilities. IE: (a AND (b OR c)) -> [[a, b],[a, c]]","main":"index.js","scripts":{"test":"./node_modules/mocha/bin/mocha"},"repository":{"type":"git","url":"git+https://github.com/riichard/boolean-parser-js.git"},"keywords":["boolean","keywords","parser","query","parser","lucene"],"author":{"name":"Richard Kraaijenhagen","email":"stdin@riichard.com"},"license":"MIT","bugs":{"url":"https://github.com/riichard/boolean-parser-js/issues"},"homepage":"https://github.com/riichard/boolean-parser-js","devDependencies":{"mocha":"^3.1.0"},"gitHead":"061bf649cc0824e3619823dde9bf2fcb2e6363a7","_id":"boolean-parser@0.0.1","_shasum":"55b28ba92314c909bfd5fe914d8b94a90cb11ca8","_from":".","_npmVersion":"3.10.8","_nodeVersion":"4.4.0","_npmUser":{"name":"riichard","email":"stdin@riichard.com"},"dist":{"shasum":"55b28ba92314c909bfd5fe914d8b94a90cb11ca8","tarball":"https://registry.npmjs.org/boolean-parser/-/boolean-parser-0.0.1.tgz","integrity":"sha512-iVBiV92L8wo+4Gy10nc+PHi/hiEf+k87UREPAlXjE3kWRaymgm8qaCxv+MDNnLxbxnQ6vgtsp5UZ9zP9pgawIA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCndVMqgHo9HudvZC+eFbS5ULn5BrxBJbuLjJYIoQAGgAIgE2LNWMh/BNtJA7F+vC9H3JSzZbNTsKbVuUfpj1fU6zg="}]},"maintainers":[{"name":"riichard","email":"stdin@riichard.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/boolean-parser-0.0.1.tgz_1477566609154_0.9867414887994528"}},"0.0.2":{"name":"boolean-parser","version":"0.0.2","description":"Script that parses a boolean query to an array with all the possibilities. IE: (a AND (b OR c)) -> [[a, b],[a, c]]","main":"index.js","scripts":{"test":"./node_modules/mocha/bin/mocha"},"repository":{"type":"git","url":"git+https://github.com/riichard/boolean-parser-js.git"},"keywords":["boolean","keywords","parser","query","parser","lucene"],"author":{"name":"Richard Kraaijenhagen","email":"stdin@riichard.com"},"license":"MIT","bugs":{"url":"https://github.com/riichard/boolean-parser-js/issues"},"homepage":"https://github.com/riichard/boolean-parser-js","devDependencies":{"mocha":"^3.1.0"},"gitHead":"90a13a2f721f893d8973191e7c909f6e8ebda7e5","_id":"boolean-parser@0.0.2","_shasum":"58721f1172e65fd132d6e6debbd00053deaffa12","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"riichard","email":"stdin@riichard.com"},"dist":{"shasum":"58721f1172e65fd132d6e6debbd00053deaffa12","tarball":"https://registry.npmjs.org/boolean-parser/-/boolean-parser-0.0.2.tgz","integrity":"sha512-e06Mqk6t7DOXaEo3s+RATvv7ZNt5brRQ2os4NUHVkVCzUD0Z7Gw4AL4AFA/gT3WaLhrobmGvRVh1/UuJiY3sKg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBtaUGBePTK30ywv2cl86/5FbsWkTZl7E3+Nk9vxO/DpAiBnMZe1DIbDsz8x1mbo/dP6BCZkpXc0cfNF0WQuyM6wfQ=="}]},"maintainers":[{"name":"riichard","email":"stdin@riichard.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/boolean-parser-0.0.2.tgz_1485428302393_0.05734870443120599"}}},"readme":"[![Build Status](https://travis-ci.org/riichard/boolean-parser-js.svg?branch=master)](https://travis-ci.org/riichard/boolean-parser-js) [![Join the chat at https://gitter.im/riichard/boolean-parser-js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/riichard/boolean-parser-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n# Boolean-parser\n\nThis function converts a boolean query to a 2 dimensional array with all possibilities. This allows you to quickly and easily see what scenarios will equal true in a complex boolean conditional.\n\n#### Examples:\n\nInput                         | Output\n--------                      | ---------\n`a AND b`                     | `[[a, b]]`\n`a OR  b`                     | `[[a], [b]]`\n`a AND b AND c`               | `[[a, b, c]]`\n`a AND b OR  c`               | `[[a, b], [c]]`\n`a AND (b OR c)`              | `[[a, b], [a, c]]`\n`a AND (b OR c) AND (d OR e)` | `[[a, b, d], [a, b, e], [a, c, d], [a, c, e]]`\n\nWhereas `a`, `b` and `c` represent words, forming a complex query pattern.\n\nThis function works recursively trough all brackets and generates an array of all possible combinations\nof a matching query.\n\n#### Long term example\n\n###### Input:\n```\n((a AND (b OR c)) AND (d AND e) AND (f OR g OR h)) OR i OR j\n```\n\n###### Output:\n```\n[[a,b,d,e,f],\n [a,c,d,e,f],\n [a,b,d,e,g],\n [a,c,d,e,g],\n [a,b,d,e,h],\n [a,c,d,e,h],\n [i],\n [j]]\n```\n\n## Philosophy\nThe output is meant to be easily parsed to check for matches.\nThere are more efficient ways to check matches to this query by only checking each term once,\nthough this method is one that is easier to maintain and limits risk of side effects.\nEspecially when considering recursively nested queries involving many brackets\nand AND/OR combinations.\n\n## Installing\n```\nnpm install boolean-parser\n```\n\n## Usage\n```javascript\nvar booleanParser = require('boolean-parser');\n\nvar searchPhrase = '((a AND (b OR c)) AND (d AND e) AND (f OR g OR h)) OR i OR j';\n\nvar parsedQuery = booleanParser.parseBooleanQuery(searchPhrase);\n// Returns:\n// [['a','b','d','e','f'],\n//  ['a','b','d','e','g'],\n//  ['a','b','d','e','h'],\n//  ['a','c','d','e','f'],\n//  ['a','c','d','e','g'],\n//  ['a','c','d','e','h'],\n//  ['i'],['j']]\n```\n\n## Use cases\nThis tool is great when constructing complex search filters that need to be matched with text. Creating search tools that need to show up more refined results than that would be possible with a simple `AND` combination.\n\n## How does this library work\n1. Parse string to an Array of OR items (strings). Everything that's in between brackets\nwill be treated as one word and will later be recursively parsed.\n2. Go trough each string in that Array, and parse it to an array of AND items.\n3. Recursively call the `parseBooleanQuery` function on whatever is in between\nbrackets. These recursive calls will return an array of all possible combinations\nwithin those brackets. (An `OR` array of `AND` combinations)\n4. Create an empty array called `nestedPaths`. And add all nested combinations that\nare in between brackets to that array.\nFor instance, with the query:\n```\n((a AND (b OR c)) AND (d AND e) AND (f OR g OR h OR j)) AND x AND y AND z\n```\nPath will look like the following.\n```javascript\n// nestedPath =\n[ [ [a,b], [a,c] ],\n  [ [d,e] ],\n  [ [f], [g], [h], [j] ] ]\n```\n5. Then push the remaining non-bracket AND terms to this array.\n```javascript\n// nestedPath =\n[ [ [a,b], [a,c] ],\n  [ [d,e] ],\n  [ [f], [g], [h], [j] ]\n  [ [x,y,z] ] ]\n```\n6. Then using the `orsAndMerge`, all those AND paths in those OR paths will be combined with the\nother OR combinations.\nIn:\n```\n[\n    [ [ a ], [ b ] ],\n    [ [ c, d ], [ e ] ],\n    [ [ f ] ]\n]\n```\nOut:\n```\n[\n    [ a, c, d, f ],\n    [ b, c, d, f ],\n    [ a, e, f ],\n    [ b, e, f ]\n]\n```\n\n7. Then we concatenate all those `OR` paths that were in between those `OR` terms\nto one Array using the `mergeOrs` function.\nIn:\n```\n[\n    [ [ a, b ], [ c ] ],\n    [ [ d ] ],\n    [ [ e ], [ f, g ] ]\n]\n```\nOut:\n```\n[\n    [ a, b ], [ c ], [ d ], [ e ], [ f, g ]\n]\n```\n","maintainers":[{"name":"riichard","email":"stdin@riichard.com"}],"time":{"modified":"2022-06-13T04:56:01.964Z","created":"2015-11-26T14:21:07.652Z","0.0.0":"2015-11-26T14:21:07.652Z","0.0.1":"2016-10-27T11:10:11.868Z","0.0.2":"2017-01-26T10:58:23.051Z"},"homepage":"https://github.com/riichard/boolean-parser-js","keywords":["boolean","keywords","parser","query","parser","lucene"],"repository":{"type":"git","url":"git+https://github.com/riichard/boolean-parser-js.git"},"author":{"name":"Richard Kraaijenhagen","email":"stdin@riichard.com"},"bugs":{"url":"https://github.com/riichard/boolean-parser-js/issues"},"license":"MIT","readmeFilename":"README.md"}