Gossamer Forum
Home : Products : DBMan : Customization :

search multiple databases (revisited))

Quote Reply
search multiple databases (revisited))
Hi, all. I know there have been alot of threads regarding the ability to search through multiple databases. I have been reading all of them.

However, I would like to ask if perhaps a simple search would be possible. I have about 4 databases all have a different number of fields. But their is one common field called "Name".

I do not believe that my databases fit into the category of relational databases because they are not related to one another at all.

I was wondering how you could use the search query section to loop one by one through each of the databases looking for the "Name" and displaying the rest of the fields of each database along with it.

To make things easier, I should specify that the search query is the only thing I wish to modify. The databases are premade and do not change, therefore there would be no need to modify the add_records and modify_records section.

I assume in the query section or in the view_records section, I would first have to 'define' the first database, then perform the search, 'define' the second database, and perform the search, etc. They the results would be displayed.

I had read on one of the posts by JPDeni, (I can't seem to find it now), that all of the results of the searches would have to be displayed on one page. That's no problem for me.

My question is where would be the best section of perform the search, from the view_records in db.cgi or the view_records in the html.pl
Then how exactly would you define the fields of each database, and then place a call to the query with the "Name" search string. and loop again to the next database.
I hope I have made things clear of what I'm trying to do
--------------------------
A second option I was thinking of was have check boxes for the search, then seaching each database specified.
I saw a post that discussed this option using javascript, however, it opened up a new browser window for each of the databases, something I wish to avoid.

In this second option of checkboxes would it be possible to search through the first database and and the bottom of the results page have a button that states "Click to search your next chosen database" and so on, until all the selected databases have been queried and displayed.

----------

phew, I hope I explained my situation. And looking forward for any input or code (yes, the code would be great :) on either of the two desired options for my simple(?) multiple database search.


Thank you
Trev R

Quote Reply
Re: search multiple databases (revisited)) In reply to
I'm not sure if these references will help, but they might:

http://www.gossamer-threads/p/002522.html
Topic: double search output

An example of using radio button to display which database to search.

Keyword Search multiple databases (static page)

This will allow users to search by keyword in one or all the databases. Note this is for default users. This sample form is for use on a static html page.

Replace value= to the names of your database files (.db)
Then rename your title for each radio button.

<CENTER><FORM ACTION="/cgi-bin/default.cgi" method="GET">
<INPUT TYPE=hidden name="uid" value="default">
<B>Keyword Search</B><BR>
<INPUT TYPE="text" name="keyword">
<INPUT TYPE="radio" NAME="db" value="Name of Database1"> Database One
<INPUT TYPE="radio" NAME="db" value="Name of Database2"> Database Two
<INPUT TYPE="radio" NAME="db" value="Name of Database3"> Database Three</FORM></CENTER>

I know i'm a little behind in updating the FAQ noted below, but you may find more option by looking under "Search" and "multiple databases"



Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: search multiple databases (revisited)) In reply to
Hi Lois, thank you for the reply, although I couldn't find anything relating to what I'm looking for.

Although, diggin further into the archived posts, I found two threads that seem to be exactly what I'm looking for. However, It doesn't appear that the threads really went anywhere except noting it would be possible.

The threads were:

http://www.gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=DBInst&Number=57709&page=&view=&sb=&vc=1

and

http://www.gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=DBInst&Number=57453&page=&view=&sb=&vc=1

The discussion was with JPDeni. I was wondering if JP had perhaps continued this conservation and got further into the requirements to make it work.

Trev

Quote Reply
Re: search multiple databases (revisited)) In reply to
I haven't gotten much response to my post. So I'll attempt it myself. Any idea which module I should use to start a multiple database search. From the view_record secton perhaps.

Trev

Quote Reply
Re: search multiple databases (revisited)) In reply to
I need to do a keyword search in multiple databases. I used the code given by Lois:

____________________________________________________________

This will allow users to search by keyword in one or all the databases. Note this is for default users. This sample form is for use on a static html page.

Replace value= to the names of your database files (.db)
Then rename your title for each radio button.

