Re: doc on searching, and sorting

From: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
To: "Luis H(dot)" <pgsql-novice(at)geekhouse(dot)no-ip(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: doc on searching, and sorting
Date: 2003-08-25 17:09:41
Message-ID: 1061831381.503.18.camel@billy
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Am Mo, 2003-08-25 um 18.53 schrieb Luis H.:
>
> In the absence of that, I'm currently trying to figure out if it is
> feasible to sort my matches as follows: I have column A and column B,
> I execute a search for certain words in A OR certain words in B, I'd
> like to sort it so that documents that match both A and B appear
> first, then A, then B. Or how about sorting such that the rows that
> matched the most words in the search string appear first? I dont know
> if such sorting would require joins and subqueries such that it would
> take up a lot of resources. Any tips would be appreciated!

Here's an example:
BTW: TRUE will be listed after FALSE, so we have to use DESC in the
ORDER BY clause.

Forget about the UNION ALL stuff, it's just there to give you an example
table with 3 rows and 2 cols.

SELECT
*
FROM
(
SELECT 1 as a, 2 as b UNION ALL
SELECT 1 as a, 1 as b UNION ALL
SELECT 1 as a, 0 as b
) AS test_table
ORDER BY
(a ILIKE '%keyword%' and b ILIKE '%keyword%') DESC;

HTH
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tomka Gergely 2003-08-25 17:13:29 Re: Way to tell what SQL is currently running?
Previous Message Nabil Sayegh 2003-08-25 17:00:59 Re: doc on searching, and sorting