Gossamer Forum
Home : Products : Links 2.0 : Customization :

RE-Alphasearch by Glennu

Quote Reply
RE-Alphasearch by Glennu
I have installed this, but doesn't seem to work, I no I have installed it correctly, there isn't much to it to make a mistake with. But just comes up with no match found no matter what letter or combinations. search.cgi?query=...&letter=A or whatever doesn't work. And also when you try and use the normal search you now you end up with a fatal errror....."fatal error: /^[]/: unmatched [] in regexp at c:\inetpub\wwwroot\entertainer2\cgi-bin\search.cgi line 218, line 1."
Glennu if you could see your way to sovle this problem it would be much appreciated, as it seems to be a good mod, if you can get it to work. I have just noticed in my search's a couple of other people have had the same problem.

Admittedlamb


Quote Reply
Re: RE-Alphasearch by Glennu In reply to
I have already mentioned this the Glennu.

To preform a normal search, in the query string you should have
...search.cgi?query=whatever&letter=

You could try surrounding the code with....

if ($in{'letter'}) {

code

}

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Thought I'd updated it on my site but must have forgoten. However if you'd had searched the forum for alpha search you'd have quickly found a solution in which I said:

instead of:

$charfirst = "$in{'letter'}";

use:

$charfirst= ($in{'letter'} =~ /[A-Z]+/i ? "$in{'letter'}" : "A-Z");

There's a few other things/improvements I've done since then as well. I'll post them all in the future when I get some time.



Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links
Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Or use this if your including links beginning with letters.

$charfirst = ($in{'letter'} =~ /[A-Z0-9]+/i ? "$in{'letter'}" : "A-Z0-9");

