X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 2A232CC8EC for ; Thu, 17 Jul 2003 07:15:28 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 85301-08 for ; Thu, 17 Jul 2003 07:15:52 +0000 (GMT) Received: from rtlocal.trade-india.com (unknown [203.196.129.235]) by svr1.postgresql.org (Postfix) with SMTP id 97049CC8E9 for ; Thu, 17 Jul 2003 04:15:21 -0300 (ADT) Received: (qmail 9269 invoked from network); 17 Jul 2003 07:23:56 -0000 Received: from unknown (HELO system67.trade-india-local.com) (unknown) by unknown with SMTP; 17 Jul 2003 07:23:56 -0000 From: Rajesh Kumar Mallah Organization: Infocom Network Limited To: Terence Kearns , Oleg Bartunov Subject: Re: relevance Date: Thu, 17 Jul 2003 12:45:44 +0530 User-Agent: KMail/1.5.1 Cc: jtx , pgsql-sql@postgresql.org References: <001001c34bfd$acad8d50$c733a8c0@slappy> <3F160F2C.6050902@cts.canberra.edu.au> In-Reply-To: <3F160F2C.6050902@cts.canberra.edu.au> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200307171245.44274.mallah@trade-india.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/211 X-Sequence-Number: 14325 On Thursday 17 Jul 2003 8:21 am, Terence Kearns wrote: > >>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). Why reinvent the wheel when tsearch already does the job perfectly and is PostgreSQL compaitable. Regds Mallah. > > 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 :)