Re: relevance

From: Terence Kearns <terencek(at)isd(dot)canberra(dot)edu(dot)au>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: jtx <jtx(at)hatesville(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: relevance
Date: 2003-07-17 02:51:24
Message-ID: 3F160F2C.6050902@cts.canberra.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


>>select id from tablename where message like '%sql%';
>>
>>If there any way to determine exactly how many times 'sql' is matched in
>>that search in each particular row, and then sort by the most matches,
>>or am I going to have to write a script to do the sorting for me?
>>

You could probably write a function in postgres (say, "matchcount()")
which returns the match count (possibly using perl and a regex).

SELECT matchcount(message,'sql') AS matchcount, id
FROM tablename
WHERE message LIKE '%sql%'
ORDER BY matchcount(message,'sql') DESC

The ORDER BY will probably fail, but you can try :)

--
Terence Kearns ~ ph: +61 2 6201 5516
IT Database/Applications Developer
Enterprise Information Systems
Client Services Division
University of Canberra
www.canberra.edu.au

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Benoît Bournon 2003-07-17 06:39:30 Re: Recursive request ...
Previous Message Oleg Bartunov 2003-07-17 02:37:49 Re: relevance