Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-file keyword search results

Status
Not open for further replies.

artisst

Programmer
Apr 24, 2004
18
US
First, thanks for your response. I have not not been able to successfully integrate it into my code. I have however been able to successfully open both files, read them simultaneously and print out independent file content results (keywords not in SIDX, are in SIDX2 by design). I now need to be able to regain the keyword search results in @skeyw, and split them into 2 return results. One will be inserted the html placeholder %%searchresults%% and the other in premiumresults:

Code:
	$main_template =~ s/%%keywords%%/$fields{'keywords'}/g;
	$main_template =~ s/%%searcresults%%/$pitem/g;
	
	$main_template =~ s/%%keywords%%/$fields{'keywords'}/g;
	$main_template =~ s/%%premiumresults%%/$pitem/g;

print "Content-type: text/html\n\n";

$main_template = tseek::insert_tmpl_includes($main_template);  
print "$main_template";
exit;

Here is where I do the search:

Code:
sub normal_search
{

### PERFORM SEARCH

$search_line = $fields{'keywords'};

$icnt = 0;
$toadk = "";

(@skeyw) = split(/ /,$search_line);


$nrkeywords = 0;
foreach $item (@skeyw){$nrkeywords++;}

open (SIDX, "$data_dir/search.idx");
open (SIDX2, "$data_dir/search2.idx");



 if ($file_locking ne "No"){flock (SIDX, LOCK_SH) or die "Can't set lock for file: $data_dir/search.idx, $data_dir/search2.idx $!\n";}
	while($line3 = <SIDX>)
	{

	$line2 = <SIDX2>;
	$sline = "${line2}${line3}";
	
	
	foreach $kwr (@skeyw)
		{

		if (($sline =~ /$kwr/i) and ($kwr ne "")) 
		{
					
			$toadk = "true";
			}
			
		}

		if ($toadk eq "true")
		
				
			{
			$resultline[$icnt] = "${line2}";
			$premium_resultline[$icnt] = "${line3}";

			$toadk = false;
			$icnt++;
			}

	}
	
	
	 #if ($file_locking ne "No"){flock (CIT, LOCK_UN);}
close (SIDX);
close (SIDX2);
}

and here is where I need to split the keyword search results from both files that are still contained in @skeyw. Search results from <SIDX> assigned to ($search_line) = @_;
and the search results from <SIDX2> assigned to ($premium_search_line) = @_;


Code:
sub get_search_ready
{
my ($search_line) = @_;

$reline = $search_line;

$reline =~ s/[+\[\]()*^.\$?\\~<>;]//g;

return ($reline);
}

sub get_search_ready2
{
my ($premium_search_line) = ${line2};

$premium_reline = $premium_search_line;

$premium_reline =~ s/[+\[\]()*^.\$?\\~<>;]//g;

return ($premium_reline);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top