Sort by relevance

From: "Chad McKay" <cbm(at)gfxsp(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Sort by relevance
Date: 2001-01-15 17:44:59
Message-ID: 002901c07f1a$e4887800$0b01a8c0@graphicfx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I am trying to use a perl script to break an input string into keywords and
pull out all the records that match any of them:

my (@chips)= split(' ', $f_name);
foreach my $chip (@chips) {
next if ($stoppers=~/ $chip / || length($chip) < 3);
if ($query) {$query .= " OR name ~* '.*$chip.*' ";}
else {$query = "SELECT * FROM info WHERE name ~* '.*$chip.*' ";}
}

this works fine for pulling the records but I would like to sort them by how
many of the "chips" matched.

On a set like:

name
-------------
Bill Smith
Ted Smith
Ted Brown

an input of : Ted Smith
would give me a query string of:
SELECT * FROM info WHERE name ~* '.*Ted.*' or name~*'.*Smith.*'

which returns all records - which is what I want - but I would like to have
Ted Smith in the first row followed by the other records grouped by name and
sorted on another column (city or state in the real table)

Thanks for your help,
Chad McKay

Browse pgsql-sql by date

  From Date Subject
Next Message Joern Muehlencord 2001-01-15 18:29:42 Adding a parameter to a trigger
Previous Message Stephan Szabo 2001-01-15 17:41:06 Re: How to display a unixtimestamp from a timestamp record?