<CENTER><FORM ACTION="/cgi-bin/default.cgi" method="GET">
<INPUT TYPE=hidden name="uid" value="default">
<B>Keyword search</B><BR>
<INPUT TYPE="text" name="keyword">
<INPUT TYPE="radio" NAME="db" value="Name of Database1"> Database One
<INPUT TYPE="radio" NAME="db" value="Name of Database2"> Database Two
<INPUT TYPE="radio" NAME="db" value="Name of Database3"> Database Three</FORM></CENTER>
________________________________________________________

It works for one database at a time, but does not search all databases for the given keyword. I also tried changing the radio button to drop down list with multiple selects possible. The keyword search works fine if one database is selected but fails if multiple databases are selected.

I want the search the given keyword in all the selected databases. And, I want the results to come all togather in one list.

Is it possible? and, what changes I need to make to the above code to make it work.

Would really appreciate any help.



Quote Reply
Re: search multiple databases (revisited)) In reply to
As far as I know there is no other method of searching several databases at once.

The method noted above would allow people to choose the database to search within.

Sorry I could not be of more help, but after viewing many threads over the past couple years or more more .. there has been no mods presented with a method to do this.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: search multiple databases (revisited)) In reply to
Hi. I'm trying to do EXACTLY what you were trying back in August - search multiple databases and have it return on a page. Did you ever work on this? Did you ever get it to work?

I'll be starting to create this myself and any help would be greatly appreciated!

Quote Reply
Re: [apenticoff] search multiple databases (revisited)) In reply to
Add me to the list of interested folks for this one. I can think of several differnt uses for it.

If anyone gets around to it.....
averick@yahoo.com,

Thanks,
averick
Quote Reply
Re: [averick] search multiple databases (revisited)) In reply to
The following is not really a simultaneous search in multiple databases,
but something slightly different:
Search for "Name" in database1 and, along with the results for "Name", display
all records in database2, database3 and database4 which also have the same value in "Name".

It seems to me that's what you want.

I tried something like that once, based on code from JPDeni.
My situation was simpler, though,
as I only wanted to retrieve the value of *one* field from *one* other database.

You have the database file name stored in $db_file_name
and the database columns (i.e. field names) in @db_cols.
So when you want to search in a different database, you have to change these two values.

my $old_file_name = $db_file_name;
my @old_cols = @db_cols;
$db_file_name = "database2";
@db_cols = &get_db_cols("database2");
$in{'name'} = "your search term";
my ($status2, @hits2) = &query;
if ($status2 eq "ok") {
my (%rec2) = &array_to_hash(@hits2); # might cause problem if more than one hit!
print "$rec2{'first_field_of_database2'} $rec2{'another_field_of_database2'}<br>";}

$db_file_name = "database3";
@db_cols = &get_db_cols("database3");
$in{'name'} = "your search term";
my ($status3, @hits3) = &query;
if ($status3 eq "ok") {
my (%rec3) = &array_to_hash(@hits3); # might cause problem if more than one hit!
print "$rec3{'first_field_of_database3'} $rec3{'another_field_of_database3'}<br>"; }

$db_file_name = $old_file_name;
@db_cols = @old_cols;

sub get_db_cols {
#takes name of db_setup as input values and returns list of database columns (ordered!)
my $configfile = shift;
my ($fields, @cols);
open(FILE, "<$configfile") || &cgierr("Cannot open $configfile.\n$!");
undef $/;
while (<FILE>){ if (/(%db_def\s+=\s+\(\s+)(\n'.*?)(\))/s) { $fields = $2;}}
close(FILE);
while ($fields =~ /(\n')(\w+)(')/g) {push (@cols, $2); }
return (@cols);
}

Now why do the two lines I marked cause problems if there's more than one hit?
Because array_to_hash is coded on the assumption that it gets the values for ONE record as input,
and not for more.
If you know there's only going to be one record for "Name" in the other database, that's no problem.

Hope this helped somehow,

kellner
Quote Reply
Re: [kellner] search multiple databases (revisited)) In reply to
strange, somehow I can't seem to edit my posts when using IE 5.5, thoug it works with Netscape6.
Anyway: Replace "&query" in the above with "&query('view')" throughout.
kellner