Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Alphabetically Sort Search Engine Results?

Alphabetically Sort Search Engine Results?
Thread Tools
megasad
Grizzled Veteran
Join Date: Oct 2002
Status: Offline
Reply With Quote
Nov 9, 2005, 05:10 PM
 
I started using a free search engine on my website back in May.

Does anyone know how I can make the search results be sorted alphabetically, either by filename or page title? Either would be fine.
BayBook (13" MacBook Pro, 2.4GHz Core 2 Duo, 4GB RAM, 1TB HD) // BayPhone (iPhone 4, 32GB, black)
     
clam2000
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Nov 10, 2005, 02:27 AM
 
let me prefix this by saying i didn't look to closely, and i haven't done much with perl.

the line's you're interested in are:
Code:
my @keys; if( defined($query->param('sort')) && $query->param('sort') eq 'title' ) { @keys = sort {uc($titles_db{$a}) cmp uc($titles_db{$b})} (keys %answer); } else { @keys = sort {$answer{$b} <=> $answer{$a}} (keys %answer); }
in the search.pl script

you probably can just say:
Code:
my @keys; @keys = keys %answer;
to stop the sorting,

mind you, this is just a guess, i really don't know if that will work.
     
megasad  (op)
Grizzled Veteran
Join Date: Oct 2002
Status: Offline
Reply With Quote
Nov 10, 2005, 05:52 AM
 
Originally Posted by clam2000
let me prefix this by saying i didn't look to closely, and i haven't done much with perl.

the line's you're interested in are:
Code:
my @keys; if( defined($query->param('sort')) && $query->param('sort') eq 'title' ) { @keys = sort {uc($titles_db{$a}) cmp uc($titles_db{$b})} (keys %answer); } else { @keys = sort {$answer{$b} <=> $answer{$a}} (keys %answer); }
in the search.pl script

you probably can just say:
Code:
my @keys; @keys = keys %answer;
to stop the sorting,

mind you, this is just a guess, i really don't know if that will work.
I figured it was those lines, but unfortunately your suggestion did not work. It seems to sort the same as before.

I know nothing of Perl but I figure this script is being very clever as far as it is concerned, weighting all the results in various ways. I think one route to take would be to strip all that gumph out.

Or, maybe easier, would be to apply an alphabetical sort command to the results, just before they are sent to the page? I realise that this is ass-backwards, doing a whole bunch of work and then undoing it, but if it's easier to implement I don't really mind.

I found this page but as I say, I do not know Perl, nor programming of any kind, so I do not know how to make it go.
BayBook (13" MacBook Pro, 2.4GHz Core 2 Duo, 4GB RAM, 1TB HD) // BayPhone (iPhone 4, 32GB, black)
     
megasad  (op)
Grizzled Veteran
Join Date: Oct 2002
Status: Offline
Reply With Quote
Nov 10, 2005, 01:38 PM
 
Just had me an idea; does anyone know of a javascript that I could put in the template search result page that would sort the results alphabetically?
BayBook (13" MacBook Pro, 2.4GHz Core 2 Duo, 4GB RAM, 1TB HD) // BayPhone (iPhone 4, 32GB, black)
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:21 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,