Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Sorting Indexed query results...

Quote Reply
Sorting Indexed query results...
Hey all,

Has anyone (apart from Gossamer) managed to make Links SQL 1.xx sort the indexed query results ?

joe

Quote Reply
Re: Sorting Indexed query results... In reply to
You can modify the $LINKS{build_sort_order_category} variable in the Links.pm file.

Basically, you would add in a comma separated list of columns that you are indexing.

EXAMPLE:

Code:

$LINKS{build_sort_order_category} = "Title,Description,URL";


The links would be sorted first by Title, then description, then URL in ascending order. If you want descending order, add DESC after the last column name in the comma separated list.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Sorting Indexed query results... In reply to
Thanks for your quick reply Eliot.. much appreciated !

I can't seem to find any instance of that variable name in Search.pm, search.cgi, DBSQL.pm or DB_Utils.pm which are all the files that help operate the search. Is it my massively hacked code ? could you give me some idea as to where I find those variables in the files ?

joe

Quote Reply
Re: Sorting Indexed query results... In reply to
Uh...You did NOT read my reply carefully! Did I say Search.pm, search.cgi, DBSQL.pm, or DB_Utils.pm??? NO!!!!

READ MY REPLY AGAIN!

In Reply To:

You can modify the $LINKS{build_sort_order_category} variable in the Links.pm file.


Plain as day, if you ask me! Tongue

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Sorting Indexed query results... In reply to
I don't mean to be rude, but what's the point of changing that variable ? I can't see, from checking those files for an instance of that variable, that it will have any impact on the indexed search results which are returned. Is this just me being dim ?

cheers,

joe

Quote Reply
Re: Sorting Indexed query results... In reply to
Hi,

No, it's not trivial to change the sort order. You would be better off using search-ni.cgi (the ni stands for non-indexed). From there, you can easily set the sort order.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Sorting Indexed query results... In reply to
Thanks Alex ! Is it possible for you to share the principals behind such a modification. If I have some idea about how to go about grouping results it might help a little.

cheers,

joe

Quote Reply
Re: Sorting Indexed query results... In reply to
Hi,

Look for:

Code:
$query = qq!
SELECT l.*, c.Name
FROM Links AS l, Category AS c
WHERE ($lwhere) AND
l.CategoryID = c.ID
LIMIT $offset, 1000
!;
And add an 'ORDER BY colname' before the LIMIT line and you should be fine.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Sorting Indexed query results... In reply to
Opps!

Thanks for that, looks easy enough... although I was sort of hoping for some hints on the indexed search. Are you able to say what the basic principals are behind making it return results in an ordered way but still use the index ?

Thanks for your time Alex, it's very much appreciated.

joe

Quote Reply
Re: Sorting Indexed query results... In reply to
Hi,

Sure, it's _very_ ugly, and much improved in 2.0 (total rewrite), but if you are feeling like some pain, it's in Search.pm around line 692:

# ... sort and the data
my @query_results = sort { $$b[1] <=> $$a[1] } map ( [$_, $$id_results {$_} ], keys %$id_results );

That sorts it by relevance. You don't have any other information except id's and relevance, but you could play with id_results a little to get it to work.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Sorting Indexed query results... In reply to
Thank you ever so much Alex ! I'll strap on the leather and prepare myself for some sadomasochist perl coding ;)

joe