Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lucene-query-builder

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lucene-query-builder

Library to build lucene queries in a typescript friendly way

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-17.14%
Maintainers
1
Weekly downloads
 
Created
Source

Lucene Query Builder

Lucene Query Builder is a utility for constructing query strings for Lucene. It provides a flexible way to build a query using an object-based approach. The library supports both function-based and class-based usage.

Installation

Install Lucene Query Builder with npm:

npm install lucene-query-builder
yarn add lucene-query-builder

Usage

Function-based Usage

import { query } from 'lucene-query-builder'

const myQuery = query({
  phrase: 'Hello world',
  and: [{ fieldName: 'value1' }, { anotherField: ['value1', 'value2'] }],
  not: [{ fieldName: 'value2' }],
  options: {
    fuzzyLetters: 5,
    fuzzyLevel: 1,
    urlEncoded: true
  },
})

console.log(myQuery)

Class-based Usage

import { QueryBuilder } from 'lucene-query-builder'

const queryBuilder = new QueryBuilder({ 
  fuzzyLetters: 5, 
  fuzzyLevel: 1, 
  urlEncoded: true 
})

const myQuery = queryBuilder.query({
  phrase: 'Hello world',
  and: [{ fieldName: 'value1' }, { anotherField: ['value1', 'value2'] }],
  not: [{ fieldName: 'value2' }],
})

console.log(myQuery)

Function Parameters and Options

ParameterDescription
phraseThe phrase to search for.
andAn array of terms to be included in the query. Each term is an object with the field name as key and the corresponding values.
notAn array of terms to be excluded from the query. Each term is an object with the field name as key and the corresponding values.
optionsAn object containing various options for query building. See below for more details.

Options

OptionDefault valueDescription
fuzzyLetters5The number of letters in the phrase to start fuzzy matching.
fuzzyLevel1The level of fuzzy matching.
urlEncodedfalseA boolean indicating whether the returned query string should be URL-encoded.

License

MIT

Keywords

FAQs

Package last updated on 04 Aug 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc