Socket
Socket
Sign inDemoInstall

lucene-query-builder

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.3 to 0.7.4

1

lib/cjs/constants/defaultValues.d.ts
export declare const defaultValues: {
fuzzyLetters: number;
fuzzyLevel: number;
proximity: number;
};

3

lib/cjs/constants/defaultValues.js

@@ -5,4 +5,5 @@ "use strict";

exports.defaultValues = {
fuzzyLetters: 5,
fuzzyLetters: 3,
fuzzyLevel: 1,
proximity: 1,
};

@@ -9,2 +9,2 @@ import { PhraseOptions } from '../types';

*/
export declare const processPhrase: (phrase?: string, { fuzzyLetters, fuzzyLevel, }?: PhraseOptions) => string;
export declare const processPhrase: (phrase?: string, { fuzzyLetters, fuzzyLevel, proximity, }?: PhraseOptions) => string;

@@ -12,13 +12,17 @@ "use strict";

*/
const processPhrase = (phrase, { fuzzyLetters = defaultValues_1.defaultValues.fuzzyLetters, fuzzyLevel = defaultValues_1.defaultValues.fuzzyLevel, } = {}) => {
const processPhrase = (phrase, { fuzzyLetters = defaultValues_1.defaultValues.fuzzyLetters, fuzzyLevel = defaultValues_1.defaultValues.fuzzyLevel, proximity = defaultValues_1.defaultValues.proximity, } = {}) => {
if (!phrase)
return '*:*';
phrase = phrase.trim();
if (phrase.length < fuzzyLetters)
return phrase;
return phrase
.split(/\s+/)
.map((word) => `"${word}"~${fuzzyLevel}`)
.join(' ');
let words = phrase.split(/\s+/);
// Single word - apply fuzzy search or append wildcard
if (words.length === 1) {
return words[0].length >= fuzzyLetters ? `${words[0]}~${fuzzyLevel}` : `${words[0]}*`;
}
// Multiple words - apply fuzzy and proximity search
words = words.map((word) => {
return word.length >= fuzzyLetters ? `${word}~${fuzzyLevel}` : word;
});
return `"${words.join(' ')}"~${proximity}`;
};
exports.processPhrase = processPhrase;

@@ -21,3 +21,3 @@ "use strict";

urlEncoded: false,
strictDateRanges: false
strictDateRanges: false,
};

@@ -24,0 +24,0 @@ this.options = Object.assign(Object.assign({}, defaultOptions), options);

@@ -29,6 +29,8 @@ /**

export interface PhraseOptions {
/** Number of letters in phrase to start fuzzy matching. */
/** Number of letters in a word to start fuzzy matching. */
fuzzyLetters?: number;
/** Fuzzy matching level. */
fuzzyLevel?: number;
/** Proximity distance. */
proximity?: number;
}

@@ -35,0 +37,0 @@ /**

export declare const defaultValues: {
fuzzyLetters: number;
fuzzyLevel: number;
proximity: number;
};
export const defaultValues = {
fuzzyLetters: 5,
fuzzyLetters: 3,
fuzzyLevel: 1,
proximity: 1,
};

@@ -9,2 +9,2 @@ import { PhraseOptions } from '../types';

*/
export declare const processPhrase: (phrase?: string, { fuzzyLetters, fuzzyLevel, }?: PhraseOptions) => string;
export declare const processPhrase: (phrase?: string, { fuzzyLetters, fuzzyLevel, proximity, }?: PhraseOptions) => string;

@@ -9,12 +9,16 @@ import { defaultValues } from '../constants/defaultValues';

*/
export const processPhrase = (phrase, { fuzzyLetters = defaultValues.fuzzyLetters, fuzzyLevel = defaultValues.fuzzyLevel, } = {}) => {
export const processPhrase = (phrase, { fuzzyLetters = defaultValues.fuzzyLetters, fuzzyLevel = defaultValues.fuzzyLevel, proximity = defaultValues.proximity, } = {}) => {
if (!phrase)
return '*:*';
phrase = phrase.trim();
if (phrase.length < fuzzyLetters)
return phrase;
return phrase
.split(/\s+/)
.map((word) => `"${word}"~${fuzzyLevel}`)
.join(' ');
let words = phrase.split(/\s+/);
// Single word - apply fuzzy search or append wildcard
if (words.length === 1) {
return words[0].length >= fuzzyLetters ? `${words[0]}~${fuzzyLevel}` : `${words[0]}*`;
}
// Multiple words - apply fuzzy and proximity search
words = words.map((word) => {
return word.length >= fuzzyLetters ? `${word}~${fuzzyLevel}` : word;
});
return `"${words.join(' ')}"~${proximity}`;
};

@@ -18,3 +18,3 @@ import { query } from './query';

urlEncoded: false,
strictDateRanges: false
strictDateRanges: false,
};

@@ -21,0 +21,0 @@ this.options = Object.assign(Object.assign({}, defaultOptions), options);

@@ -29,6 +29,8 @@ /**

export interface PhraseOptions {
/** Number of letters in phrase to start fuzzy matching. */
/** Number of letters in a word to start fuzzy matching. */
fuzzyLetters?: number;
/** Fuzzy matching level. */
fuzzyLevel?: number;
/** Proximity distance. */
proximity?: number;
}

@@ -35,0 +37,0 @@ /**

{
"name": "lucene-query-builder",
"version": "0.7.3",
"version": "0.7.4",
"description": "Library to build lucene queries in a typescript friendly way",

@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js",

@@ -171,6 +171,7 @@ # Lucene Query Builder

|------------------|---------------|------------------------------------------------------------------------------------------------------|
| `fuzzyLetters` | `5` | The number of letters in the phrase to start fuzzy matching. |
| `fuzzyLetters` | `3` | The number of letters in the phrase to start fuzzy matching. |
| `fuzzyLevel` | `1` | The level of fuzzy matching. |
| `proximity` | `1` | The number of words allowed between words in the phrase. |
| `urlEncoded` | `false` | A boolean indicating whether the returned query string should be URL-encoded. |
| `strictDateRanges`| `false` | Indicates whether the resulting date query should be strict (bonded with 'AND') or not (bonded with 'OR'). |
| `strictDateRanges`| `false` | Indicates whether the resulting date query should be strict (bonded with 'AND') or not (bonded with 'OR'). |

@@ -177,0 +178,0 @@ #### Option Details

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc