{"id":17042129,"url":"https://github.com/bluem/searchstringparser","last_synced_at":"2025-04-12T14:42:02.969Z","repository":{"id":62495399,"uuid":"41305775","full_name":"BlueM/searchstringparser","owner":"BlueM","description":"Library for parsing search strings","archived":false,"fork":false,"pushed_at":"2020-08-15T05:44:51.000Z","size":28,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T04:17:17.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/BlueM.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":"2015-08-24T13:50:47.000Z","updated_at":"2024-06-11T03:39:07.000Z","dependencies_parsed_at":"2022-11-02T11:31:23.982Z","dependency_job_id":null,"html_url":"https://github.com/BlueM/searchstringparser","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueM%2Fsearchstringparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueM%2Fsearchstringparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueM%2Fsearchstringparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueM%2Fsearchstringparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlueM","download_url":"https://codeload.github.com/BlueM/searchstringparser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248583005,"owners_count":21128491,"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-10-14T09:15:09.034Z","updated_at":"2025-04-12T14:42:02.945Z","avatar_url":"https://github.com/BlueM.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![SensioLabsInsight](https://insight.sensiolabs.com/projects/2dc0e9b6-2357-40bd-a56b-9a8dade3408f/mini.png)](https://insight.sensiolabs.com/projects/2dc0e9b6-2357-40bd-a56b-9a8dade3408f)\n[![Build Status](https://travis-ci.org/BlueM/searchstringparser.svg?branch=master)](https://travis-ci.org/BlueM/searchstringparser)\n\nSearchstringParser Overview\n===========================\n\nWhat is it?\n--------------\nSearchstringParser is a library for PHP 5.3 or higher which will take a “typical” search-engine-like search string and split it into parts. It supports phrases, required, optional and excluded terms/phrases by using `+`, `-`, `AND`, `NOT` and `OR`.\n\nIf you use a search engine like Apache Solr which does the parsing itself, you may not need a library such as this. But in cases where you need switchable search backends but still have a consistent search syntax or where you simply use your SQL database’s fulltext search features, it provides simple and easy parsing. Equally, even when using a software such as Solr, it can be handy to control what is passed to Solr, for instance to optimize the search syntax (example: by setting the `mm` parameter depending on the number of optional terms).\n\n\nInstallation\n------------\nThe preferred way to install this library is through [Composer](https://getcomposer.org). For this, add `\"bluem/searchstringparser\": \"~2.0\"` to the requirements in your `composer.json` file. As this library uses [semantic versioning](http://semver.org), you will get fixes and feature additions when running `composer update`, but not changes which break the API.\n\nAlternatively, you can clone the repository using git or download a tagged release.\n\n\nSupported Syntax\n----------------\n\n* A term which is prefixed by `+` is regarded as required. Example: `+word`.\n* When there is an `AND` between two terms, both are regarded as required. Example: `Hello AND World`.\n* A term which is prefixed by `-` is regarded as excluded. Example: `-word`\n* A term which is preceded by `NOT` is regarded as excluded. Example: `NOT word`\n* When there is an `OR` between two terms, both are regarded as optional. Example: `Hello OR World`.\n* Phrases can be specified using double quotes. Double quotes inside a phrase can be escaped using a backslash. Example: `\"my \\\" phrase\"`.\n* Everything said above regarding `+`, `-`, `AND`, `OR`, `NOT` applies to phrases as well.\n\nAny term to which none of above rules applies, is by default regarded as an optional term . This can be changed by passing `array('defaultOperator' =\u003e SearchstringParser:SYMBOL_AND)` as argument 2 to `SearchstringParser`’s constructor to make such terms required.\n\nExamples:\n\n* `Hello World` ➔ Optional terms “Hello” and “World”, no required or excluded terms\n* `Hello World -foobar` ➜ Optional terms “Hello” and “World”, excluded term “foobar”, no required terms (Equivalent to: `Hello World NOT foobar`)\n* `+\"search string parser\" \"PHP 5.6\" OR \"PHP 5.3\" NOT \"PHP 4\" NOT C# -C++ C` ➔ Required phrase “search string parser”, optional phrases “PHP 5.6” and “PHP 5.3”, excluded phrases/terms “PHP 4”, “C#” and “C++” and skipped term “C” (which is shorter than the default minimum length of 2 characters)\n\nExample with `array('defaultOperator' =\u003e SearchstringParser:SYMBOL_AND)`:\n* `Hello World -foobar` ➜ Required terms “Hello” and “World”, excluded term “foobar”, no optional terms\n\n\nUsage\n========\n```php\n$search = new BlueM\\SearchstringParser('Your AND string long OR short NOT \"exclude this phrase\" X');\n\n$search-\u003egetAndTerms();     // array('your', 'string')\n$search-\u003egetOrTerms();      // array('long', 'short')\n$search-\u003egetNotTerms();     // array('exclude this phrase')\n$search-\u003egetSkippedTerms(); // array('X')\n```\n\nChanging the minimum length\n---------------------------\nSimply pass the length to the constructor:\n\n```php\n$search = new BlueM\\SearchstringParser('...', array('minlength' =\u003e 3));\n```\n\n\nDealing with errors\n---------------------------\nThe following errors might occur:\n\n* A phrase is opened using `\"`, but not closed\n* “NOT” is used as last term\n* “OR” is used as first or last term\n* “AND” is used as first or last term\n* “OR” is preceded or followed by an excluded term/phrase\n* “AND” is preceded or followed by an excluded term/phrase\n* “NOT” is followed by a term prefixed with “+”\n\nThe default behaviour is to not throw exceptions, but to make the best out of the situation. (See unit tests or Testdox output for details.) SearchstringParser will still collect exceptions, so if you want to provide hints to the user, you can do that by getting them via method `getExceptions()`. As `SearchstringParser` throws different exceptions depending on the type of problem, you can nicely handle (or ignore) the errors separately, for example by performing `instanceof` checks.\n\n\nAuthor \u0026 License\n====================\nThis code was written by Carsten Blüm ([www.bluem.net](http://www.bluem.net)) and licensed under the BSD 2-Clause license.\n\n\nChanges from earlier versions\n=============================\n\nFrom 2.0.3 to 2.0.4\n-----------------\n* Fix namespace issues in exception classes\n* Add PHPUnit as dev-dependency (tests were present, but dependency was missing)\n\nFrom 2.0.2 to 2.0.3\n-----------------\n* Update in Readme\n\nFrom 2.0.1 to 2.0.2\n-----------------\n* Use PSR-4 instead of PSR-0\n\nFrom 2.0 to 2.0.1\n-----------------\n* HHVM compatibility\n\nFrom 1.0.1 to 2.0\n-----------------\n* API is unchanged, but the semantics have changed. Versions below 2 behaved as if `defaultOperator` (introduced with 2.0) was set to `SearchstringParser:SYMBOL_AND`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluem%2Fsearchstringparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluem%2Fsearchstringparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluem%2Fsearchstringparser/lists"}