Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDSnR-0006Uv-UX for pgsql-general@arkaria.postgresql.org; Mon, 08 Apr 2019 11:50:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hDSnQ-0007cp-F8 for pgsql-general@arkaria.postgresql.org; Mon, 08 Apr 2019 11:50:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDSnQ-0007c0-1q for pgsql-general@lists.postgresql.org; Mon, 08 Apr 2019 11:50:40 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hDSnL-0006dp-LJ for pgsql-general@lists.postgresql.org; Mon, 08 Apr 2019 11:50:39 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 2C5F321C3D3A; Mon, 8 Apr 2019 14:50:34 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.237] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 28E6021C3D22; Mon, 8 Apr 2019 14:50:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1554724233; bh=JzUw+vbCodA/quJbSCegqrbz9yrcx3vCMGpwBObLT+4=; h=Subject:To:References:From:Date:In-Reply-To; b=fiZNldOHRoflfi7w6A2s6P9ggEBhueqM5VAHOTk1g5qyeyJhW/ERZXXlehkQEdUnX XOXn8zlT/g0+tAFBBlw1ZAj8vkAEcZqvn8FF/euFdxzYPug1XLpon2y2bR2QAmECTe AfLIXKFkNl010spMqlMiTImU5LUJ5Y+VA9rfMnQE= Subject: Re: How to use full-text search URL parser to filter query results by domain name? To: Jess Wren , pgsql-general@lists.postgresql.org References: <2a782f3e-7473-43ce-aad5-1de31cf2b31a@interference.cc> From: Arthur Zakirov Message-ID: <941c4c08-23e3-ac5c-9e2e-8af76cadd3e3@postgrespro.ru> Date: Mon, 8 Apr 2019 14:50:33 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <2a782f3e-7473-43ce-aad5-1de31cf2b31a@interference.cc> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 > ", > 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