Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eg2Qn-0007Im-Oa for pgsql-general@arkaria.postgresql.org; Mon, 29 Jan 2018 05:56:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eg2Ql-00048n-6g for pgsql-general@arkaria.postgresql.org; Mon, 29 Jan 2018 05:56:35 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eg2Qk-00048d-NC for pgsql-general@lists.postgresql.org; Mon, 29 Jan 2018 05:56:35 +0000 Received: from mail-it0-x235.google.com ([2607:f8b0:4001:c0b::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eg2Qg-0005ox-Un for pgsql-general@postgresql.org; Mon, 29 Jan 2018 05:56:33 +0000 Received: by mail-it0-x235.google.com with SMTP id m11so29987529iti.1 for ; Sun, 28 Jan 2018 21:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lucee-org.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=Zc89bCqsqTvavOT7c7LPUg/82y7SvJWSXbbbbKzLKew=; b=e6OzZZ3oU5WEsOkR3xbDbwDhu1L6szTqroIsYtJW9Ct3WSzJYPp7BhyjhOcu+mz9Gv +jfBZG/BI92wR/tKBpKtRrhffUbKzVB+Z65b3aUiEZQhjEfem8Xk80NAwHdgHCPSARww h8eTBbQh6puELLNqWk1hr11tju/ZsBdLPjMK+F/y98QX2QtCBs5935xHzDGpv4NKBcyz Oxhey2Y+F3gOTj3jNv5kSG3TroVf+ISOQhdEm92qM2xbod+O0dzJpcLw5ldS9tQ9vZ16 RC4wnrPmqc+DbXfDp9OQz3ti3QnZpXzCYnUdpFcQk6viJbeVuuhiC0KOGS1VooxaYZpF THSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=Zc89bCqsqTvavOT7c7LPUg/82y7SvJWSXbbbbKzLKew=; b=GI3mvtABOtWMOVGtEu46kS1lQI9mSxZrHS9QP3OZkzIGplbBgyU89NvoFw7Gxh9gwo LG+2H1gewxZbWjwh4SmFzMTXvkvPCLBQPpsFpnfzXFoqUqUg77ZfBDRo/BmrS4v4SbLh LI2pO68OxvwwzDeJeBOot4aLTjmgdPv4+hpfuhlK6Q8QKtdY7SQPv1KvayhzoyiYFMvV hoeFQNr7NzJc8NEtLx19Z6qBzuynqPRpnJhTNHyRkDCrrt0aCcIQQzVSFSXdiLIp/lyO A26fUNdJhQnRkUhB4POuDalmfKylJ0dqktLHi+MQkqCxt+QKWmTQvVWoRv4Jg0ZxGUCz nnJw== X-Gm-Message-State: AKwxyteKpc2P/C5L6vHtUAKEx29DEmp5gGFZJs+rFT1bN7w5x7ZfwV2e zqQ0RfOcDsXg4CbHd9Rrt6E5sHDt X-Google-Smtp-Source: AH8x224cTd34sLCHse4dj8cB4nozKjt3uahMAH+YXf1UeXNXD0Xi3cLi/Pl6TcKgiM0rweMsXpJxVQ== X-Received: by 10.36.254.4 with SMTP id w4mr7805170ith.80.1517205389497; Sun, 28 Jan 2018 21:56:29 -0800 (PST) Received: from [192.168.1.15] (45-19-167-161.lightspeed.irvnca.sbcglobal.net. [45.19.167.161]) by smtp.googlemail.com with ESMTPSA id s70sm7012402itb.0.2018.01.28.21.56.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 21:56:28 -0800 (PST) To: pgsql-general From: "Igal @ Lucee.org" Subject: Consider Spaces in pg_trgm for Better Similarity Message-ID: Date: Sun, 28 Jan 2018 21:56:26 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------BB95A6730EAC0BA0CA7FD661" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------BB95A6730EAC0BA0CA7FD661 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Is there a way to consider white space in tri-grams?  That would allow for better matches of phrases. For example, currently "one two three" and "three two one" would generate the same tri-grams ({  o,  t, on, th, tw,ee ,hre,ne ,one,ree,thr,two,wo }), and the distance of "one two four" will be the same for both of them.  The query: SELECT   phrase         ,input         ,similarity(t1.phrase, t2.input)         ,word_similarity(t1.phrase, t2.input) FROM      (values('one two three'),('three two one')) t1(phrase)         ,(values('one two four')) t2(input); Returns: phrase        |input        |similarity  |word_similarity | --------------|-------------|------------|----------------| one two three |one two four |0.444444448 |0.615384638 | three two one |one two four |0.444444448 |0.615384638 | But surely "one two four" is more similar to "one two three" than to "three two one". Any thoughts? Igal Sapir Lucee Core Developer Lucee.org --------------BB95A6730EAC0BA0CA7FD661 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Is there a way to consider white space in tri-grams?  That would allow for better matches of phrases. 

For example, currently "one two three" and "three two one" would generate the same tri-grams ({  o,  t, on, th, tw,ee ,hre,ne ,one,ree,thr,two,wo }), and the distance of "one two four" will be the same for both of them.  The query:

SELECT   phrase
        ,input
        ,similarity(t1.phrase, t2.input)
        ,word_similarity(t1.phrase, t2.input)
FROM      (values('one two three'),('three two one')) t1(phrase)
        ,(values('one two four')) t2(input);

Returns:

phrase        |input        |similarity  |word_similarity |
--------------|-------------|------------|----------------|
one two three |one two four |0.444444448 |0.615384638     |
three two one |one two four |0.444444448 |0.615384638     |

But surely "one two four" is more similar to "one two three" than to "three two one".

Any thoughts?

Igal Sapir
Lucee Core Developer
Lucee.org

--------------BB95A6730EAC0BA0CA7FD661--