Re: Fwd: [BUGS] pg_trgm word_similarity inconsistencies or bug - Mailing list pgsql-bugs

From Alexander Korotkov
Subject Re: Fwd: [BUGS] pg_trgm word_similarity inconsistencies or bug
Date
Msg-id CAPpHfdv1oYVxCmLxyEGNH7vb3Fy2s0xHdv9R_NUy5EHecUqijQ@mail.gmail.com
Whole thread Raw
In response to Re: Fwd: [BUGS] pg_trgm word_similarity inconsistencies or bug  (Teodor Sigaev <teodor@sigaev.ru>)
Responses Re: Fwd: [BUGS] pg_trgm word_similarity inconsistencies or bug  (Alexander Korotkov <a.korotkov@postgrespro.ru>)
Re: Fwd: [BUGS] pg_trgm word_similarity inconsistencies or bug  (Alexander Korotkov <a.korotkov@postgrespro.ru>)
List pgsql-bugs
On Tue, Dec 12, 2017 at 2:33 PM, Teodor Sigaev <teodor@sigaev.ru> wrote:
0002-pg-trgm-strict_word-similarity.patch – implementation of strict_word_similarity() with comments, docs and tests.
After some looking in

1)
repeated piece of code:
+           if (strategy == SimilarityStrategyNumber)
+               nlimit = similarity_threshold;
+           else if (strategy == WordSimilarityStrategyNumber)
+               nlimit = word_similarity_threshold;
+           else /* strategy == StrictWordSimilarityStrategyNumber */
+               nlimit = strict_word_similarity_threshold;
Isn't it better to move that piece to separate function?
 
Good point.  Moved to separate function.

2)
calc_word_similarity(char *str1, int slen1, char *str2, int slen2,
                     bool check_only, bool word_bounds)

Seems, two bools args are replaceble to  bitwise-ORed flag. It will simplify adding new options in future.

Yep.  I've introduced flags.

Also, I've adjusted tests to make them stable (found example where TOP-8 distances are unique).
Please, find revised patch in attachment.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company 
Attachment

pgsql-bugs by date:

Previous
From: Patrik Martinsson
Date:
Subject: Re: BUG #14967: Postgresql won't start after upgrade from postgresql93-9.3.20-1PGDG.rhel7.x86_64
Next
From: Olga Lytvynova-Bogdanova
Date:
Subject: VARBIT question