{"id":18573905,"url":"https://github.com/basedwon/search","last_synced_at":"2025-10-20T06:30:20.352Z","repository":{"id":197516440,"uuid":"698803430","full_name":"basedwon/search","owner":"basedwon","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-08T02:43:37.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T18:15:54.462Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basedwon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-01T02:41:25.000Z","updated_at":"2023-10-01T02:41:40.000Z","dependencies_parsed_at":"2023-11-07T12:29:33.023Z","dependency_job_id":"15221654-4c84-465a-a290-b4fdbe9437d1","html_url":"https://github.com/basedwon/search","commit_stats":null,"previous_names":["basedwon/search"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basedwon","download_url":"https://codeload.github.com/basedwon/search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442348,"owners_count":22071863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T23:13:21.677Z","updated_at":"2025-10-20T06:30:15.303Z","avatar_url":"https://github.com/basedwon.png","language":"JavaScript","readme":"# Search\n\n[![npm](https://img.shields.io/npm/v/@basd/search?style=flat\u0026logo=npm)](https://www.npmjs.com/package/@basd/search)\n[![pipeline](https://gitlab.com/frenware/framework/plaindb/search/badges/master/pipeline.svg)](https://gitlab.com/frenware/framework/plaindb/search/-/pipelines)\n[![license](https://img.shields.io/npm/l/@basd/search)](https://gitlab.com/frenware/framework/plaindb/search/-/blob/master/LICENSE)\n[![downloads](https://img.shields.io/npm/dw/@basd/search)](https://www.npmjs.com/package/@basd/search) \n\n[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab\u0026color=%23383a40)](https://gitlab.com/frenware/framework/plaindb/search)\n[![Github](https://img.shields.io/badge/Github%20-%20?logo=github\u0026color=%23383a40)](https://github.com/basedwon/search)\n[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter\u0026color=%23383a40)](https://twitter.com/basdwon)\n[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord\u0026color=%23383a40)](https://discordapp.com/users/basedwon)\n\nA 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/\u0026/|) and any degree of parenthesis nesting.\n\n## Features\n- Tokenization of search queries\n- Parsing to Abstract Syntax Trees (AST)\n- Interpretation to evaluate search queries against text\n- Normalization of text and query strings\n- Abstract factory for easy extension\n\n## Installation\n\nInstall the package with:\n\n```bash\nnpm install @basd/search\n```\n\n## Usage\n\nFirst, import the `Search` library.\n\n```js\nimport Search from '@basd/search'\n```\nor\n```js\nconst Search = require('@basd/search')\n```\n\n## Quick Start\n\nHere's how to create a simple search evaluator and use it.\n\n```js\nconst Search = require('@basd/search')\n\nconst search = new Search()\nconst evaluator = search.evaluator('apple AND orange')\n\nconst result = evaluator('I have an apple and an orange.')\n// Returns true\n```\n\nHere's a basic example of how you can use `@basd/search` to perform a text search:\n\n```js\nconst { Tokenizer, Parser, Interpreter } = require('@basd/search')\n\nconst query = 'apple AND orange OR pear'\nconst tokenizer = new Tokenizer()\nconst tokens = tokenizer.tokenize(query)\n\nconst parser = new Parser(tokens)\nconst ast = parser.parse()\n\nconst interpreter = new Interpreter(ast)\nconst result = interpreter.interpret('apple orange') // true\n```\n\n## Documentation\n\n- [API Reference](/docs/api.md)\n\n## API Reference\n\n### Classes\n\n#### `SearchFactory`\nFactory class to produce instances of Tokenizer, Parser, and Interpreter.\n\n```js\nconst factory = new SearchFactory(registry)\n```\n\n##### Methods\n- `createTokenizer(...args)`: Creates a `SearchTokenizer` instance.\n- `createParser(...args)`: Creates a `SearchParser` instance.\n- `createInterpreter(...args)`: Creates a `SearchInterpreter` instance.\n\n#### `SearchNormalizer`\nNormalizes text to be used in tokenization and interpretation.\n\n```js\nconst normalizedText = SearchNormalizer.normalize('some text')\n```\n\n#### `SearchTokenizer`\nTokenizes the normalized query.\n\n```js\nconst tokenizer = new SearchTokenizer()\nconst tokens = tokenizer.tokenize('apple AND orange')\n```\n\n#### `SearchParser`\nParses the tokens into an AST.\n\n```js\nconst parser = new SearchParser(tokens)\nconst ast = parser.parse()\n```\n\n#### `SearchInterpreter`\nInterprets the AST against a given text.\n\n```js\nconst interpreter = new SearchInterpreter(ast)\nconst result = interpreter.interpret('I have an apple.')\n```\n\n#### `Search`\nThe main class that combines all the functionalities.\n\n```js\nconst search = new Search()\n```\n\n##### Methods\n- `evaluator(needle)`: Returns an evaluator function for a given search query.\n- `evaluate(needle, haystack)`: Evaluates a search query against a given text.\n\n## Extending the Library\n\nThe library is designed to be easily extendable. You can extend `SearchTokenizer`, `SearchParser`, and `SearchInterpreter` to add additional functionalities.\n\n### Classes\n\n#### `TextNormalizer`\n\nNormalizes text by removing punctuations, converting to uppercase, and replacing multiple spaces with a single space.\n\n#### `Tokenizer`\n\nTokenizes a query into distinct elements such as words, operators, and parentheses.\n\n#### `Parser`\n\nTakes the tokens and turns them into a binary AST.\n\n#### `Interpreter`\n\nTakes the AST and matches a given text string against it.\n\n## API Reference\n\n### `Tokenizer.tokenize(query: string): Token[]`\n\nTakes a query string and returns an array of tokens.\n\n### `Parser.parse(): ASTNode`\n\nTakes an array of tokens and returns a binary AST.\n\n### `Interpreter.interpret(data: string): boolean`\n\nTakes a string of text and returns a boolean indicating whether it matches the AST.\n\n## Tests\n\nIn order to run the test suite, simply clone the repository and install its dependencies:\n\n```bash\ngit clone https://gitlab.com/frenware/framework/plaindb/search.git\ncd search\nnpm install\n```\n\nTo run the tests:\n\n```bash\nnpm test\n```\n\n## Contributing\n\nThank you! Please see our [contributing guidelines](/docs/contributing.md) for details.\n\n## Donations\n\nIf 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!\n\n**Bitcoin (BTC):**\n```\n1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF\n```\n\n**Monero (XMR):**\n```\n46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ\n```\n\n## License\n\n@basd/search is [MIT licensed](https://gitlab.com/frenware/framework/plaindb/search/-/blob/master/LICENSE).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasedwon%2Fsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fsearch/lists"}