9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/grauphel.htm
14 namespace OCA\Grauphel\Search;
17 * User search query parser
21 * @author Christian Weiske <cweiske@cweiske.de>
22 * @copyright 2014 Christian Weiske
23 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24 * @version Release: @package_version@
25 * @link http://cweiske.de/grauphel.htm
30 * Splits the user's query string up into several keywords
31 * that all have to be within or not appear in the note (AND, NOT).
33 * Split by space, quotes are supported:
35 * -> searches for notes that contain "foo" and "bar"
37 * -> searches for notes that contain "foo" and "bar baz"
39 * Exclusion is supported:
41 * -> search for notes that contain "foo" but not "bar"
43 * -> search for notes that contain "foo" but not "bar baz"
45 * @param string $query User-given query string
47 * @return array Array of keyword arrays, grouped by "AND" and "NOT"
49 public function parse($query)
52 $query = trim($query);
62 foreach (str_split($query) as $char) {
63 if ($char == '"' || $char == '\'') {
64 if ($chQuote === null) {
68 } else if ($char == $chQuote) {
70 if (strlen($curKeyword)) {
71 $keywords[$group][] = $curKeyword;
77 } else if ($char == ' ' && $chQuote === null) {
78 if (strlen($curKeyword)) {
79 $keywords[$group][] = $curKeyword;
84 } else if ($char == '+' || $char == '-' && $curKeyword == '') {
85 $group = $groupMap[$char];
91 if (strlen($curKeyword)) {
92 $keywords[$group][] = $curKeyword;