Registry / serialization / lucene-query-parser

lucene-query-parser

JSON →
library1.2.0jsnpmunverified

This library offers a JavaScript implementation of the Lucene query parser, allowing applications to translate Lucene-style query strings into an Abstract Syntax Tree (AST). It was developed using PEG.js, a parser generator. The current stable version is 1.2.0, which was released in 2017. The project appears to be abandoned, with no significant updates or commits in several years. Its key differentiator is providing a direct JavaScript port of the Lucene query parsing logic, enabling both client-side and server-side (Node.js) applications to interpret complex search queries adhering to Lucene syntax. Users should be aware of its inactive development status and potential compatibility challenges with modern JavaScript ecosystems, especially concerning ES Modules (ESM) or newer Node.js features, as it predates widespread adoption of these standards.

npm install lucene-query-parser
INSTALL
IMPORT
SIG · LUCENE-QUERY-PARSE
L
lucene-query-parser
serializationjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
const parser = require('lucene-query-parser');
import parser from 'lucene-query-parser';
This library is CommonJS-first. Direct ESM `import` statements are not supported without a build step or shim.
lucenequeryparser (AMD)
require(['lucene-query-parser.js'], function(lucenequeryparser) { /* ... */ });
For browser usage with RequireJS, the library is exposed as an AMD module. The filename includes `.js`.

Demonstrates how to parse simple and grouped Lucene query strings into an AST and access the parsed components.

const parser = require('lucene-query-parser'); // Basic query parsing example const results1 = parser.parse('title:"The Right Way" AND text:go'); console.log('--- Example 1: Basic Query ---'); console.log(`Left field: ${results1['left']['field']}`); console.log(`Left term: ${results1['left']['term']}`); console.log(`Operator: ${results1['operator']}`); console.log(`Right field: ${results1['right']['field']}`); console.log(`Right term: ${results1['right']['term']}`); // More complex query with grouping const results2 = parser.parse('test AND (foo OR bar)'); console.log('\n--- Example 2: Grouped Query ---'); console.log(`Left term: ${results2['left']['term']}`); console.log(`Operator: ${results2['operator']}`); const rightNode = results2['right']; // The grouped expression is a nested node console.log(`Nested left term: ${rightNode['left']['term']}`); console.log(`Nested operator: ${rightNode['operator']}`); console.log(`Nested right term: ${rightNode['right']['term']}`);
Debug
Known issues
gotchaThis package is not actively maintained. The last commit was in September 2017. Users should be aware of potential security vulnerabilities in its dependencies or lack of compatibility with modern JavaScript features and environments.
fix
Consider forking the repository and updating its dependencies, or migrating to a more actively maintained Lucene parser if long-term support is required.
affects: >=1.2.0
gotchaThe library primarily uses CommonJS (CJS) module syntax (`require`). It does not natively support ES Modules (ESM) `import` statements, which can lead to issues in modern Node.js projects or browser environments that are ESM-first.
fix
For Node.js, ensure your project is configured for CJS, or use dynamic `import()` if ESM is necessary. For browser, use the provided AMD module with RequireJS or bundle it using a tool like Webpack/Rollup that can handle CJS modules.
affects: >=1.0.0
gotchaThere are no TypeScript type definitions (`.d.ts` files) shipped with this package, nor are they available on DefinitelyTyped. This means TypeScript users will not get type safety or autocomplete for the parser's output.
fix
Manually create a declaration file (`lucene-query-parser.d.ts`) to provide types for the parsed AST structure, or cast the parser's output to `any`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to use `require()` in an ES Module context (`type: module` in package.json or `.mjs` file).
fix
Change your file to a CommonJS context (e.g., rename to `.js` if `type: module` is not set, or ensure it's not an `.mjs` file). Alternatively, use `import parser from 'lucene-query-parser';` if your bundler supports transpiling CJS to ESM, or `const parser = await import('lucene-query-parser');` for dynamic import.
Error: Cannot find module 'lucene-query-parser'
The package is not installed or the `require` path is incorrect.
fix
Run `npm install lucene-query-parser` to install the package. Ensure the `require` statement uses the correct package name.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
lucene-query-parser — npm install lucene-query-parser · libregistry