|
| 1 | +# pecee/boolean-query-parser |
| 2 | + |
| 3 | +Convert a boolean search query into a query that is compatible with a fulltext search. |
| 4 | + |
| 5 | +### Notes |
| 6 | + |
| 7 | +This library is a maintained fork of the original project "BooleanSearchParser" created by DuncanOglethat, [available here](https://github.com/DuncanOgle/BooleanSearchParser). |
| 8 | + |
| 9 | +The goal of this project is to iron out bugs, optimise the code, add new features and make it compatible with future versions of PHP. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- PHP 7.1 or higher |
| 14 | + |
| 15 | +### Installation |
| 16 | + |
| 17 | +``` |
| 18 | +composer require pecee/boolean-query-parser |
| 19 | +``` |
| 20 | + |
| 21 | +### Parsing a query |
| 22 | + |
| 23 | +```php |
| 24 | +$parser = new \Pecee\BooleanQueryParser\BooleanQueryParser(); |
| 25 | + |
| 26 | +$formattedQuery = $parser->parse('ict OR (technology AND bob)'); |
| 27 | +``` |
| 28 | + |
| 29 | +**Output** |
| 30 | + |
| 31 | +``` |
| 32 | +ict (+technology +bob) |
| 33 | +``` |
| 34 | + |
| 35 | +### Order |
| 36 | + |
| 37 | +Order and brackets are important, more often than not OR logic takes priority |
| 38 | + |
| 39 | +`sales OR finance AND manager` will become `sales finance +manager` and not `sales +finance +manager` |
| 40 | + |
| 41 | +## Examples |
| 42 | + |
| 43 | +|Input|Output| |
| 44 | +|-----|------| |
| 45 | +|`ict` | `+ict`| |
| 46 | +|`ict it` | `+ict +it`| |
| 47 | +|`ict OR it` | `ict it`| |
| 48 | +|`NOT ict` | `-ict`| |
| 49 | +|`it NOT ict` | `+it -ict`| |
| 50 | +|`web AND (ict OR it)` | `+web +(ict it)`| |
| 51 | +|`ict OR (it AND web)` | `ict (+it +web)`| |
| 52 | +|`ict NOT (ict AND it AND web)` | `+ict -(+ict +it +web)`| |
| 53 | +|`php OR (NOT web NOT embedded ict OR it)` | `php (-web -embedded ict it)`| |
| 54 | +|`(web OR embedded) (ict OR it)` | `+(web embedded) +(ict it)`| |
| 55 | +|`develop AND (web OR (ict AND php))` | `+develop +(web (+ict +php))`| |
| 56 | +|`"ict` | `null `| |
| 57 | +|`"ict OR it"` | `+"ict OR it"`| |
| 58 | + |
| 59 | +## Advanced examples |
| 60 | +|Input|Output| |
| 61 | +|-----|------| |
| 62 | +`"business development" or "it sales" and (danish or dutch or italian or denmark or holland or netherlands or italy)` | `"business development" "it sales" +(danish dutch italian denmark holland netherlands italy)` |
| 63 | +`(procurement or buying or purchasing) and (marine or sea) and (engineering or engineer)` | `+(procurement buying purchasing) +(marine sea) +(engineering engineer)` |
| 64 | + |
| 65 | +## Licence |
| 66 | + |
| 67 | +Licensed under the MIT licence. |
| 68 | + |
| 69 | +### The MIT License (MIT) |
| 70 | + |
| 71 | +Copyright (c) 2018 Simon Sessingø / pecee-boolean-query-parser |
| 72 | + |
| 73 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 74 | +of this software and associated documentation files (the "Software"), to deal |
| 75 | +in the Software without restriction, including without limitation the rights |
| 76 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 77 | +copies of the Software, and to permit persons to whom the Software is |
| 78 | +furnished to do so, subject to the following conditions: |
| 79 | + |
| 80 | +The above copyright notice and this permission notice shall be included in all |
| 81 | +copies or substantial portions of the Software. |
| 82 | + |
| 83 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 84 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 85 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 86 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 87 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 88 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 89 | +SOFTWARE. |
0 commit comments