{"id":16876408,"url":"https://github.com/staktrace/query-parser","last_synced_at":"2025-08-22T12:40:19.142Z","repository":{"id":37353099,"uuid":"386809042","full_name":"staktrace/query-parser","owner":"staktrace","description":"A search query parser","archived":false,"fork":false,"pushed_at":"2022-06-23T19:57:28.000Z","size":23,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-16T17:56:01.797Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/staktrace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-17T01:46:00.000Z","updated_at":"2024-06-29T15:36:16.000Z","dependencies_parsed_at":"2022-08-29T09:31:00.561Z","dependency_job_id":null,"html_url":"https://github.com/staktrace/query-parser","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/staktrace/query-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staktrace%2Fquery-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staktrace%2Fquery-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staktrace%2Fquery-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staktrace%2Fquery-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/staktrace","download_url":"https://codeload.github.com/staktrace/query-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staktrace%2Fquery-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271641312,"owners_count":24795348,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-13T15:39:20.986Z","updated_at":"2025-08-22T12:40:19.105Z","avatar_url":"https://github.com/staktrace.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"query-parser\n===\n\nA simple parser for search queries. This takes a string like `from:foo -subject:'a long subject \\u00270c' baz` and returns it in a structured format:\n\n```\nQuery {\n    raw_query: \"from:foo -subject:\\'a long subject \\\\u00270c\\' baz\",\n    terms: [\n        Term { negated: false, key: Some(\"from\"), value: Simple(\"foo\") },\n        Term { negated: true, key: Some(\"subject\"), value: Simple(\"a long subject ✌\") },\n        Term { negated: false, key: None, value: Simple(\"baz\") }\n    ]\n}\n```\n\nThe primary entry point for this library are the following functions:\n\n```rust\n    parse(\u0026str) -\u003e Query;\n    parse_with_options(\u0026str, \u0026ParseOptions) -\u003e Query;\n```\n\nRefer to the [full documentation](https://docs.rs/query-parser/) for details.\n\n## Automatic Parse Correction ##\n\nThe parser can optionally attempt to correct query syntax that looks like it may\ninvolve typos or a misunderstanding of quoting rules.\n\nCorrection is enabled by specifying the number of correction passes to perform.\nThe parser operates in a single-pass without back-tracking or running multiple\nspeculative passes in parallel.  Because some correction operations like\nescaping a quote character result in a divergence between how the correction\nwould parse and the current parse is occurring, each correction pass must stop\ncorrecting once it makes a diverging correction.\n\n### Correction Model ###\n\nCorrection is based around the idea that best practice for a query will have\nspaces between all terms.  This assumption helps create more edit distance\nbetween \"best practice\" queries.  Specifically, although the parser will parse\n`'whoopsi'e` as 2 terms, our best practice guidance means that the best practice\nformulations of this query would look like:\n- corrected best practice: `'whoopsie'`\n- alternate best practice: `'whoopsi' e` or `'whoopsi' 'e'`\n\nWe additionally add the assumption to our model that typos where characters are\ntransposed are more likely than accidental repeated keypresses or spurious\nkeypresses.\n\nNo attempt is made to support correction of key or value term string values.\nThis would require the parser to have dictionaries available and that is beyond\nthe scope of the parser.\n\n### Implemented Corrections ###\n\nThe following corrections are currently implemented and tested.  More can be\nadded if they are consistent with the correction model described above and do\nnot substantially change the complexity of the parser.\n\n- Transposition of the last character in a quoted string with the quote.  For\n  example, `'typ'o` will be corrected to `'typo'`.\n  - This can run into problems with contractions where the apostrophe is not\n    escaped and single-quotes are in use.  If your queries involve a lot of\n    prose, it may be advisable to favor an interactive query building model that\n    can provide interactive visual feedback about term and phrase boundaries.\n- Failure to quote inside a quoted string will result in the quotes being\n  escaped.  For example, `'abc'de'fgh'` will have the interior quotes escaped\n  as long as correction_passes is at least 2.  When this correction is made, it\n  causes a parser divergence, so only a single escaping correction can happen\n  per correction pass.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstaktrace%2Fquery-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstaktrace%2Fquery-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstaktrace%2Fquery-parser/lists"}