Gossamer Forum
Home : Products : Links 2.0 : Customization :

you may say i am greedy...

Quote Reply
you may say i am greedy...
greedy...because i have to liks databases' but i would like to keep their individual search.cgi..but also have one script that searches both databases and brings back all the likes like liks from the first database on top then the second one below.....

Please can someone help?

Thanks

Gian Wilson
Quote Reply
Re: you may say i am greedy... In reply to
Well, these codes may work.

Since you have two links databases, I am sure that you also have two different .cfg files (or different variables in one .cfg file) and that you have two links.def files.

If you have two different .cfg files, then you will have to require both .cfg files in the Required Libraries section of the search.cgi file.

Make sure that you have unique variable names for the databases, like $db_file_name and $db_file2_name.

Then follow these steps:

1) Add the following codes:

Code:
if ($in{'dbtype'} eq "database1") {

before the following codes:

Code:
open (DB, "<$db_file_name")...

2) Then add a closing right bracket after the following codes:

Code:
close DB;

3) Then add the following codes after the closing right bracket you added:

Code:
if {$in{'dbtype'} eq "database2") {
# Go through second database.
open (DB2, "<$db_file2_name") or &cgierr("error in search. unable to open database: $db_file_name. Reason: $!");
flock (DB2, 1) if ($db_use_flock);
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = &split_decode($_);
$grand_total++;

# Check to see if the link matches.
$match = 0; $andmatch = 1;
if ($regexp) {
FIELD: foreach $field (@search_fields) {
$_ = $values[$field];
$or_match ?
($match = $match | | &{$regexp}) :
($match = &{$regexp});
last FIELD if ($match);
}
}

# Check to see if the link matches any database fields. Only exact matches
# here.
if ($or_match | | $match | | !$regexp) {
FIELD: foreach $field (@field_search) {
if ($or_match) {
$match = $match | | ($in{$db_cols[$field]} eq $values[$field]);
$match and last FIELD;
}
else {
$match = ($in{$db_cols[$field]} eq $values[$field]);
$match or last FIELD;
}
}
}
$andmatch = $andmatch && $match;

# If we have a hit, add it in!
if (($or_match && $match) or $andmatch) {
push (@{$link_results{$values[$db_category]}}, @values);
$numhits++; # We have a match!
}

# Check to see if the category matches.
if ($regexp and !$seen{$values[$db_category]}++) {
$match=0; $andmatch = 1;
$_ = $values[$db_category];
$or_match ?
($match = $match | | &{$regexp}) :
($match = &{$regexp});
$andmatch = $andmatch && $match;

if (($or_match && $match) or $andmatch) {
$numcat++;
push (@category_results, $values[$db_category]);
}
}
}
close DB2;
}

4) Then in your search.html template file or anywhere else you have your search form codes, add the following codes:

Code:
<input type="radio" name="dbtype" value="database1"> Database1
<input type="radio" name="dbtype" value="database2"> Database2

These are pretty intensive codes and may not work very well. But this is a quick and dirty solution to your inquiry.

Hope this works and helps.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




[This message has been edited by Eliot (edited December 09, 1999).]
Quote Reply
Re: you may say i am greedy... In reply to
you can put a loop

Code:
foreach (qw!$db_file_name $db_file_name2!) {
open (DB2, "<$_") or &cgierr("Can't Open: $_. Reason: $!");
#regular code...
}

keep in mind it won't work unless they both have the same exact fields..

jerry
Quote Reply
Re: you may say i am greedy... In reply to
Great suggestion, Widgetz...Forgot about the loop option.

Oops!

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: you may say i am greedy... In reply to
Wow you guys are quick......just on little problem......they dont have the smae exact fields.....
Quote Reply
Re: you may say i am greedy... In reply to
Then you cannot use the codes. The codes provided only work for databases with the same exact field structure.

Good luck.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: you may say i am greedy... In reply to
I just tried to implement this code but now whenever I search I get an internal server error!

Thankyou,
From Paul Wilson.
Quote Reply
Re: you may say i am greedy... In reply to
Internal Server Errors are the hardest to track down because there is no indication as to what is causing it, not even in system error logs generally. I call them Infernal Server Errors because of that. It could be caused by the wrong path to perl at the top of the script or a typo someplace. The best bet is to double- and triple-check everything you did to see if you made an error somewhere when you put in the code. Other than that, it could be a plain logic error which would be harder to detect.

I hope this helps.

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
Quote Reply
Re: you may say i am greedy... In reply to
Hmmmmmmmm.....ok thanks!

Thankyou,
From Paul Wilson.
Quote Reply
Re: you may say i am greedy... In reply to
Could the problem be to do with the fact that I am using Site_html.pl rather than templates?

Would I have to alter the code in any way if I wanted to use it with Site_html.pl?

Thankyou,
From Paul Wilson.
Quote Reply
Re: [Eliot] you may say i am greedy... In reply to
Regarding this mod, can I use this logic with a dbMan file
and a LINKS file ( 2 seperate databases) with the same fields. I have a LINKS database for general(public) entry and a membership database, for members only, so I can't see how I could make it all one database without creating some people/political problems.
Quote Reply
Re: [Eliot] you may say i am greedy... In reply to
In regards to your instructions (as below quoted) i as a non scripter would like to learn if i got this right
}
}
close DB;
}
if {$in{'dbtype'} eq "database2") {
as far as the closing bracket and it's position goes???
=======================================
Then in regards to the search or category results pages html:
You seem to have a solution with radio buttons, meaning people can choose which db they want to search in - BUT NOT THAT THE RESULTS appear in order on the same results page from both db's!!!
So, my aim is to have search results or category listings that are retrieved from both databases and are lined up as i chose by submission date.
This because i want some links to appear in regular font and some others (out of a second db) in another font or color, that is what i try to achieve, i guess your mod is not all it takes to do that???
================================================
Then in the category.html template there would have to be some sort of change too at
<%if links%>

<!-- Links -->
<%links%>

<%endif%>

, there would have to be something like
<%links2%> or so to bring in the links of database2, or is that not how it works???
My oh my, maybe this is over my head or knowledge, but any further hints to get there would be great, after all learning keeps us young........
++++++++++++++++++++++++++++++++++++++++++++++++
2) Then add a closing right bracket after the following codes:

Code:
close DB;

4) Then in your search.html template file or anywhere else you have your search form codes, add the following codes:

Code:
<input type="radio" name="dbtype" value="database1"> Database1
<input type="radio" name="dbtype" value="database2"> Database2