Gathering detailed insights and metrics for @basd/search
Gathering detailed insights and metrics for @basd/search
npm install @basd/search
Typescript
Module System
Node Version
NPM Version
64.7
Supply Chain
78.5
Quality
72.6
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
859
Last Day
1
Last Week
2
Last Month
32
Last Year
345
MIT License
12 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Oct 01, 2023
Latest Version
0.0.5
Package Id
@basd/search@0.0.5
Unpacked Size
49.64 kB
Size
10.03 kB
File Count
14
NPM Version
8.19.4
Node Version
16.20.0
Published on
Dec 08, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-71.4%
2
Compared to previous week
Last Month
23.1%
32
Compared to previous month
Last Year
-32.9%
345
Compared to previous year
3
3
A powerful and flexible text search library for JavaScript that enables you to build a simple text search engine. It provides a set of classes to tokenize, parse, and interpret queries using a binary AST (Abstract Syntax Tree). The library supports various grouping operators (and/or/&/|) and any degree of parenthesis nesting.
Install the package with:
1npm install @basd/search
First, import the Search
library.
1import Search from '@basd/search'
or
1const Search = require('@basd/search')
Here's how to create a simple search evaluator and use it.
1const Search = require('@basd/search') 2 3const search = new Search() 4const evaluator = search.evaluator('apple AND orange') 5 6const result = evaluator('I have an apple and an orange.') 7// Returns true
Here's a basic example of how you can use @basd/search
to perform a text search:
1const { Tokenizer, Parser, Interpreter } = require('@basd/search') 2 3const query = 'apple AND orange OR pear' 4const tokenizer = new Tokenizer() 5const tokens = tokenizer.tokenize(query) 6 7const parser = new Parser(tokens) 8const ast = parser.parse() 9 10const interpreter = new Interpreter(ast) 11const result = interpreter.interpret('apple orange') // true
SearchFactory
Factory class to produce instances of Tokenizer, Parser, and Interpreter.
1const factory = new SearchFactory(registry)
createTokenizer(...args)
: Creates a SearchTokenizer
instance.createParser(...args)
: Creates a SearchParser
instance.createInterpreter(...args)
: Creates a SearchInterpreter
instance.SearchNormalizer
Normalizes text to be used in tokenization and interpretation.
1const normalizedText = SearchNormalizer.normalize('some text')
SearchTokenizer
Tokenizes the normalized query.
1const tokenizer = new SearchTokenizer() 2const tokens = tokenizer.tokenize('apple AND orange')
SearchParser
Parses the tokens into an AST.
1const parser = new SearchParser(tokens) 2const ast = parser.parse()
SearchInterpreter
Interprets the AST against a given text.
1const interpreter = new SearchInterpreter(ast) 2const result = interpreter.interpret('I have an apple.')
Search
The main class that combines all the functionalities.
1const search = new Search()
evaluator(needle)
: Returns an evaluator function for a given search query.evaluate(needle, haystack)
: Evaluates a search query against a given text.The library is designed to be easily extendable. You can extend SearchTokenizer
, SearchParser
, and SearchInterpreter
to add additional functionalities.
TextNormalizer
Normalizes text by removing punctuations, converting to uppercase, and replacing multiple spaces with a single space.
Tokenizer
Tokenizes a query into distinct elements such as words, operators, and parentheses.
Parser
Takes the tokens and turns them into a binary AST.
Interpreter
Takes the AST and matches a given text string against it.
Tokenizer.tokenize(query: string): Token[]
Takes a query string and returns an array of tokens.
Parser.parse(): ASTNode
Takes an array of tokens and returns a binary AST.
Interpreter.interpret(data: string): boolean
Takes a string of text and returns a boolean indicating whether it matches the AST.
In order to run the test suite, simply clone the repository and install its dependencies:
1git clone https://gitlab.com/frenware/framework/plaindb/search.git 2cd search 3npm install
To run the tests:
1npm test
Thank you! Please see our contributing guidelines for details.
If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!
Bitcoin (BTC):
1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF
Monero (XMR):
46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ
@basd/search is MIT licensed.
No vulnerabilities found.
No security vulnerabilities found.