pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chad McKay <cbm@gfxsp.com>
To: pgsql-sql@postgresql.org
Subject: Sort by relevance
Date: Mon, 15 Jan 2001 12:44:59 -0500
Message-ID: <002901c07f1a$e4887800$0b01a8c0@graphicfx.net> (raw)

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

view thread (8+ messages)  latest in thread

Message-ID: <002901c07f1a$e4887800$0b01a8c0@graphicfx.net>
Permalink:  ../002901c07f1a$e4887800$0b01a8c0@graphicfx.net/
Also on:    postgresql.org/message-id/002901c07f1a$e4887800$0b01a8c0@graphicfx.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: cbm@gfxsp.com
  Subject: Re: Sort by relevance
  In-Reply-To: <002901c07f1a$e4887800$0b01a8c0@graphicfx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox