pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: Jess Wren <jess.wren@interference.cc>
To: pgsql-general@lists.postgresql.org
Subject: Re: How to use full-text search URL parser to filter query results by domain name?
Date: Mon, 8 Apr 2019 14:50:33 +0300
Message-ID: <941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru> (raw)
In-Reply-To: <2a782f3e-7473-43ce-aad5-1de31cf2b31a@interference.cc>
References: <2a782f3e-7473-43ce-aad5-1de31cf2b31a@interference.cc>

On 07.04.2019 07:06, Jess Wren wrote:
> However, I can't figure out how I would integrate this into the above 
> query to filter out duplicate domains from the results. And because this 
> is the docs for "testing and debugging text search 
> <https://www.postgresql.org/docs/11/textsearch-debugging.html#TEXTSEARCH-PARSER-TESTING>";, 
> I don't know if this use of `ts_parse()` is even related to how the URL 
> parser is intended to be used in practice.
> 
> How would I use the "host" parser in my query above to return one row 
> per domain? Also, how would I appropriately index the "links" table for 
> "host" and "url" token lookup?

I think it is normal to use ts_parse(). And I suppose you might use 
windows functions.

For example, you have table links:

=# create table links (score int, link text);
=# insert into links values
   (1, 'http://www.foo.com/bar';),
   (2, 'http://www.foo.com/foo';),
   (2, 'http://www.bar.com/foo';),
   (1, 'http://www.bar.com/bar';);

You can use the following query:

=# with l as (
   select score, token, link,
     rank() over (partition by token order by score) as rank
   from links,
     lateral ts_parse('default', link)
   where tokid = 6)
select score, token, link from l where rank = 1;
  score |    token    |          link
-------+-------------+------------------------
      1 | www.bar.com | http://www.bar.com/bar
      1 | www.foo.com | http://www.foo.com/bar

It is just the idea, probably the query might be simpler.

-- 
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company





view thread (6+ messages)  latest in thread

Message-ID: <941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru>
Permalink:  ../941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru/
Also on:    postgresql.org/message-id/941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: a.zakirov@postgrespro.ru, jess.wren@interference.cc
  Subject: Re: How to use full-text search URL parser to filter query results by domain name?
  In-Reply-To: <941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru>
  References: <2a782f3e-7473-43ce-aad5-1de31cf2b31a@interference.cc> <941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru>

* 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