{"id":23507363,"url":"https://github.com/simplyhexagonal/parse-search-string","last_synced_at":"2025-06-11T15:13:32.840Z","repository":{"id":71910331,"uuid":"446046064","full_name":"simplyhexagonal/parse-search-string","owner":"simplyhexagonal","description":"Parsing of search strings into optional, required, or forbidden phrases, groups, operators, and/or words","archived":false,"fork":false,"pushed_at":"2022-01-09T09:53:21.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-06T18:43:51.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplyhexagonal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-01-09T09:36:26.000Z","updated_at":"2022-01-09T09:53:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"471c13e7-d658-47f1-b282-be64c392e9ff","html_url":"https://github.com/simplyhexagonal/parse-search-string","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"a70d08a052cdbd822c67b94aaae4604aaf0bd1b1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fparse-search-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fparse-search-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fparse-search-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fparse-search-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplyhexagonal","download_url":"https://codeload.github.com/simplyhexagonal/parse-search-string/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fparse-search-string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259205268,"owners_count":22821255,"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-12-25T10:18:15.691Z","updated_at":"2025-06-11T15:13:32.792Z","avatar_url":"https://github.com/simplyhexagonal.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/jeanlescure","https://opencollective.com/simplyhexagonal"],"categories":[],"sub_categories":[],"readme":"# Parse Search String\n![Tests](https://github.com/simplyhexagonal/parse-search-string/workflows/tests/badge.svg)\n[![Try parse-search-string on RunKit](https://badge.runkitcdn.com/@simplyhexagonal/parse-search-string.svg)](https://npm.runkit.com/@simplyhexagonal/parse-search-string)\n\nFunction to parse search strings into useful search tokens grouped by optional, required, or forbidden: \n\n- quoted phrases (`\"this is a phrase\"`)\n- conjunction operators  (`AND`, `OR`)\n- parenthesis grouping (`(word AND \"phrase in a group\")`) (supports 2 levels of nesting)\n- required/forbidden flagging (`+word` or `-word` respectively) (can also be used to flag phrases and groups)\n\n## Open source notice\n\nThis project is open to updates by its users, [I](https://github.com/jeanlescure) ensure that PRs are relevant to the community.\nIn other words, if you find a bug or want a new feature, please help us by becoming one of the\n[contributors](#contributors-) ✌️ ! See the [contributing section](#contributing)\n\n## Like this module? ❤\n\nPlease consider:\n\n- [Buying me a coffee](https://www.buymeacoffee.com/jeanlescure) ☕\n- Supporting Simply Hexagonal on [Open Collective](https://opencollective.com/simplyhexagonal) 🏆\n- Starring this repo on [Github](https://github.com/simplyhexagonal/parse-search-string) 🌟\n\n## Install\n\n```sh\npnpm i @simplyhexagonal/parse-search-string\n\n# or\nyarn add @simplyhexagonal/parse-search-string\n\n# or\nnpm install @simplyhexagonal/parse-search-string\n```\n\n## Usage\n\n```ts\nimport parseSearchString from '@simplyhexagonal/parse-search-string';\n\nconst result = parseSearchString('\"Elon Musk\" AND +(Bitcoin OR Doge)');\n\nconsole.log(JSON.stringify(result, null, 2));\n\n// [\n//   {\n//     \"index\": 0,\n//     \"tokenType\": \"andOperation\",\n//     \"value\": \"AND\",\n//     \"children\": [\n//       {\n//         \"index\": 1,\n//         \"tokenType\": \"optionalPhrase\",\n//         \"value\": \"Elon Musk\",\n//         \"children\": []\n//       },\n//       {\n//         \"index\": 17,\n//         \"tokenType\": \"requiredGroup\",\n//         \"value\": \"(Bitcoin OR Doge)\",\n//         \"children\": [\n//           {\n//             \"index\": 18,\n//             \"tokenType\": \"orOperation\",\n//             \"value\": \"OR\",\n//             \"children\": [\n//               {\n//                 \"index\": 18,\n//                 \"tokenType\": \"optionalWord\",\n//                 \"value\": \"Bitcoin\",\n//                 \"children\": []\n//               },\n//               {\n//                 \"index\": 29,\n//                 \"tokenType\": \"optionalWord\",\n//                 \"value\": \"Doge\",\n//                 \"children\": []\n//               }\n//             ]\n//           }\n//         ]\n//       }\n//     ]\n//   }\n// ]\n```\n\nThe token object structure was designed to be human readable yet easy to transform into a `$search` aggregation query compatible with [MongoDB Query API](https://www.mongodb.com/atlas/search).\n\n## Inspired By\n\nFinancial Time's [n-search-parser](https://github.com/Financial-Times/n-search-parser) (npm module) which is in turn inspired by [Lucene query parser](https://github.com/thoward/lucene-query-parser.js) (module) and [Building a search query parser](https://tgvashworth.com/2016/06/27/twitter-search-query-parser.html) (article).\n\n## Contributing\n\nYes, thank you! This plugin is community-driven, most of its features are from different authors.\nPlease update the docs and tests and add your name to the `package.json` file.\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://jeanlescure.cr\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/3330339?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJean Lescure\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-jeanlescure\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/parse-search-string/commits?author=jeanlescure\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#userTesting-jeanlescure\" title=\"User Testing\"\u003e📓\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/parse-search-string/commits?author=jeanlescure\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"#example-jeanlescure\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/parse-search-string/commits?author=jeanlescure\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n\u003c/table\u003e\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## License\n\nCopyright (c) 2022-Present [Package Contributors](https://github.com/simplyhexagonal/parse-search-string/#contributors-).\u003cbr/\u003e\nLicensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Fparse-search-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplyhexagonal%2Fparse-search-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Fparse-search-string/lists"}