Gossamer Forum
Home : Products : DBMan : Customization :

Mod in progress: Search within a search. Help needed.

Quote Reply
Mod in progress: Search within a search. Help needed.
Hello all,

I've been trying to fashion an 'internal search' mod that works with JPDeni's original short/long mod. In short, when a user views the long version of a record, this internal search mod displays abbreviated versions of other records, such as "Other articles by this author" or "This week's newest records." Clicking on one of these related records brings up its long version.

I'm not a Perl genius. Using what I've learned about DBMan from this forum, I was able to concoct a solution, but it suffers from at least one drawback: I intended the mod to isolate temporary %in values for our internal search, and then replace the original %in values (as called in the url) so that the page will load as expected. Instead, the %in values seem to be added to each other, muddying the water, so to speak.

In other words, the only way to use this mod successfully is to make sure that it executes after the main record and associated page numbering, etc. has been displayed. Putting it before the main record threatens to replace the expected %in values with the temporary, internal %in values, screwing up results and related links.

I'd like to improve the mod and make it usable anywhere on the page. So I turn again to this community for advice. If you can tighten up or repair the following work, I'd be most grateful.



Here's the mod as it stands:

Code:
# somewhere in sub html_record_long, create new
# key-value pairs to search on, and call the new subroutine.

%in_values = ("Key","value","sb",1,"so","descend","mh",1);
print &internal_search(%in_values);


sub internal_search {
# --------------------------------------------------------
# Performs another db query to produce a new display
# of records within and separate from the current results.

my (%inhash) = @_;
my $output;

# attempt to transfer the current %in values to a
# temporary holding hash

%current_in = %in;
undef %in;

# creates new, temporary %in with values from %inhash

while (($key, $value) = each (%inhash)) {
push(@invalues, $key, $value);
}
%in = @invalues;

# call the search

my ($status2, @hits2) = &query("view");
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);

# if results were found, send them to html_record_brief
# (a new subroutine) for display

if ($status2 eq "ok") {
for (0 .. $numhits2 - 1) {
$output .= &$html_record_brief (&array_to_hash($_, @hits2));
++$rec_count;
}
}

# attempt to restore the current %in values

undef %in;
%in = %current_in;

return $output;
}


Thanks for looking,

ecn

Last edited by:

ecn: Mar 21, 2003, 11:09 PM
Quote Reply
Re: [ecn] Mod in progress: Search within a search. Help needed. In reply to
Quote:
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);

Is the use of the # in $#hits2 OK?

Sorry if I can't be more help than that.

I have done something like that, but not as a MOD, but rather pulling different searches into different html frames. Really simple to combine different "searches" that way, once each search works on it's own. When I say search, that includes the categories MOD (left menu frame) and short/long in the main frame.

Then just for fun a tiny little bottom frame for "last updated".

On a different note, it seems like what you need is something like the relational MOD where the records come from different search results.

Good luck
Quote Reply
Re: [joematt] Mod in progress: Search within a search. Help needed. In reply to
Thanks for your reply, joematt --

Tell you the truth, I can't answer your question, but I can tell you that I borrowed that line from html_view_success character for character, changing only $numhits to $numhits2 and $#hits to $#hits2. For all I know, the line isn't needed for my mod at all.

Sounds like your solution is a good one, far less risky than what I'm trying. But since this mod works almost perfectly for my situation, I'm still hoping I can figure out where it's failing.

The main problem seems to be that I am not successfully emtpying the %in hash for the internal search. %in values from the internal search are 'sticking,' and carrying over to the main search. Don't have a clue why.