$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 ($_token == 'exact' AND !$_inside_quote) { $_last_boolean = '++'; } else if ($_token == 'or' AND !$_inside_quote) { $_last_boolean = '*'; } else if ($_token == '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); $_q_buff .= "\"$_phrase\" "; // reset $_phrase = ''; } else { $_phrase .= str_replace('"', '', $_token).' '; // we continue to the next loop and concatenating words $_token = strtok(" \n\t"); continue; } } else { if ($_current_field == $_previous_field) { $_q_buff .= "$_token "; } else if (($_current_field != $_previous_field) && !empty($_q_buff)) { $_array_queries[] = array('f' => $_previous_field, 'b' => $_last_boolean, 'q' => trim($_q_buff)); $_q_buff = "$_token "; } else { $_array_queries[] = array('f' => $_current_field, 'b' => $_last_boolean, 'q' => trim($_token)); $_q_buff = ''; } } // 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; } ?>