$int_max_words) { break; } $_token = trim($_token); // check for stopwords if (in_array($_token, $arr_stop_words) AND !$_inside_quote) { // do nothing $_token = strtok(" \n\t"); continue; } // check boolean mode // if (in_array($_token, array('exact', 'and', 'or', 'not'))) { if (preg_match('@\b(exact|and|or|not)\b@i', $_token)) { $_bool = strtolower($_token); if ($_bool == 'exact' AND !$_inside_quote) { $_last_boolean = '++'; } else if ($_bool == 'or' AND !$_inside_quote) { $_last_boolean = '*'; } else if ($_bool == 'not' AND !$_inside_quote) { $_last_boolean = '-'; } else { $_last_boolean = '+'; } // we continue to the next loop $_token = strtok(" \n\t"); continue; } // check for current field foreach ($arr_searcheable_fields as $_search_field) { if ((strpos($_token, $_search_field.'=') === 0) AND !$_inside_quote) { $_current_field = $_search_field; $_token = str_replace($_search_field.'=', '', $_token); if ($_word_count > 0) { $_array_queries[] = array('f' => 'boolean', 'b' => $_last_boolean); } $_last_boolean = '+'; } } // check if we are inside quotes if (strpos($_token, '"') === 0) { $_inside_quote = true; // remove the first quote $_token = substr_replace($_token, '', 0, 1); } if ($_inside_quote) { if (strpos($_token, '"') === strlen($_token)-1) { $_inside_quote = false; $_phrase .= str_replace('"', '', $_token); $_array_queries[] = array('f' => $_current_field, 'b' => $_last_boolean, 'q' => $_phrase, 'is_phrase' => 1); // reset $_phrase = ''; } else { $_phrase .= str_replace('"', '', $_token).' '; // we continue to the next loop and concatenating words $_token = strtok(" \n\t"); continue; } } else { if (stripos($_token, '(') === true) { $_array_queries[] = array('f' => 'opengroup', 'b' => $_last_boolean); } else if (stripos($_token, ')') === true) { $_array_queries[] = array('f' => 'closegroup', 'b' => $_last_boolean); } else { $_array_queries[] = array('f' => $_current_field, 'b' => $_last_boolean, 'q' => $_token); } } // set previous field flag $_previous_field = $_current_field; // re-toke $_token = strtok(" \n\t"); // add word counter $_word_count++; } $_array_queries[] = array('f' => 'cql_end'); return $_array_queries; }