Re: Fuzzy substring searching with the pg_trgm extension

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fuzzy substring searching with the pg_trgm extension
Date: 2016-02-25 22:00:51
Message-ID: CAMkU=1zREk5a4g=d134q6J0VnV4H9s4YZHFA0owLbaD3ghHizQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jan 29, 2016 at 6:15 AM, Teodor Sigaev <teodor(at)sigaev(dot)ru> wrote:
>> The behavior of this function is surprising to me.
>>
>> select substring_similarity('dog' , 'hotdogpound') ;
>>
>> substring_similarity
>> ----------------------
>> 0.25
>>
> Substring search was desined to search similar word in string:
> contrib_regression=# select substring_similarity('dog' , 'hot dogpound') ;
> substring_similarity
> ----------------------
> 0.75
>
> contrib_regression=# select substring_similarity('dog' , 'hot dog pound') ;
> substring_similarity
> ----------------------
> 1
> It seems to me that users search words in long string. But I'm agree that
> more detailed explanation needed and, may be, we need to change feature name
> to fuzzywordsearch or something else, I can't imagine how.

If we implement my proposed behavior, and I wanted the existing
behavior instead, I could just do:

select substring_similarity(' dog ' , 'hotdogpound');

But with the existing implementation, there isn't anything I could to
switch to the one I want instead. So treating is purely as a substring
is more flexible than treating it as a word match.

The reason I like the option of not treating word boundaries as
special in this case is that often in scientific vocabulary, and in
catalog part numbers, people are pretty inconsistent about whether
they included spaces. "HEK 293", "HEK293", and "HEK-293" could be all
the same thing. So I like to strip out spaces and punctuation on both
sides of operator. Of course I can't do that if there are invisible
un-removable spaces on the substring side.

But, It doesn't sound like I am going to win that debate. Given that,
I don't think we need a different name for the function. I'm fine with
explaining the word-boundary subtlety in the documentation, and
keeping the function name itself simple.

Cheers,

Jeff

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-02-25 22:10:03 Re: Password identifiers, protocol aging and SCRAM protocol
Previous Message Vitaly Burovoy 2016-02-25 21:44:26 Re: [PATCH] Integer overflow in timestamp[tz]_part() and date/time boundaries check