
Security Fundamentals
Obfuscation 101: Unmasking the Tricks Behind Malicious Code
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
lucene-query-string-builder
Advanced tools
Easily build your lucene string queries using small and pure functions.
Imagine having an API that leverages lucene for performing queries on the (indexed) database. In that case you might want to generate lucene query strings on the client/front end.
The usage section shows how you can leverage this lib for your purposes.
bower install lucene-query-string-builder --save
# or
npm install lucene-query-string-builder --save
Let's see how you can use lucene query string builder to define lucene query strings with simple JavaScript functions.
Assuming that the lucene global variable contains the lucene functions. This would be the default when loaded into a browser.
var findUserLuceneQueryString = lucene.builder(function(data){
// just to make the example more readable;
var _ = lucene;
return _.group(_.and(
_.field('eye-color', _.term(data.eye.color)),
_.field('age', _.range(data.age.min, data.age.max))
));
});
var luceneQueryString = findUserLuceneQueryString({
eye: { color: 'brown'},
age: {
min: 10,
max: 20
}
});
luceneQueryString === '( eye-color: "brown" AND age:{ 10 TO 20 } )' // => true
The functions are based on the lucene specifications found here: https://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Terms
var _ = lucene;
/***
* terms or term
*/
_.term('hello'); // => '"hello"'
_.terms('hello world'); // => '"hello world"'
/***
* field
*/
_.field('hello', _.term('world')); // => 'hello: "world"'
/***
* or/and/not
*
* These functions are variadic and all work the same way. This example only
shows the or but ot works similar with and and not
*/
_.or(_.term('hello'), _.term('world')); // => '"hello" OR "world"'
_.or(_.term('hello'), _.term('you'), _.term('world')); // => '"hello" OR "you" OR "world"'
/***
* group
*
* Is a variadic function too
*/
_.group(_.term('hello'), _.term('you'), _.term('world')); // => '( "hello" "you" "world" )'
/***
* range
*
* Takes two strings and 2 booleans.
*/
/* combined with the field function to query for ages between 10 and 20 */
_.field('age', _.range(10, 20)); // => 'age: { 10 TO 20 }'
/***
* fuzzy
*/
_.fuzzy(_.term('hello'), 0.2); // => '"hello"~0.2'
/***
* proximity
*/
_.proximity("a", "c", 2); // => '"a b"'~2
/***
* required
*/
_.required(_.term('required')); // => '+"required"'
I have not gotten the chance to use this lib in my own projects. Please share your thoughts, issues and improvements.
npm run-script setup
When performing pull request make sure to not add the dist files. This is left to the maintainers(s) of the library. They are responsible to version and avoid code breakages.
You can perform your own build with npm run-script
build to make a lucine.js and
a lucine.min.js
notice
I am currently not using this repository in any of my projects. Therefore I am looking for people that are able to make LQSB more useful for them and others.
The MIT License (MIT)
FAQs
Build Lucene queries by defining lucene query builders
The npm package lucene-query-string-builder receives a total of 436 weekly downloads. As such, lucene-query-string-builder popularity was classified as not popular.
We found that lucene-query-string-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.
Security News
Biome's v2.0 beta introduces custom plugins, domain-specific linting, and type-aware rules while laying groundwork for HTML support and embedded language features in 2025.