Gossamer Forum
Home : General : Perl Programming :

Searching Multiple Databases

Quote Reply
Searching Multiple Databases
I am using a hacked version of Xav Indexed Search script and I was wondering how to search multiple databases. (I posted a comment about this in Xav Search Topic, but I thought I should create a new Topic that may be applicable to other CGI programs.)

Anyway, I would like to search multiple ASCII flat files that have the same structure.

Here are the codes that I have in place:

Code:
open (ALLFILE, "<$Index_File") | | &Fatal;
open (SECFILE, ">$Second_File")| | &Fatal;
foreach $LINE (<ALLFILE, SECFILE> ) {
******************************************
Relevance Codes
******************************************
}
close(ALLFILE);
close(SECFILE);

NOTE: I did not think it was necessary to post the relevancy codes I have between the open and close codes.

Anyone know how I can get this to work? When I search, the second file is ignored and I only get results from the first data file.

Smile

TIA

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 08, 1999).]

[This message has been edited by Eliot (edited July 08, 1999).]
Quote Reply
Re: Searching Multiple Databases In reply to
Code (slightly edited) from latest XAV script.

Code:
my (%IndexFile, %BaseDir, %BaseURL, %Exclude);
my $RealmFile = 'realms'; # | delimited database of indexes


#### this loads realm data formatted as $fields[] , %IndexFile = [1]
sub LoadRealms {
#how did he open/read/close realms?
foreach (Lines($RealmFile, 1)) {
my @Fields = split(m!\|!);
next unless ($Fields[0] && $Fields[1]);
my $Realm = $Fields[0];
$IndexFile{$Realm} = $Fields[1];
$BaseDir{$Realm} = $Fields[2] | | '';
$BaseURL{$Realm} = $Fields[3] | | '';
$Exclude{$Realm} = $Fields[4] | | '';
}
}



#### Search
# &SearchIndexFile($IndexFile{$Realm}) = specific realm {$Realm}
# &SearchIndexFile($IndexFile{$_}) = all realms {$_}
# If Realm is specific, search it - otherwise search all:
# simplified to just index files
if (($Realm) && ($Realm ne 'All')) {
&SearchIndexFile($IndexFile{$Realm});
}

else {
foreach (keys %IndexFile) {
&SearchIndexFile($IndexFile{$_});
}
}



sub SearchIndexFile {
my ($IndexFile) = (@_);
unless (open(ALLFILE,"<$IndexFile")) {
print "<!--foo-->\n" if ($AllowDebug == 1);
return 0;
}
Record: while (<ALLFILE> ) {
# etc.
}
}

[This message has been edited by Dave (edited July 08, 1999).]
Quote Reply
Re: Searching Multiple Databases In reply to
Thanks, Dave.

Very confusing to say the least...Still looks like I will need to work on this some more.

But, thanks again for the effort. I really appreciate it.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us