Here's the full-text search part of the code. First I have the function, then the call to it searching every file in the array $all_files. The important part is right up top on line 3.
function file_find($file, $phpfilename, $num_ands, $keywords_core, $keywords_boolean, $phpfilenames, $ascii_limit) {
$filetype = substr($file, -3, 3);
$fp = fopen($file, "r") or die ("unable to read");
$invpagecount = -1;
$stop = false;
$anynot = false;
$anyor = false;
$num_ands_found = 0;
$remaining = $keywords_core;
$remaining_relations = $keywords_boolean;
$remaining_ascii = $ascii_limit;
$ftsearch_results = array();
while (!$stop) {
//get line of text
$line = strtolower(fgets($fp));
if ($line == false) {$stop = true;}
else {
//if inventory file, keep track of which page
if ($filetype == 'xml') {
if (substr($line, 0, 5) == '<page') {
$invpagecount++;
}
}
//find keywords in line, add filename to array
foreach ($remaining as $keyword) {
$indexOf = array_search($keyword, $remaining);
$operator = $remaining_relations[$indexOf];
$ascii_ceiling = $remaining_ascii[$indexOf];
$beginword = strpos($line,$keyword);
$wordlength = strlen($keyword);
//determine ASCII limits
$prelim = 65;
$postlim = 65;
//if asterisk in front, allow all characters
if ($ascii_ceiling == 1) {
$prelim = 255;
}
//if asterisk on end, allow all characters
else if ($ascii_ceiling == 2) {
$postlim = 255;
}
//if "not" word in line, stop loop and flag "not"
if ($operator == '1') {
if ($beginword) {
$pre = ord(substr($line, $beginword-1, 1));
$post = ord(substr($line, $beginword+$wordlength, 1));
if ($pre < $prelim && $post < $postlim) {
$anynot = true;
$stop = true;
}
}
}
//if "and" word in line, remove from remaining terms and add to counter
//this is necessary because ALL and words need to be present in file, must search for others & counter must match total number
else if ($operator == '2') {
if($beginword) {
$pre = ord(substr($line, $beginword-1, 1));
$post = ord(substr($line, $beginword+$wordlength, 1));
if ($pre < $prelim && $post < $postlim) {
$num_ands_found++;
$invmarker = $invpagecount;
unset($remaining[$indexOf]);
array_values($remaining);
unset($remaining_relations[$indexOf]);
array_values($remaining_relations);
unset($remaining_ascii[$indexOf]);
array_values($remaining_ascii);
}
}
}
//if "or" word in line, flag "or"
else if ($operator == '3') {
if ($beginword) {
$pre = ord(substr($line, $beginword-1, 1));
$post = ord(substr($line, $beginword+$wordlength, 1));
if ($pre < $prelim && $post < $postlim) {
$anyor = true;
$invmarker = $invpagecount;
}
}
}
}
}
}
fclose($fp);
if ($anynot == false && $anyor == true && $num_ands_found == $num_ands) {
$ftsearch_results[$phpfilename] = $invmarker;
}
array_unique($ftsearch_results);
return $ftsearch_results;
}
$allftsearch_results = array();
//Run file_find on descriptions and add file names to allftsearch_results
for ($i = 0; $i <= count($all_files); $i++) {
$description_search_result = file_find('mss/'.$all_files[$i], $phpfilenames[$i], $num_ands, $keywords_core, $keywords_boolean, $phpfilenames, $ascii_limit);
foreach ($description_search_result as $keyfilename => $invpagevalue) array_push($allftsearch_results, $keyfilename);
}