Sorry ignore my comment about searching the forum. I just had a look for it and although I found it, it wasn't very easy to find!

Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links
Quote Reply
Re: RE-Alphasearch by Glennu In reply to
You mean numbers?

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Yep, numbers even. (my brain is not functioning too well at the moment!)

Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links
Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Ok Glenu did as you suggested, made no difference, still founf no match and still got that fatal error when used normal search. this is what i changed:
-------------------------------
# Go through the database.
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name. Reason: $!");
flock (DB, 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++;
$_ = "\U$values[$db_title]\E";
$charfirst= ($in{'letter'} =~ /[A-Z]+/i ? "$in{'letter'}" : "A-Z");
if (m/^[$charfirst]/) {
and also this:
}
# Check to see if the category matches.
-----------------------------------------------
And this is the search term i used:
http://tasdirect/entertainer2/cgi-bin/search.cgi?query=...&letter=A
--------------------------------------------
So whats the problem...and as i said it still gives a fatal error when you use the normal search query.

Admittedlamb.


Quote Reply
Re: RE-Alphasearch by Glennu In reply to
put $charfirst= ($in{'letter'} =~ /[A-Z]+/i ? "$in{'letter'}" : "A-Z"); at the top of the script.

What have you got inbetween:if (m/^[$charfirst]/) {
and
}




Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links
Quote Reply
Re: RE-Alphasearch by Glennu In reply to
To get rid of the error could you not make a copy of the code that searches the database and use....

if ($in{'letter'}) (

do this code

}
else {

default code

}

How about......

$ltr = $in{'letter'};
$char1 = substr($in{$db_cols[$field]},0,1);

.......hmm or should that be..$char1 = substr($values[$field],0,1);

if ($ltr eq $char1) {

get results....

}









Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Ok Glenu this is what you have one your pages...the instuction:
----------------------------------------Below:

# Go through the database.
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name. Reason: $!");
flock (DB, 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++;

Add:

$_ = "\U$values[$db_title]\E";
$charfirst = "$in{'letter'}";
if (m/^[$charfirst]/) {


Then replace:

# Check to see if the category matches.

With:

}
# Check to see if the category matches.
-----------------------------------------------So search.cgi?query=...&letter=A
Displays al links matching query beginning with letter A

So search.cgi?query=...&letter=A-Z
Displays all links matching query beginning with letter A-Z

So search.cgi?query=...&letter=A-Z0-9
Displays al links matching query beginning with letter A-Z or 0-9
---------------------------------------------
I followed that to the Tee....now you say put that code at the top of the search script which I will try but don't see how that would make a difference. What paul said seem's to make sense but what "default code"

Admittedlamb.


Quote Reply
Re: RE-Alphasearch by Glennu In reply to
The code that is already in search.cgi

Then "do this code" would be the modded version.

Therefore if $in{'letter'} was passed to search.cgi, the modded code would execute but otherwise the default code will.

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Ok getting somewhere: chaged it to look like this:
----------------------------------------------
# Go through the database.
$charfirst= ($in{'letter'} =~ /[A-Z]+/i ? "$in{'letter'}" : "A-Z");
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name. Reason: $!");
flock (DB, 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++;
$_ = "\U$values[$db_title]\E";

if (m/^[$charfirst]/) {
--------------------------------------------------
THIS:
$charfirst= ($in{'letter'} =~ /[A-Z]+/i ? "$in{'letter'}" : "A-Z");
NOW AT THE TOP...that seemed to got rid of the fatal error using the normal search query...but still can't find a match with the single letter query?
GEE I Love Perl fun isn't it.

Admittedlamb.



Quote Reply
Re: RE-Alphasearch by Glennu In reply to
In Reply To:
but still can't find a match with the single letter query?
Uh that ISN'T what this mod does. It isn't for single letter queries, it is for matching only links who's title field begins with the value of $in{'letter'};

For single letter queries you need to change this (not recommended).......

Code:
# Save the reg expressions to avoid rebuilding.
$or_match = $bool ne 'and';
if ($or_match) {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 2); # Skip single letter words.
$tmp .= "m/\Q${$search_terms}[$_]\E/io ||";
}
}
to.........

Code:
# Save the reg expressions to avoid rebuilding.
$or_match = $bool ne 'and';
if ($or_match) {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 1); # Skip single letter words.
$tmp .= "m/\Q${$search_terms}[$_]\E/io ||";
}
}
Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Thanks Paul, but already new you could do that, but that just brings up all the links in your database, like search.cgi?query=c searches all allowed fields for C so virtually brings up all links. What I wish to do is ...I have a song links ok. I wish people to be able to click say "A" and that will bring up all the songs beginnig with A in the search results. I thought this Mod would do it, but aparently not..Is there a way to do it?

Admittedlamb>

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Yes this mod will do that.

Create a new tag if you want to create a navigation bar like......

[
<a href="http://www.domain.com/cgi-bin/search.cgi?query=<%term%>&letter=a">A</a>|
<a href="http://www.domain.com/cgi-bin/search.cgi?query=<%term%>&letter=b">B</a>|
<a href="http://www.domain.com/cgi-bin/search.cgi?query=<%term%>&letter=c">C</a>|
<a href="http://www.domain.com/cgi-bin/search.cgi?query=<%term%>&letter=d">D</a>|
etc........up to z
]

This would need to go on your search results pages so that <%term%> is replaced by the search term.

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: RE-Alphasearch by Glennu In reply to
'Is there a way to do it?'

Yep. It can be done quite easily by making a few more alterations to search.cgi. However I wouldn't use search.cgi as you won't be needing all the other stuff in it. The alpha links in the resource centre will build static pages of links beginning with A, B, C etc.... My dynamicat mod will do also just letters.


Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links
Quote Reply
Re: RE-Alphasearch by Glennu In reply to
Thanks Paul your suggestion works just find for me..and Glenu, yes saw that mod in resource section, but gee it would be like building a whole new links..and does more than i ever wished anyway..your mod the way I have it works fine for what i need it for thank you.

Admittedlamb.

PS: I will probably use 2 or 3 more of you mods glenu..they are quite good..and will definitley put a link to you on my site when finnished .. it saves me alot of work. *CHEERS*