]> granicus.if.org Git - postgresql/commitdiff
trgm - Trigram matching for PostgreSQL
authorTeodor Sigaev <teodor@sigaev.ru>
Mon, 31 May 2004 17:18:12 +0000 (17:18 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Mon, 31 May 2004 17:18:12 +0000 (17:18 +0000)
--------------------------------------

The pg_trgm contrib module provides functions and index classes
for determining the similarity of text based on trigram
matching.

contrib/pg_trgm/Makefile [new file with mode: 0644]
contrib/pg_trgm/README.pg_trgm [new file with mode: 0644]
contrib/pg_trgm/data/trgm.data [new file with mode: 0644]
contrib/pg_trgm/expected/pg_trgm.out [new file with mode: 0644]
contrib/pg_trgm/pg_trgm.sql.in [new file with mode: 0644]
contrib/pg_trgm/sql/pg_trgm.sql [new file with mode: 0644]
contrib/pg_trgm/trgm.h [new file with mode: 0644]
contrib/pg_trgm/trgm_gist.c [new file with mode: 0644]
contrib/pg_trgm/trgm_op.c [new file with mode: 0644]

diff --git a/contrib/pg_trgm/Makefile b/contrib/pg_trgm/Makefile
new file mode 100644 (file)
index 0000000..a2df4dd
--- /dev/null
@@ -0,0 +1,17 @@
+subdir = contrib/pg_trgm
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+
+
+override CPPFLAGS := -I. $(CPPFLAGS)
+
+MODULE_big = pg_trgm
+OBJS = trgm_op.o trgm_gist.o 
+
+DATA_built = pg_trgm.sql
+DOCS = README.pg_trgm
+REGRESS = pg_trgm
+
+include $(top_srcdir)/contrib/contrib-global.mk
+# DO NOT DELETE
+
diff --git a/contrib/pg_trgm/README.pg_trgm b/contrib/pg_trgm/README.pg_trgm
new file mode 100644 (file)
index 0000000..ac2eb01
--- /dev/null
@@ -0,0 +1,138 @@
+trgm - Trigram matching for PostgreSQL
+--------------------------------------
+
+Introduction
+
+       This module is sponsored by Delta-Soft Ltd., Moscow, Russia.
+
+       The pg_trgm contrib module provides functions and index classes
+       for determining the similarity of text based on trigram
+       matching.
+
+Definitions
+
+       Trigram (or Trigraph)
+
+       A trigram is a set of three consecutive characters taken
+       from a string.  A string is considered to have two spaces
+       prefixed and one space suffixed when determining the set
+       of trigrams that comprise the string.
+
+       eg. The set of trigrams in the word "cat" is "  c", " ca", 
+       "at " and "cat".
+
+Public Functions
+
+       real similarity(text, text)
+
+       Returns a number that indicates how closely matches the two
+       arguments are.  A zero result indicates that the two words
+       are completely dissimilar, and a result of one indicates that
+       the two words are identical.
+
+       real show_limit()
+
+       Returns the current similarity threshold used by the '%'
+       operator.  This in effect sets the minimum similarity between
+       two words in order that they be considered similar enough to
+       be misspellings of each other, for example.
+
+       real set_limit(real)
+
+       Sets the current similarity threshold that is used by the '%'
+       operator, and is returned by the show_limit() function.
+
+       text[] show_trgm(text)
+
+       Returns an array of all the trigrams of the supplied text
+       parameter.
+
+Public Operators
+
+       text % text (returns boolean)
+
+       The '%' operator returns TRUE if its two arguments have a similarity
+       that is greater than the similarity threshold set by set_limit(). It
+       will return FALSE if the similarity is less than the current
+       threshold.
+
+Public Index Operator Classes
+
+       gist_trgm_ops
+
+       The pg_trgm module comes with an index operator class that allows a
+       developer to create an index over a text column for the purpose
+       of very fast similarity searches.
+
+       To use this index, the '%' operator must be used and an appropriate
+       similarity threshold for the application must be set.
+
+       eg.
+
+       CREATE TABLE test_trgm (t text);
+       CREATE INDEX trgm_idx ON test_trgm USING gist (t gist_trgm_ops);
+       
+       At this point, you will have an index on the t text column that you
+       can use for similarity searching.
+
+       eg.
+
+       SELECT
+               t,
+               similarity(t, 'word') AS sml
+       FROM
+               test_trgm
+       WHERE
+               t % 'word'
+       ORDER BY
+               sml DESC, t;
+
+       This will return all values in the text column that are sufficiently
+       similar to 'word', sorted from best match to worst.  The index will
+       be used to make this a fast operation over very large data sets.
+
+Tsearch2 Integration
+
+       Trigram matching is a very useful tool when used in conjunction
+       with a text index created by the Tsearch2 contrib module. (See
+       contrib/tsearch2)
+
+       The first step is to generate an auxiliary table containing all
+       the unique words in the Tsearch2 index:
+
+       CREATE TABLE words AS 
+               SELECT word FROM stat('SELECT vector FROM documents');
+
+       Where 'documents' is the table that contains the Tsearch2 index
+       column 'vector', of type 'tsvector'.
+
+       Next, create a trigram index on the word column:
+
+       CREATE INDEX words_idx ON words USING gist(word gist_trgm_ops);
+
+       Now, a SELECT query similar to the example above can be used to
+       suggest spellings for misspelled words in user search terms. A
+       useful extra clause is to ensure that the similar words are also
+       of similar length to the misspelled word.
+
+       Note: Since the 'words' table has been generated as a separate,
+       static table, it will need to be periodically regenerated so that
+       it remains up to date with the word list in the Tsearch2 index.
+
+Authors
+
+       Oleg Bartunov <oleg@sai.msu.su>, Moscow, Moscow University, Russia
+       Teodor Sigaev <teodor@sigaev.ru>, Moscow, Delta-Soft Ltd.,Russia
+       
+Contributors
+
+       Christopher Kings-Lynne wrote this README file
+
+References
+
+       Tsearch2 Development Site
+       http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/
+       
+       GiST Development Site
+       http://www.sai.msu.su/~megera/postgres/gist/
+
diff --git a/contrib/pg_trgm/data/trgm.data b/contrib/pg_trgm/data/trgm.data
new file mode 100644 (file)
index 0000000..37319d6
--- /dev/null
@@ -0,0 +1,1000 @@
+qwertyu0001
+qwertyu0002
+qwertyu0003
+qwertyu0004
+qwertyu0005
+qwertyu0006
+qwertyu0007
+qwertyu0008
+qwertyu0009
+qwertyu0010
+qwertyu0011
+qwertyu0012
+qwertyu0013
+qwertyu0014
+qwertyu0015
+qwertyu0016
+qwertyu0017
+qwertyu0018
+qwertyu0019
+qwertyu0020
+qwertyu0021
+qwertyu0022
+qwertyu0023
+qwertyu0024
+qwertyu0025
+qwertyu0026
+qwertyu0027
+qwertyu0028
+qwertyu0029
+qwertyu0030
+qwertyu0031
+qwertyu0032
+qwertyu0033
+qwertyu0034
+qwertyu0035
+qwertyu0036
+qwertyu0037
+qwertyu0038
+qwertyu0039
+qwertyu0040
+qwertyu0041
+qwertyu0042
+qwertyu0043
+qwertyu0044
+qwertyu0045
+qwertyu0046
+qwertyu0047
+qwertyu0048
+qwertyu0049
+qwertyu0050
+qwertyu0051
+qwertyu0052
+qwertyu0053
+qwertyu0054
+qwertyu0055
+qwertyu0056
+qwertyu0057
+qwertyu0058
+qwertyu0059
+qwertyu0060
+qwertyu0061
+qwertyu0062
+qwertyu0063
+qwertyu0064
+qwertyu0065
+qwertyu0066
+qwertyu0067
+qwertyu0068
+qwertyu0069
+qwertyu0070
+qwertyu0071
+qwertyu0072
+qwertyu0073
+qwertyu0074
+qwertyu0075
+qwertyu0076
+qwertyu0077
+qwertyu0078
+qwertyu0079
+qwertyu0080
+qwertyu0081
+qwertyu0082
+qwertyu0083
+qwertyu0084
+qwertyu0085
+qwertyu0086
+qwertyu0087
+qwertyu0088
+qwertyu0089
+qwertyu0090
+qwertyu0091
+qwertyu0092
+qwertyu0093
+qwertyu0094
+qwertyu0095
+qwertyu0096
+qwertyu0097
+qwertyu0098
+qwertyu0099
+qwertyu0100
+qwertyu0101
+qwertyu0102
+qwertyu0103
+qwertyu0104
+qwertyu0105
+qwertyu0106
+qwertyu0107
+qwertyu0108
+qwertyu0109
+qwertyu0110
+qwertyu0111
+qwertyu0112
+qwertyu0113
+qwertyu0114
+qwertyu0115
+qwertyu0116
+qwertyu0117
+qwertyu0118
+qwertyu0119
+qwertyu0120
+qwertyu0121
+qwertyu0122
+qwertyu0123
+qwertyu0124
+qwertyu0125
+qwertyu0126
+qwertyu0127
+qwertyu0128
+qwertyu0129
+qwertyu0130
+qwertyu0131
+qwertyu0132
+qwertyu0133
+qwertyu0134
+qwertyu0135
+qwertyu0136
+qwertyu0137
+qwertyu0138
+qwertyu0139
+qwertyu0140
+qwertyu0141
+qwertyu0142
+qwertyu0143
+qwertyu0144
+qwertyu0145
+qwertyu0146
+qwertyu0147
+qwertyu0148
+qwertyu0149
+qwertyu0150
+qwertyu0151
+qwertyu0152
+qwertyu0153
+qwertyu0154
+qwertyu0155
+qwertyu0156
+qwertyu0157
+qwertyu0158
+qwertyu0159
+qwertyu0160
+qwertyu0161
+qwertyu0162
+qwertyu0163
+qwertyu0164
+qwertyu0165
+qwertyu0166
+qwertyu0167
+qwertyu0168
+qwertyu0169
+qwertyu0170
+qwertyu0171
+qwertyu0172
+qwertyu0173
+qwertyu0174
+qwertyu0175
+qwertyu0176
+qwertyu0177
+qwertyu0178
+qwertyu0179
+qwertyu0180
+qwertyu0181
+qwertyu0182
+qwertyu0183
+qwertyu0184
+qwertyu0185
+qwertyu0186
+qwertyu0187
+qwertyu0188
+qwertyu0189
+qwertyu0190
+qwertyu0191
+qwertyu0192
+qwertyu0193
+qwertyu0194
+qwertyu0195
+qwertyu0196
+qwertyu0197
+qwertyu0198
+qwertyu0199
+qwertyu0200
+qwertyu0201
+qwertyu0202
+qwertyu0203
+qwertyu0204
+qwertyu0205
+qwertyu0206
+qwertyu0207
+qwertyu0208
+qwertyu0209
+qwertyu0210
+qwertyu0211
+qwertyu0212
+qwertyu0213
+qwertyu0214
+qwertyu0215
+qwertyu0216
+qwertyu0217
+qwertyu0218
+qwertyu0219
+qwertyu0220
+qwertyu0221
+qwertyu0222
+qwertyu0223
+qwertyu0224
+qwertyu0225
+qwertyu0226
+qwertyu0227
+qwertyu0228
+qwertyu0229
+qwertyu0230
+qwertyu0231
+qwertyu0232
+qwertyu0233
+qwertyu0234
+qwertyu0235
+qwertyu0236
+qwertyu0237
+qwertyu0238
+qwertyu0239
+qwertyu0240
+qwertyu0241
+qwertyu0242
+qwertyu0243
+qwertyu0244
+qwertyu0245
+qwertyu0246
+qwertyu0247
+qwertyu0248
+qwertyu0249
+qwertyu0250
+qwertyu0251
+qwertyu0252
+qwertyu0253
+qwertyu0254
+qwertyu0255
+qwertyu0256
+qwertyu0257
+qwertyu0258
+qwertyu0259
+qwertyu0260
+qwertyu0261
+qwertyu0262
+qwertyu0263
+qwertyu0264
+qwertyu0265
+qwertyu0266
+qwertyu0267
+qwertyu0268
+qwertyu0269
+qwertyu0270
+qwertyu0271
+qwertyu0272
+qwertyu0273
+qwertyu0274
+qwertyu0275
+qwertyu0276
+qwertyu0277
+qwertyu0278
+qwertyu0279
+qwertyu0280
+qwertyu0281
+qwertyu0282
+qwertyu0283
+qwertyu0284
+qwertyu0285
+qwertyu0286
+qwertyu0287
+qwertyu0288
+qwertyu0289
+qwertyu0290
+qwertyu0291
+qwertyu0292
+qwertyu0293
+qwertyu0294
+qwertyu0295
+qwertyu0296
+qwertyu0297
+qwertyu0298
+qwertyu0299
+qwertyu0300
+qwertyu0301
+qwertyu0302
+qwertyu0303
+qwertyu0304
+qwertyu0305
+qwertyu0306
+qwertyu0307
+qwertyu0308
+qwertyu0309
+qwertyu0310
+qwertyu0311
+qwertyu0312
+qwertyu0313
+qwertyu0314
+qwertyu0315
+qwertyu0316
+qwertyu0317
+qwertyu0318
+qwertyu0319
+qwertyu0320
+qwertyu0321
+qwertyu0322
+qwertyu0323
+qwertyu0324
+qwertyu0325
+qwertyu0326
+qwertyu0327
+qwertyu0328
+qwertyu0329
+qwertyu0330
+qwertyu0331
+qwertyu0332
+qwertyu0333
+qwertyu0334
+qwertyu0335
+qwertyu0336
+qwertyu0337
+qwertyu0338
+qwertyu0339
+qwertyu0340
+qwertyu0341
+qwertyu0342
+qwertyu0343
+qwertyu0344
+qwertyu0345
+qwertyu0346
+qwertyu0347
+qwertyu0348
+qwertyu0349
+qwertyu0350
+qwertyu0351
+qwertyu0352
+qwertyu0353
+qwertyu0354
+qwertyu0355
+qwertyu0356
+qwertyu0357
+qwertyu0358
+qwertyu0359
+qwertyu0360
+qwertyu0361
+qwertyu0362
+qwertyu0363
+qwertyu0364
+qwertyu0365
+qwertyu0366
+qwertyu0367
+qwertyu0368
+qwertyu0369
+qwertyu0370
+qwertyu0371
+qwertyu0372
+qwertyu0373
+qwertyu0374
+qwertyu0375
+qwertyu0376
+qwertyu0377
+qwertyu0378
+qwertyu0379
+qwertyu0380
+qwertyu0381
+qwertyu0382
+qwertyu0383
+qwertyu0384
+qwertyu0385
+qwertyu0386
+qwertyu0387
+qwertyu0388
+qwertyu0389
+qwertyu0390
+qwertyu0391
+qwertyu0392
+qwertyu0393
+qwertyu0394
+qwertyu0395
+qwertyu0396
+qwertyu0397
+qwertyu0398
+qwertyu0399
+qwertyu0400
+qwertyu0401
+qwertyu0402
+qwertyu0403
+qwertyu0404
+qwertyu0405
+qwertyu0406
+qwertyu0407
+qwertyu0408
+qwertyu0409
+qwertyu0410
+qwertyu0411
+qwertyu0412
+qwertyu0413
+qwertyu0414
+qwertyu0415
+qwertyu0416
+qwertyu0417
+qwertyu0418
+qwertyu0419
+qwertyu0420
+qwertyu0421
+qwertyu0422
+qwertyu0423
+qwertyu0424
+qwertyu0425
+qwertyu0426
+qwertyu0427
+qwertyu0428
+qwertyu0429
+qwertyu0430
+qwertyu0431
+qwertyu0432
+qwertyu0433
+qwertyu0434
+qwertyu0435
+qwertyu0436
+qwertyu0437
+qwertyu0438
+qwertyu0439
+qwertyu0440
+qwertyu0441
+qwertyu0442
+qwertyu0443
+qwertyu0444
+qwertyu0445
+qwertyu0446
+qwertyu0447
+qwertyu0448
+qwertyu0449
+qwertyu0450
+qwertyu0451
+qwertyu0452
+qwertyu0453
+qwertyu0454
+qwertyu0455
+qwertyu0456
+qwertyu0457
+qwertyu0458
+qwertyu0459
+qwertyu0460
+qwertyu0461
+qwertyu0462
+qwertyu0463
+qwertyu0464
+qwertyu0465
+qwertyu0466
+qwertyu0467
+qwertyu0468
+qwertyu0469
+qwertyu0470
+qwertyu0471
+qwertyu0472
+qwertyu0473
+qwertyu0474
+qwertyu0475
+qwertyu0476
+qwertyu0477
+qwertyu0478
+qwertyu0479
+qwertyu0480
+qwertyu0481
+qwertyu0482
+qwertyu0483
+qwertyu0484
+qwertyu0485
+qwertyu0486
+qwertyu0487
+qwertyu0488
+qwertyu0489
+qwertyu0490
+qwertyu0491
+qwertyu0492
+qwertyu0493
+qwertyu0494
+qwertyu0495
+qwertyu0496
+qwertyu0497
+qwertyu0498
+qwertyu0499
+qwertyu0500
+qwertyu0501
+qwertyu0502
+qwertyu0503
+qwertyu0504
+qwertyu0505
+qwertyu0506
+qwertyu0507
+qwertyu0508
+qwertyu0509
+qwertyu0510
+qwertyu0511
+qwertyu0512
+qwertyu0513
+qwertyu0514
+qwertyu0515
+qwertyu0516
+qwertyu0517
+qwertyu0518
+qwertyu0519
+qwertyu0520
+qwertyu0521
+qwertyu0522
+qwertyu0523
+qwertyu0524
+qwertyu0525
+qwertyu0526
+qwertyu0527
+qwertyu0528
+qwertyu0529
+qwertyu0530
+qwertyu0531
+qwertyu0532
+qwertyu0533
+qwertyu0534
+qwertyu0535
+qwertyu0536
+qwertyu0537
+qwertyu0538
+qwertyu0539
+qwertyu0540
+qwertyu0541
+qwertyu0542
+qwertyu0543
+qwertyu0544
+qwertyu0545
+qwertyu0546
+qwertyu0547
+qwertyu0548
+qwertyu0549
+qwertyu0550
+qwertyu0551
+qwertyu0552
+qwertyu0553
+qwertyu0554
+qwertyu0555
+qwertyu0556
+qwertyu0557
+qwertyu0558
+qwertyu0559
+qwertyu0560
+qwertyu0561
+qwertyu0562
+qwertyu0563
+qwertyu0564
+qwertyu0565
+qwertyu0566
+qwertyu0567
+qwertyu0568
+qwertyu0569
+qwertyu0570
+qwertyu0571
+qwertyu0572
+qwertyu0573
+qwertyu0574
+qwertyu0575
+qwertyu0576
+qwertyu0577
+qwertyu0578
+qwertyu0579
+qwertyu0580
+qwertyu0581
+qwertyu0582
+qwertyu0583
+qwertyu0584
+qwertyu0585
+qwertyu0586
+qwertyu0587
+qwertyu0588
+qwertyu0589
+qwertyu0590
+qwertyu0591
+qwertyu0592
+qwertyu0593
+qwertyu0594
+qwertyu0595
+qwertyu0596
+qwertyu0597
+qwertyu0598
+qwertyu0599
+qwertyu0600
+qwertyu0601
+qwertyu0602
+qwertyu0603
+qwertyu0604
+qwertyu0605
+qwertyu0606
+qwertyu0607
+qwertyu0608
+qwertyu0609
+qwertyu0610
+qwertyu0611
+qwertyu0612
+qwertyu0613
+qwertyu0614
+qwertyu0615
+qwertyu0616
+qwertyu0617
+qwertyu0618
+qwertyu0619
+qwertyu0620
+qwertyu0621
+qwertyu0622
+qwertyu0623
+qwertyu0624
+qwertyu0625
+qwertyu0626
+qwertyu0627
+qwertyu0628
+qwertyu0629
+qwertyu0630
+qwertyu0631
+qwertyu0632
+qwertyu0633
+qwertyu0634
+qwertyu0635
+qwertyu0636
+qwertyu0637
+qwertyu0638
+qwertyu0639
+qwertyu0640
+qwertyu0641
+qwertyu0642
+qwertyu0643
+qwertyu0644
+qwertyu0645
+qwertyu0646
+qwertyu0647
+qwertyu0648
+qwertyu0649
+qwertyu0650
+qwertyu0651
+qwertyu0652
+qwertyu0653
+qwertyu0654
+qwertyu0655
+qwertyu0656
+qwertyu0657
+qwertyu0658
+qwertyu0659
+qwertyu0660
+qwertyu0661
+qwertyu0662
+qwertyu0663
+qwertyu0664
+qwertyu0665
+qwertyu0666
+qwertyu0667
+qwertyu0668
+qwertyu0669
+qwertyu0670
+qwertyu0671
+qwertyu0672
+qwertyu0673
+qwertyu0674
+qwertyu0675
+qwertyu0676
+qwertyu0677
+qwertyu0678
+qwertyu0679
+qwertyu0680
+qwertyu0681
+qwertyu0682
+qwertyu0683
+qwertyu0684
+qwertyu0685
+qwertyu0686
+qwertyu0687
+qwertyu0688
+qwertyu0689
+qwertyu0690
+qwertyu0691
+qwertyu0692
+qwertyu0693
+qwertyu0694
+qwertyu0695
+qwertyu0696
+qwertyu0697
+qwertyu0698
+qwertyu0699
+qwertyu0700
+qwertyu0701
+qwertyu0702
+qwertyu0703
+qwertyu0704
+qwertyu0705
+qwertyu0706
+qwertyu0707
+qwertyu0708
+qwertyu0709
+qwertyu0710
+qwertyu0711
+qwertyu0712
+qwertyu0713
+qwertyu0714
+qwertyu0715
+qwertyu0716
+qwertyu0717
+qwertyu0718
+qwertyu0719
+qwertyu0720
+qwertyu0721
+qwertyu0722
+qwertyu0723
+qwertyu0724
+qwertyu0725
+qwertyu0726
+qwertyu0727
+qwertyu0728
+qwertyu0729
+qwertyu0730
+qwertyu0731
+qwertyu0732
+qwertyu0733
+qwertyu0734
+qwertyu0735
+qwertyu0736
+qwertyu0737
+qwertyu0738
+qwertyu0739
+qwertyu0740
+qwertyu0741
+qwertyu0742
+qwertyu0743
+qwertyu0744
+qwertyu0745
+qwertyu0746
+qwertyu0747
+qwertyu0748
+qwertyu0749
+qwertyu0750
+qwertyu0751
+qwertyu0752
+qwertyu0753
+qwertyu0754
+qwertyu0755
+qwertyu0756
+qwertyu0757
+qwertyu0758
+qwertyu0759
+qwertyu0760
+qwertyu0761
+qwertyu0762
+qwertyu0763
+qwertyu0764
+qwertyu0765
+qwertyu0766
+qwertyu0767
+qwertyu0768
+qwertyu0769
+qwertyu0770
+qwertyu0771
+qwertyu0772
+qwertyu0773
+qwertyu0774
+qwertyu0775
+qwertyu0776
+qwertyu0777
+qwertyu0778
+qwertyu0779
+qwertyu0780
+qwertyu0781
+qwertyu0782
+qwertyu0783
+qwertyu0784
+qwertyu0785
+qwertyu0786
+qwertyu0787
+qwertyu0788
+qwertyu0789
+qwertyu0790
+qwertyu0791
+qwertyu0792
+qwertyu0793
+qwertyu0794
+qwertyu0795
+qwertyu0796
+qwertyu0797
+qwertyu0798
+qwertyu0799
+qwertyu0800
+qwertyu0801
+qwertyu0802
+qwertyu0803
+qwertyu0804
+qwertyu0805
+qwertyu0806
+qwertyu0807
+qwertyu0808
+qwertyu0809
+qwertyu0810
+qwertyu0811
+qwertyu0812
+qwertyu0813
+qwertyu0814
+qwertyu0815
+qwertyu0816
+qwertyu0817
+qwertyu0818
+qwertyu0819
+qwertyu0820
+qwertyu0821
+qwertyu0822
+qwertyu0823
+qwertyu0824
+qwertyu0825
+qwertyu0826
+qwertyu0827
+qwertyu0828
+qwertyu0829
+qwertyu0830
+qwertyu0831
+qwertyu0832
+qwertyu0833
+qwertyu0834
+qwertyu0835
+qwertyu0836
+qwertyu0837
+qwertyu0838
+qwertyu0839
+qwertyu0840
+qwertyu0841
+qwertyu0842
+qwertyu0843
+qwertyu0844
+qwertyu0845
+qwertyu0846
+qwertyu0847
+qwertyu0848
+qwertyu0849
+qwertyu0850
+qwertyu0851
+qwertyu0852
+qwertyu0853
+qwertyu0854
+qwertyu0855
+qwertyu0856
+qwertyu0857
+qwertyu0858
+qwertyu0859
+qwertyu0860
+qwertyu0861
+qwertyu0862
+qwertyu0863
+qwertyu0864
+qwertyu0865
+qwertyu0866
+qwertyu0867
+qwertyu0868
+qwertyu0869
+qwertyu0870
+qwertyu0871
+qwertyu0872
+qwertyu0873
+qwertyu0874
+qwertyu0875
+qwertyu0876
+qwertyu0877
+qwertyu0878
+qwertyu0879
+qwertyu0880
+qwertyu0881
+qwertyu0882
+qwertyu0883
+qwertyu0884
+qwertyu0885
+qwertyu0886
+qwertyu0887
+qwertyu0888
+qwertyu0889
+qwertyu0890
+qwertyu0891
+qwertyu0892
+qwertyu0893
+qwertyu0894
+qwertyu0895
+qwertyu0896
+qwertyu0897
+qwertyu0898
+qwertyu0899
+qwertyu0900
+qwertyu0901
+qwertyu0902
+qwertyu0903
+qwertyu0904
+qwertyu0905
+qwertyu0906
+qwertyu0907
+qwertyu0908
+qwertyu0909
+qwertyu0910
+qwertyu0911
+qwertyu0912
+qwertyu0913
+qwertyu0914
+qwertyu0915
+qwertyu0916
+qwertyu0917
+qwertyu0918
+qwertyu0919
+qwertyu0920
+qwertyu0921
+qwertyu0922
+qwertyu0923
+qwertyu0924
+qwertyu0925
+qwertyu0926
+qwertyu0927
+qwertyu0928
+qwertyu0929
+qwertyu0930
+qwertyu0931
+qwertyu0932
+qwertyu0933
+qwertyu0934
+qwertyu0935
+qwertyu0936
+qwertyu0937
+qwertyu0938
+qwertyu0939
+qwertyu0940
+qwertyu0941
+qwertyu0942
+qwertyu0943
+qwertyu0944
+qwertyu0945
+qwertyu0946
+qwertyu0947
+qwertyu0948
+qwertyu0949
+qwertyu0950
+qwertyu0951
+qwertyu0952
+qwertyu0953
+qwertyu0954
+qwertyu0955
+qwertyu0956
+qwertyu0957
+qwertyu0958
+qwertyu0959
+qwertyu0960
+qwertyu0961
+qwertyu0962
+qwertyu0963
+qwertyu0964
+qwertyu0965
+qwertyu0966
+qwertyu0967
+qwertyu0968
+qwertyu0969
+qwertyu0970
+qwertyu0971
+qwertyu0972
+qwertyu0973
+qwertyu0974
+qwertyu0975
+qwertyu0976
+qwertyu0977
+qwertyu0978
+qwertyu0979
+qwertyu0980
+qwertyu0981
+qwertyu0982
+qwertyu0983
+qwertyu0984
+qwertyu0985
+qwertyu0986
+qwertyu0987
+qwertyu0988
+qwertyu0989
+qwertyu0990
+qwertyu0991
+qwertyu0992
+qwertyu0993
+qwertyu0994
+qwertyu0995
+qwertyu0996
+qwertyu0997
+qwertyu0998
+qwertyu0999
+qwertyu1000
diff --git a/contrib/pg_trgm/expected/pg_trgm.out b/contrib/pg_trgm/expected/pg_trgm.out
new file mode 100644 (file)
index 0000000..f0697f6
--- /dev/null
@@ -0,0 +1,2314 @@
+\set ECHO none
+psql:pg_trgm.sql:43: NOTICE:  type "gtrgm" is not yet defined
+DETAIL:  Creating a shell type definition.
+psql:pg_trgm.sql:48: NOTICE:  argument type gtrgm is only a shell
+select show_trgm('');
+ show_trgm 
+-----------
+ {}
+(1 row)
+
+select show_trgm('(*&^$@%@');
+ show_trgm 
+-----------
+ {}
+(1 row)
+
+select show_trgm('a b c');
+               show_trgm               
+---------------------------------------
+ {"  a","  b","  c"," a "," b "," c "}
+(1 row)
+
+select show_trgm(' a b c ');
+               show_trgm               
+---------------------------------------
+ {"  a","  b","  c"," a "," b "," c "}
+(1 row)
+
+select show_trgm('aA bB cC');
+                        show_trgm                        
+---------------------------------------------------------
+ {"  a","  b","  c"," aa"," bb"," cc","aa ","bb ","cc "}
+(1 row)
+
+select show_trgm(' aA bB cC ');
+                        show_trgm                        
+---------------------------------------------------------
+ {"  a","  b","  c"," aa"," bb"," cc","aa ","bb ","cc "}
+(1 row)
+
+select show_trgm('a b C0*%^');
+                  show_trgm                  
+---------------------------------------------
+ {"  a","  b","  c"," a "," b "," c0","c0 "}
+(1 row)
+
+select similarity('wow','WOWa ');
+ similarity 
+------------
+        0.5
+(1 row)
+
+select similarity('wow',' WOW ');
+ similarity 
+------------
+          1
+(1 row)
+
+CREATE TABLE test_trgm(t text);
+\copy test_trgm from 'data/trgm.data
+select t,similarity(t,'qwertyu0988') as sml from test_trgm where t % 'qwertyu0988' order by sml desc, t;
+      t      |   sml    
+-------------+----------
+ qwertyu0988 |        1
+ qwertyu0980 | 0.714286
+ qwertyu0981 | 0.714286
+ qwertyu0982 | 0.714286
+ qwertyu0983 | 0.714286
+ qwertyu0984 | 0.714286
+ qwertyu0985 | 0.714286
+ qwertyu0986 | 0.714286
+ qwertyu0987 | 0.714286
+ qwertyu0989 | 0.714286
+ qwertyu0088 |      0.6
+ qwertyu0098 |      0.6
+ qwertyu0188 |      0.6
+ qwertyu0288 |      0.6
+ qwertyu0388 |      0.6
+ qwertyu0488 |      0.6
+ qwertyu0588 |      0.6
+ qwertyu0688 |      0.6
+ qwertyu0788 |      0.6
+ qwertyu0888 |      0.6
+ qwertyu0900 |      0.6
+ qwertyu0901 |      0.6
+ qwertyu0902 |      0.6
+ qwertyu0903 |      0.6
+ qwertyu0904 |      0.6
+ qwertyu0905 |      0.6
+ qwertyu0906 |      0.6
+ qwertyu0907 |      0.6
+ qwertyu0908 |      0.6
+ qwertyu0909 |      0.6
+ qwertyu0910 |      0.6
+ qwertyu0911 |      0.6
+ qwertyu0912 |      0.6
+ qwertyu0913 |      0.6
+ qwertyu0914 |      0.6
+ qwertyu0915 |      0.6
+ qwertyu0916 |      0.6
+ qwertyu0917 |      0.6
+ qwertyu0918 |      0.6
+ qwertyu0919 |      0.6
+ qwertyu0920 |      0.6
+ qwertyu0921 |      0.6
+ qwertyu0922 |      0.6
+ qwertyu0923 |      0.6
+ qwertyu0924 |      0.6
+ qwertyu0925 |      0.6
+ qwertyu0926 |      0.6
+ qwertyu0927 |      0.6
+ qwertyu0928 |      0.6
+ qwertyu0929 |      0.6
+ qwertyu0930 |      0.6
+ qwertyu0931 |      0.6
+ qwertyu0932 |      0.6
+ qwertyu0933 |      0.6
+ qwertyu0934 |      0.6
+ qwertyu0935 |      0.6
+ qwertyu0936 |      0.6
+ qwertyu0937 |      0.6
+ qwertyu0938 |      0.6
+ qwertyu0939 |      0.6
+ qwertyu0940 |      0.6
+ qwertyu0941 |      0.6
+ qwertyu0942 |      0.6
+ qwertyu0943 |      0.6
+ qwertyu0944 |      0.6
+ qwertyu0945 |      0.6
+ qwertyu0946 |      0.6
+ qwertyu0947 |      0.6
+ qwertyu0948 |      0.6
+ qwertyu0949 |      0.6
+ qwertyu0950 |      0.6
+ qwertyu0951 |      0.6
+ qwertyu0952 |      0.6
+ qwertyu0953 |      0.6
+ qwertyu0954 |      0.6
+ qwertyu0955 |      0.6
+ qwertyu0956 |      0.6
+ qwertyu0957 |      0.6
+ qwertyu0958 |      0.6
+ qwertyu0959 |      0.6
+ qwertyu0960 |      0.6
+ qwertyu0961 |      0.6
+ qwertyu0962 |      0.6
+ qwertyu0963 |      0.6
+ qwertyu0964 |      0.6
+ qwertyu0965 |      0.6
+ qwertyu0966 |      0.6
+ qwertyu0967 |      0.6
+ qwertyu0968 |      0.6
+ qwertyu0969 |      0.6
+ qwertyu0970 |      0.6
+ qwertyu0971 |      0.6
+ qwertyu0972 |      0.6
+ qwertyu0973 |      0.6
+ qwertyu0974 |      0.6
+ qwertyu0975 |      0.6
+ qwertyu0976 |      0.6
+ qwertyu0977 |      0.6
+ qwertyu0978 |      0.6
+ qwertyu0979 |      0.6
+ qwertyu0990 |      0.6
+ qwertyu0991 |      0.6
+ qwertyu0992 |      0.6
+ qwertyu0993 |      0.6
+ qwertyu0994 |      0.6
+ qwertyu0995 |      0.6
+ qwertyu0996 |      0.6
+ qwertyu0997 |      0.6
+ qwertyu0998 |      0.6
+ qwertyu0999 |      0.6
+ qwertyu0001 |      0.5
+ qwertyu0002 |      0.5
+ qwertyu0003 |      0.5
+ qwertyu0004 |      0.5
+ qwertyu0005 |      0.5
+ qwertyu0006 |      0.5
+ qwertyu0007 |      0.5
+ qwertyu0008 |      0.5
+ qwertyu0009 |      0.5
+ qwertyu0010 |      0.5
+ qwertyu0011 |      0.5
+ qwertyu0012 |      0.5
+ qwertyu0013 |      0.5
+ qwertyu0014 |      0.5
+ qwertyu0015 |      0.5
+ qwertyu0016 |      0.5
+ qwertyu0017 |      0.5
+ qwertyu0018 |      0.5
+ qwertyu0019 |      0.5
+ qwertyu0020 |      0.5
+ qwertyu0021 |      0.5
+ qwertyu0022 |      0.5
+ qwertyu0023 |      0.5
+ qwertyu0024 |      0.5
+ qwertyu0025 |      0.5
+ qwertyu0026 |      0.5
+ qwertyu0027 |      0.5
+ qwertyu0028 |      0.5
+ qwertyu0029 |      0.5
+ qwertyu0030 |      0.5
+ qwertyu0031 |      0.5
+ qwertyu0032 |      0.5
+ qwertyu0033 |      0.5
+ qwertyu0034 |      0.5
+ qwertyu0035 |      0.5
+ qwertyu0036 |      0.5
+ qwertyu0037 |      0.5
+ qwertyu0038 |      0.5
+ qwertyu0039 |      0.5
+ qwertyu0040 |      0.5
+ qwertyu0041 |      0.5
+ qwertyu0042 |      0.5
+ qwertyu0043 |      0.5
+ qwertyu0044 |      0.5
+ qwertyu0045 |      0.5
+ qwertyu0046 |      0.5
+ qwertyu0047 |      0.5
+ qwertyu0048 |      0.5
+ qwertyu0049 |      0.5
+ qwertyu0050 |      0.5
+ qwertyu0051 |      0.5
+ qwertyu0052 |      0.5
+ qwertyu0053 |      0.5
+ qwertyu0054 |      0.5
+ qwertyu0055 |      0.5
+ qwertyu0056 |      0.5
+ qwertyu0057 |      0.5
+ qwertyu0058 |      0.5
+ qwertyu0059 |      0.5
+ qwertyu0060 |      0.5
+ qwertyu0061 |      0.5
+ qwertyu0062 |      0.5
+ qwertyu0063 |      0.5
+ qwertyu0064 |      0.5
+ qwertyu0065 |      0.5
+ qwertyu0066 |      0.5
+ qwertyu0067 |      0.5
+ qwertyu0068 |      0.5
+ qwertyu0069 |      0.5
+ qwertyu0070 |      0.5
+ qwertyu0071 |      0.5
+ qwertyu0072 |      0.5
+ qwertyu0073 |      0.5
+ qwertyu0074 |      0.5
+ qwertyu0075 |      0.5
+ qwertyu0076 |      0.5
+ qwertyu0077 |      0.5
+ qwertyu0078 |      0.5
+ qwertyu0079 |      0.5
+ qwertyu0080 |      0.5
+ qwertyu0081 |      0.5
+ qwertyu0082 |      0.5
+ qwertyu0083 |      0.5
+ qwertyu0084 |      0.5
+ qwertyu0085 |      0.5
+ qwertyu0086 |      0.5
+ qwertyu0087 |      0.5
+ qwertyu0089 |      0.5
+ qwertyu0090 |      0.5
+ qwertyu0091 |      0.5
+ qwertyu0092 |      0.5
+ qwertyu0093 |      0.5
+ qwertyu0094 |      0.5
+ qwertyu0095 |      0.5
+ qwertyu0096 |      0.5
+ qwertyu0097 |      0.5
+ qwertyu0099 |      0.5
+ qwertyu0100 |      0.5
+ qwertyu0101 |      0.5
+ qwertyu0102 |      0.5
+ qwertyu0103 |      0.5
+ qwertyu0104 |      0.5
+ qwertyu0105 |      0.5
+ qwertyu0106 |      0.5
+ qwertyu0107 |      0.5
+ qwertyu0108 |      0.5
+ qwertyu0109 |      0.5
+ qwertyu0110 |      0.5
+ qwertyu0111 |      0.5
+ qwertyu0112 |      0.5
+ qwertyu0113 |      0.5
+ qwertyu0114 |      0.5
+ qwertyu0115 |      0.5
+ qwertyu0116 |      0.5
+ qwertyu0117 |      0.5
+ qwertyu0118 |      0.5
+ qwertyu0119 |      0.5
+ qwertyu0120 |      0.5
+ qwertyu0121 |      0.5
+ qwertyu0122 |      0.5
+ qwertyu0123 |      0.5
+ qwertyu0124 |      0.5
+ qwertyu0125 |      0.5
+ qwertyu0126 |      0.5
+ qwertyu0127 |      0.5
+ qwertyu0128 |      0.5
+ qwertyu0129 |      0.5
+ qwertyu0130 |      0.5
+ qwertyu0131 |      0.5
+ qwertyu0132 |      0.5
+ qwertyu0133 |      0.5
+ qwertyu0134 |      0.5
+ qwertyu0135 |      0.5
+ qwertyu0136 |      0.5
+ qwertyu0137 |      0.5
+ qwertyu0138 |      0.5
+ qwertyu0139 |      0.5
+ qwertyu0140 |      0.5
+ qwertyu0141 |      0.5
+ qwertyu0142 |      0.5
+ qwertyu0143 |      0.5
+ qwertyu0144 |      0.5
+ qwertyu0145 |      0.5
+ qwertyu0146 |      0.5
+ qwertyu0147 |      0.5
+ qwertyu0148 |      0.5
+ qwertyu0149 |      0.5
+ qwertyu0150 |      0.5
+ qwertyu0151 |      0.5
+ qwertyu0152 |      0.5
+ qwertyu0153 |      0.5
+ qwertyu0154 |      0.5
+ qwertyu0155 |      0.5
+ qwertyu0156 |      0.5
+ qwertyu0157 |      0.5
+ qwertyu0158 |      0.5
+ qwertyu0159 |      0.5
+ qwertyu0160 |      0.5
+ qwertyu0161 |      0.5
+ qwertyu0162 |      0.5
+ qwertyu0163 |      0.5
+ qwertyu0164 |      0.5
+ qwertyu0165 |      0.5
+ qwertyu0166 |      0.5
+ qwertyu0167 |      0.5
+ qwertyu0168 |      0.5
+ qwertyu0169 |      0.5
+ qwertyu0170 |      0.5
+ qwertyu0171 |      0.5
+ qwertyu0172 |      0.5
+ qwertyu0173 |      0.5
+ qwertyu0174 |      0.5
+ qwertyu0175 |      0.5
+ qwertyu0176 |      0.5
+ qwertyu0177 |      0.5
+ qwertyu0178 |      0.5
+ qwertyu0179 |      0.5
+ qwertyu0180 |      0.5
+ qwertyu0181 |      0.5
+ qwertyu0182 |      0.5
+ qwertyu0183 |      0.5
+ qwertyu0184 |      0.5
+ qwertyu0185 |      0.5
+ qwertyu0186 |      0.5
+ qwertyu0187 |      0.5
+ qwertyu0189 |      0.5
+ qwertyu0190 |      0.5
+ qwertyu0191 |      0.5
+ qwertyu0192 |      0.5
+ qwertyu0193 |      0.5
+ qwertyu0194 |      0.5
+ qwertyu0195 |      0.5
+ qwertyu0196 |      0.5
+ qwertyu0197 |      0.5
+ qwertyu0198 |      0.5
+ qwertyu0199 |      0.5
+ qwertyu0200 |      0.5
+ qwertyu0201 |      0.5
+ qwertyu0202 |      0.5
+ qwertyu0203 |      0.5
+ qwertyu0204 |      0.5
+ qwertyu0205 |      0.5
+ qwertyu0206 |      0.5
+ qwertyu0207 |      0.5
+ qwertyu0208 |      0.5
+ qwertyu0209 |      0.5
+ qwertyu0210 |      0.5
+ qwertyu0211 |      0.5
+ qwertyu0212 |      0.5
+ qwertyu0213 |      0.5
+ qwertyu0214 |      0.5
+ qwertyu0215 |      0.5
+ qwertyu0216 |      0.5
+ qwertyu0217 |      0.5
+ qwertyu0218 |      0.5
+ qwertyu0219 |      0.5
+ qwertyu0220 |      0.5
+ qwertyu0221 |      0.5
+ qwertyu0222 |      0.5
+ qwertyu0223 |      0.5
+ qwertyu0224 |      0.5
+ qwertyu0225 |      0.5
+ qwertyu0226 |      0.5
+ qwertyu0227 |      0.5
+ qwertyu0228 |      0.5
+ qwertyu0229 |      0.5
+ qwertyu0230 |      0.5
+ qwertyu0231 |      0.5
+ qwertyu0232 |      0.5
+ qwertyu0233 |      0.5
+ qwertyu0234 |      0.5
+ qwertyu0235 |      0.5
+ qwertyu0236 |      0.5
+ qwertyu0237 |      0.5
+ qwertyu0238 |      0.5
+ qwertyu0239 |      0.5
+ qwertyu0240 |      0.5
+ qwertyu0241 |      0.5
+ qwertyu0242 |      0.5
+ qwertyu0243 |      0.5
+ qwertyu0244 |      0.5
+ qwertyu0245 |      0.5
+ qwertyu0246 |      0.5
+ qwertyu0247 |      0.5
+ qwertyu0248 |      0.5
+ qwertyu0249 |      0.5
+ qwertyu0250 |      0.5
+ qwertyu0251 |      0.5
+ qwertyu0252 |      0.5
+ qwertyu0253 |      0.5
+ qwertyu0254 |      0.5
+ qwertyu0255 |      0.5
+ qwertyu0256 |      0.5
+ qwertyu0257 |      0.5
+ qwertyu0258 |      0.5
+ qwertyu0259 |      0.5
+ qwertyu0260 |      0.5
+ qwertyu0261 |      0.5
+ qwertyu0262 |      0.5
+ qwertyu0263 |      0.5
+ qwertyu0264 |      0.5
+ qwertyu0265 |      0.5
+ qwertyu0266 |      0.5
+ qwertyu0267 |      0.5
+ qwertyu0268 |      0.5
+ qwertyu0269 |      0.5
+ qwertyu0270 |      0.5
+ qwertyu0271 |      0.5
+ qwertyu0272 |      0.5
+ qwertyu0273 |      0.5
+ qwertyu0274 |      0.5
+ qwertyu0275 |      0.5
+ qwertyu0276 |      0.5
+ qwertyu0277 |      0.5
+ qwertyu0278 |      0.5
+ qwertyu0279 |      0.5
+ qwertyu0280 |      0.5
+ qwertyu0281 |      0.5
+ qwertyu0282 |      0.5
+ qwertyu0283 |      0.5
+ qwertyu0284 |      0.5
+ qwertyu0285 |      0.5
+ qwertyu0286 |      0.5
+ qwertyu0287 |      0.5
+ qwertyu0289 |      0.5
+ qwertyu0290 |      0.5
+ qwertyu0291 |      0.5
+ qwertyu0292 |      0.5
+ qwertyu0293 |      0.5
+ qwertyu0294 |      0.5
+ qwertyu0295 |      0.5
+ qwertyu0296 |      0.5
+ qwertyu0297 |      0.5
+ qwertyu0298 |      0.5
+ qwertyu0299 |      0.5
+ qwertyu0300 |      0.5
+ qwertyu0301 |      0.5
+ qwertyu0302 |      0.5
+ qwertyu0303 |      0.5
+ qwertyu0304 |      0.5
+ qwertyu0305 |      0.5
+ qwertyu0306 |      0.5
+ qwertyu0307 |      0.5
+ qwertyu0308 |      0.5
+ qwertyu0309 |      0.5
+ qwertyu0310 |      0.5
+ qwertyu0311 |      0.5
+ qwertyu0312 |      0.5
+ qwertyu0313 |      0.5
+ qwertyu0314 |      0.5
+ qwertyu0315 |      0.5
+ qwertyu0316 |      0.5
+ qwertyu0317 |      0.5
+ qwertyu0318 |      0.5
+ qwertyu0319 |      0.5
+ qwertyu0320 |      0.5
+ qwertyu0321 |      0.5
+ qwertyu0322 |      0.5
+ qwertyu0323 |      0.5
+ qwertyu0324 |      0.5
+ qwertyu0325 |      0.5
+ qwertyu0326 |      0.5
+ qwertyu0327 |      0.5
+ qwertyu0328 |      0.5
+ qwertyu0329 |      0.5
+ qwertyu0330 |      0.5
+ qwertyu0331 |      0.5
+ qwertyu0332 |      0.5
+ qwertyu0333 |      0.5
+ qwertyu0334 |      0.5
+ qwertyu0335 |      0.5
+ qwertyu0336 |      0.5
+ qwertyu0337 |      0.5
+ qwertyu0338 |      0.5
+ qwertyu0339 |      0.5
+ qwertyu0340 |      0.5
+ qwertyu0341 |      0.5
+ qwertyu0342 |      0.5
+ qwertyu0343 |      0.5
+ qwertyu0344 |      0.5
+ qwertyu0345 |      0.5
+ qwertyu0346 |      0.5
+ qwertyu0347 |      0.5
+ qwertyu0348 |      0.5
+ qwertyu0349 |      0.5
+ qwertyu0350 |      0.5
+ qwertyu0351 |      0.5
+ qwertyu0352 |      0.5
+ qwertyu0353 |      0.5
+ qwertyu0354 |      0.5
+ qwertyu0355 |      0.5
+ qwertyu0356 |      0.5
+ qwertyu0357 |      0.5
+ qwertyu0358 |      0.5
+ qwertyu0359 |      0.5
+ qwertyu0360 |      0.5
+ qwertyu0361 |      0.5
+ qwertyu0362 |      0.5
+ qwertyu0363 |      0.5
+ qwertyu0364 |      0.5
+ qwertyu0365 |      0.5
+ qwertyu0366 |      0.5
+ qwertyu0367 |      0.5
+ qwertyu0368 |      0.5
+ qwertyu0369 |      0.5
+ qwertyu0370 |      0.5
+ qwertyu0371 |      0.5
+ qwertyu0372 |      0.5
+ qwertyu0373 |      0.5
+ qwertyu0374 |      0.5
+ qwertyu0375 |      0.5
+ qwertyu0376 |      0.5
+ qwertyu0377 |      0.5
+ qwertyu0378 |      0.5
+ qwertyu0379 |      0.5
+ qwertyu0380 |      0.5
+ qwertyu0381 |      0.5
+ qwertyu0382 |      0.5
+ qwertyu0383 |      0.5
+ qwertyu0384 |      0.5
+ qwertyu0385 |      0.5
+ qwertyu0386 |      0.5
+ qwertyu0387 |      0.5
+ qwertyu0389 |      0.5
+ qwertyu0390 |      0.5
+ qwertyu0391 |      0.5
+ qwertyu0392 |      0.5
+ qwertyu0393 |      0.5
+ qwertyu0394 |      0.5
+ qwertyu0395 |      0.5
+ qwertyu0396 |      0.5
+ qwertyu0397 |      0.5
+ qwertyu0398 |      0.5
+ qwertyu0399 |      0.5
+ qwertyu0400 |      0.5
+ qwertyu0401 |      0.5
+ qwertyu0402 |      0.5
+ qwertyu0403 |      0.5
+ qwertyu0404 |      0.5
+ qwertyu0405 |      0.5
+ qwertyu0406 |      0.5
+ qwertyu0407 |      0.5
+ qwertyu0408 |      0.5
+ qwertyu0409 |      0.5
+ qwertyu0410 |      0.5
+ qwertyu0411 |      0.5
+ qwertyu0412 |      0.5
+ qwertyu0413 |      0.5
+ qwertyu0414 |      0.5
+ qwertyu0415 |      0.5
+ qwertyu0416 |      0.5
+ qwertyu0417 |      0.5
+ qwertyu0418 |      0.5
+ qwertyu0419 |      0.5
+ qwertyu0420 |      0.5
+ qwertyu0421 |      0.5
+ qwertyu0422 |      0.5
+ qwertyu0423 |      0.5
+ qwertyu0424 |      0.5
+ qwertyu0425 |      0.5
+ qwertyu0426 |      0.5
+ qwertyu0427 |      0.5
+ qwertyu0428 |      0.5
+ qwertyu0429 |      0.5
+ qwertyu0430 |      0.5
+ qwertyu0431 |      0.5
+ qwertyu0432 |      0.5
+ qwertyu0433 |      0.5
+ qwertyu0434 |      0.5
+ qwertyu0435 |      0.5
+ qwertyu0436 |      0.5
+ qwertyu0437 |      0.5
+ qwertyu0438 |      0.5
+ qwertyu0439 |      0.5
+ qwertyu0440 |      0.5
+ qwertyu0441 |      0.5
+ qwertyu0442 |      0.5
+ qwertyu0443 |      0.5
+ qwertyu0444 |      0.5
+ qwertyu0445 |      0.5
+ qwertyu0446 |      0.5
+ qwertyu0447 |      0.5
+ qwertyu0448 |      0.5
+ qwertyu0449 |      0.5
+ qwertyu0450 |      0.5
+ qwertyu0451 |      0.5
+ qwertyu0452 |      0.5
+ qwertyu0453 |      0.5
+ qwertyu0454 |      0.5
+ qwertyu0455 |      0.5
+ qwertyu0456 |      0.5
+ qwertyu0457 |      0.5
+ qwertyu0458 |      0.5
+ qwertyu0459 |      0.5
+ qwertyu0460 |      0.5
+ qwertyu0461 |      0.5
+ qwertyu0462 |      0.5
+ qwertyu0463 |      0.5
+ qwertyu0464 |      0.5
+ qwertyu0465 |      0.5
+ qwertyu0466 |      0.5
+ qwertyu0467 |      0.5
+ qwertyu0468 |      0.5
+ qwertyu0469 |      0.5
+ qwertyu0470 |      0.5
+ qwertyu0471 |      0.5
+ qwertyu0472 |      0.5
+ qwertyu0473 |      0.5
+ qwertyu0474 |      0.5
+ qwertyu0475 |      0.5
+ qwertyu0476 |      0.5
+ qwertyu0477 |      0.5
+ qwertyu0478 |      0.5
+ qwertyu0479 |      0.5
+ qwertyu0480 |      0.5
+ qwertyu0481 |      0.5
+ qwertyu0482 |      0.5
+ qwertyu0483 |      0.5
+ qwertyu0484 |      0.5
+ qwertyu0485 |      0.5
+ qwertyu0486 |      0.5
+ qwertyu0487 |      0.5
+ qwertyu0489 |      0.5
+ qwertyu0490 |      0.5
+ qwertyu0491 |      0.5
+ qwertyu0492 |      0.5
+ qwertyu0493 |      0.5
+ qwertyu0494 |      0.5
+ qwertyu0495 |      0.5
+ qwertyu0496 |      0.5
+ qwertyu0497 |      0.5
+ qwertyu0498 |      0.5
+ qwertyu0499 |      0.5
+ qwertyu0500 |      0.5
+ qwertyu0501 |      0.5
+ qwertyu0502 |      0.5
+ qwertyu0503 |      0.5
+ qwertyu0504 |      0.5
+ qwertyu0505 |      0.5
+ qwertyu0506 |      0.5
+ qwertyu0507 |      0.5
+ qwertyu0508 |      0.5
+ qwertyu0509 |      0.5
+ qwertyu0510 |      0.5
+ qwertyu0511 |      0.5
+ qwertyu0512 |      0.5
+ qwertyu0513 |      0.5
+ qwertyu0514 |      0.5
+ qwertyu0515 |      0.5
+ qwertyu0516 |      0.5
+ qwertyu0517 |      0.5
+ qwertyu0518 |      0.5
+ qwertyu0519 |      0.5
+ qwertyu0520 |      0.5
+ qwertyu0521 |      0.5
+ qwertyu0522 |      0.5
+ qwertyu0523 |      0.5
+ qwertyu0524 |      0.5
+ qwertyu0525 |      0.5
+ qwertyu0526 |      0.5
+ qwertyu0527 |      0.5
+ qwertyu0528 |      0.5
+ qwertyu0529 |      0.5
+ qwertyu0530 |      0.5
+ qwertyu0531 |      0.5
+ qwertyu0532 |      0.5
+ qwertyu0533 |      0.5
+ qwertyu0534 |      0.5
+ qwertyu0535 |      0.5
+ qwertyu0536 |      0.5
+ qwertyu0537 |      0.5
+ qwertyu0538 |      0.5
+ qwertyu0539 |      0.5
+ qwertyu0540 |      0.5
+ qwertyu0541 |      0.5
+ qwertyu0542 |      0.5
+ qwertyu0543 |      0.5
+ qwertyu0544 |      0.5
+ qwertyu0545 |      0.5
+ qwertyu0546 |      0.5
+ qwertyu0547 |      0.5
+ qwertyu0548 |      0.5
+ qwertyu0549 |      0.5
+ qwertyu0550 |      0.5
+ qwertyu0551 |      0.5
+ qwertyu0552 |      0.5
+ qwertyu0553 |      0.5
+ qwertyu0554 |      0.5
+ qwertyu0555 |      0.5
+ qwertyu0556 |      0.5
+ qwertyu0557 |      0.5
+ qwertyu0558 |      0.5
+ qwertyu0559 |      0.5
+ qwertyu0560 |      0.5
+ qwertyu0561 |      0.5
+ qwertyu0562 |      0.5
+ qwertyu0563 |      0.5
+ qwertyu0564 |      0.5
+ qwertyu0565 |      0.5
+ qwertyu0566 |      0.5
+ qwertyu0567 |      0.5
+ qwertyu0568 |      0.5
+ qwertyu0569 |      0.5
+ qwertyu0570 |      0.5
+ qwertyu0571 |      0.5
+ qwertyu0572 |      0.5
+ qwertyu0573 |      0.5
+ qwertyu0574 |      0.5
+ qwertyu0575 |      0.5
+ qwertyu0576 |      0.5
+ qwertyu0577 |      0.5
+ qwertyu0578 |      0.5
+ qwertyu0579 |      0.5
+ qwertyu0580 |      0.5
+ qwertyu0581 |      0.5
+ qwertyu0582 |      0.5
+ qwertyu0583 |      0.5
+ qwertyu0584 |      0.5
+ qwertyu0585 |      0.5
+ qwertyu0586 |      0.5
+ qwertyu0587 |      0.5
+ qwertyu0589 |      0.5
+ qwertyu0590 |      0.5
+ qwertyu0591 |      0.5
+ qwertyu0592 |      0.5
+ qwertyu0593 |      0.5
+ qwertyu0594 |      0.5
+ qwertyu0595 |      0.5
+ qwertyu0596 |      0.5
+ qwertyu0597 |      0.5
+ qwertyu0598 |      0.5
+ qwertyu0599 |      0.5
+ qwertyu0600 |      0.5
+ qwertyu0601 |      0.5
+ qwertyu0602 |      0.5
+ qwertyu0603 |      0.5
+ qwertyu0604 |      0.5
+ qwertyu0605 |      0.5
+ qwertyu0606 |      0.5
+ qwertyu0607 |      0.5
+ qwertyu0608 |      0.5
+ qwertyu0609 |      0.5
+ qwertyu0610 |      0.5
+ qwertyu0611 |      0.5
+ qwertyu0612 |      0.5
+ qwertyu0613 |      0.5
+ qwertyu0614 |      0.5
+ qwertyu0615 |      0.5
+ qwertyu0616 |      0.5
+ qwertyu0617 |      0.5
+ qwertyu0618 |      0.5
+ qwertyu0619 |      0.5
+ qwertyu0620 |      0.5
+ qwertyu0621 |      0.5
+ qwertyu0622 |      0.5
+ qwertyu0623 |      0.5
+ qwertyu0624 |      0.5
+ qwertyu0625 |      0.5
+ qwertyu0626 |      0.5
+ qwertyu0627 |      0.5
+ qwertyu0628 |      0.5
+ qwertyu0629 |      0.5
+ qwertyu0630 |      0.5
+ qwertyu0631 |      0.5
+ qwertyu0632 |      0.5
+ qwertyu0633 |      0.5
+ qwertyu0634 |      0.5
+ qwertyu0635 |      0.5
+ qwertyu0636 |      0.5
+ qwertyu0637 |      0.5
+ qwertyu0638 |      0.5
+ qwertyu0639 |      0.5
+ qwertyu0640 |      0.5
+ qwertyu0641 |      0.5
+ qwertyu0642 |      0.5
+ qwertyu0643 |      0.5
+ qwertyu0644 |      0.5
+ qwertyu0645 |      0.5
+ qwertyu0646 |      0.5
+ qwertyu0647 |      0.5
+ qwertyu0648 |      0.5
+ qwertyu0649 |      0.5
+ qwertyu0650 |      0.5
+ qwertyu0651 |      0.5
+ qwertyu0652 |      0.5
+ qwertyu0653 |      0.5
+ qwertyu0654 |      0.5
+ qwertyu0655 |      0.5
+ qwertyu0656 |      0.5
+ qwertyu0657 |      0.5
+ qwertyu0658 |      0.5
+ qwertyu0659 |      0.5
+ qwertyu0660 |      0.5
+ qwertyu0661 |      0.5
+ qwertyu0662 |      0.5
+ qwertyu0663 |      0.5
+ qwertyu0664 |      0.5
+ qwertyu0665 |      0.5
+ qwertyu0666 |      0.5
+ qwertyu0667 |      0.5
+ qwertyu0668 |      0.5
+ qwertyu0669 |      0.5
+ qwertyu0670 |      0.5
+ qwertyu0671 |      0.5
+ qwertyu0672 |      0.5
+ qwertyu0673 |      0.5
+ qwertyu0674 |      0.5
+ qwertyu0675 |      0.5
+ qwertyu0676 |      0.5
+ qwertyu0677 |      0.5
+ qwertyu0678 |      0.5
+ qwertyu0679 |      0.5
+ qwertyu0680 |      0.5
+ qwertyu0681 |      0.5
+ qwertyu0682 |      0.5
+ qwertyu0683 |      0.5
+ qwertyu0684 |      0.5
+ qwertyu0685 |      0.5
+ qwertyu0686 |      0.5
+ qwertyu0687 |      0.5
+ qwertyu0689 |      0.5
+ qwertyu0690 |      0.5
+ qwertyu0691 |      0.5
+ qwertyu0692 |      0.5
+ qwertyu0693 |      0.5
+ qwertyu0694 |      0.5
+ qwertyu0695 |      0.5
+ qwertyu0696 |      0.5
+ qwertyu0697 |      0.5
+ qwertyu0698 |      0.5
+ qwertyu0699 |      0.5
+ qwertyu0700 |      0.5
+ qwertyu0701 |      0.5
+ qwertyu0702 |      0.5
+ qwertyu0703 |      0.5
+ qwertyu0704 |      0.5
+ qwertyu0705 |      0.5
+ qwertyu0706 |      0.5
+ qwertyu0707 |      0.5
+ qwertyu0708 |      0.5
+ qwertyu0709 |      0.5
+ qwertyu0710 |      0.5
+ qwertyu0711 |      0.5
+ qwertyu0712 |      0.5
+ qwertyu0713 |      0.5
+ qwertyu0714 |      0.5
+ qwertyu0715 |      0.5
+ qwertyu0716 |      0.5
+ qwertyu0717 |      0.5
+ qwertyu0718 |      0.5
+ qwertyu0719 |      0.5
+ qwertyu0720 |      0.5
+ qwertyu0721 |      0.5
+ qwertyu0722 |      0.5
+ qwertyu0723 |      0.5
+ qwertyu0724 |      0.5
+ qwertyu0725 |      0.5
+ qwertyu0726 |      0.5
+ qwertyu0727 |      0.5
+ qwertyu0728 |      0.5
+ qwertyu0729 |      0.5
+ qwertyu0730 |      0.5
+ qwertyu0731 |      0.5
+ qwertyu0732 |      0.5
+ qwertyu0733 |      0.5
+ qwertyu0734 |      0.5
+ qwertyu0735 |      0.5
+ qwertyu0736 |      0.5
+ qwertyu0737 |      0.5
+ qwertyu0738 |      0.5
+ qwertyu0739 |      0.5
+ qwertyu0740 |      0.5
+ qwertyu0741 |      0.5
+ qwertyu0742 |      0.5
+ qwertyu0743 |      0.5
+ qwertyu0744 |      0.5
+ qwertyu0745 |      0.5
+ qwertyu0746 |      0.5
+ qwertyu0747 |      0.5
+ qwertyu0748 |      0.5
+ qwertyu0749 |      0.5
+ qwertyu0750 |      0.5
+ qwertyu0751 |      0.5
+ qwertyu0752 |      0.5
+ qwertyu0753 |      0.5
+ qwertyu0754 |      0.5
+ qwertyu0755 |      0.5
+ qwertyu0756 |      0.5
+ qwertyu0757 |      0.5
+ qwertyu0758 |      0.5
+ qwertyu0759 |      0.5
+ qwertyu0760 |      0.5
+ qwertyu0761 |      0.5
+ qwertyu0762 |      0.5
+ qwertyu0763 |      0.5
+ qwertyu0764 |      0.5
+ qwertyu0765 |      0.5
+ qwertyu0766 |      0.5
+ qwertyu0767 |      0.5
+ qwertyu0768 |      0.5
+ qwertyu0769 |      0.5
+ qwertyu0770 |      0.5
+ qwertyu0771 |      0.5
+ qwertyu0772 |      0.5
+ qwertyu0773 |      0.5
+ qwertyu0774 |      0.5
+ qwertyu0775 |      0.5
+ qwertyu0776 |      0.5
+ qwertyu0777 |      0.5
+ qwertyu0778 |      0.5
+ qwertyu0779 |      0.5
+ qwertyu0780 |      0.5
+ qwertyu0781 |      0.5
+ qwertyu0782 |      0.5
+ qwertyu0783 |      0.5
+ qwertyu0784 |      0.5
+ qwertyu0785 |      0.5
+ qwertyu0786 |      0.5
+ qwertyu0787 |      0.5
+ qwertyu0789 |      0.5
+ qwertyu0790 |      0.5
+ qwertyu0791 |      0.5
+ qwertyu0792 |      0.5
+ qwertyu0793 |      0.5
+ qwertyu0794 |      0.5
+ qwertyu0795 |      0.5
+ qwertyu0796 |      0.5
+ qwertyu0797 |      0.5
+ qwertyu0798 |      0.5
+ qwertyu0799 |      0.5
+ qwertyu0800 |      0.5
+ qwertyu0801 |      0.5
+ qwertyu0802 |      0.5
+ qwertyu0803 |      0.5
+ qwertyu0804 |      0.5
+ qwertyu0805 |      0.5
+ qwertyu0806 |      0.5
+ qwertyu0807 |      0.5
+ qwertyu0808 |      0.5
+ qwertyu0809 |      0.5
+ qwertyu0810 |      0.5
+ qwertyu0811 |      0.5
+ qwertyu0812 |      0.5
+ qwertyu0813 |      0.5
+ qwertyu0814 |      0.5
+ qwertyu0815 |      0.5
+ qwertyu0816 |      0.5
+ qwertyu0817 |      0.5
+ qwertyu0818 |      0.5
+ qwertyu0819 |      0.5
+ qwertyu0820 |      0.5
+ qwertyu0821 |      0.5
+ qwertyu0822 |      0.5
+ qwertyu0823 |      0.5
+ qwertyu0824 |      0.5
+ qwertyu0825 |      0.5
+ qwertyu0826 |      0.5
+ qwertyu0827 |      0.5
+ qwertyu0828 |      0.5
+ qwertyu0829 |      0.5
+ qwertyu0830 |      0.5
+ qwertyu0831 |      0.5
+ qwertyu0832 |      0.5
+ qwertyu0833 |      0.5
+ qwertyu0834 |      0.5
+ qwertyu0835 |      0.5
+ qwertyu0836 |      0.5
+ qwertyu0837 |      0.5
+ qwertyu0838 |      0.5
+ qwertyu0839 |      0.5
+ qwertyu0840 |      0.5
+ qwertyu0841 |      0.5
+ qwertyu0842 |      0.5
+ qwertyu0843 |      0.5
+ qwertyu0844 |      0.5
+ qwertyu0845 |      0.5
+ qwertyu0846 |      0.5
+ qwertyu0847 |      0.5
+ qwertyu0848 |      0.5
+ qwertyu0849 |      0.5
+ qwertyu0850 |      0.5
+ qwertyu0851 |      0.5
+ qwertyu0852 |      0.5
+ qwertyu0853 |      0.5
+ qwertyu0854 |      0.5
+ qwertyu0855 |      0.5
+ qwertyu0856 |      0.5
+ qwertyu0857 |      0.5
+ qwertyu0858 |      0.5
+ qwertyu0859 |      0.5
+ qwertyu0860 |      0.5
+ qwertyu0861 |      0.5
+ qwertyu0862 |      0.5
+ qwertyu0863 |      0.5
+ qwertyu0864 |      0.5
+ qwertyu0865 |      0.5
+ qwertyu0866 |      0.5
+ qwertyu0867 |      0.5
+ qwertyu0868 |      0.5
+ qwertyu0869 |      0.5
+ qwertyu0870 |      0.5
+ qwertyu0871 |      0.5
+ qwertyu0872 |      0.5
+ qwertyu0873 |      0.5
+ qwertyu0874 |      0.5
+ qwertyu0875 |      0.5
+ qwertyu0876 |      0.5
+ qwertyu0877 |      0.5
+ qwertyu0878 |      0.5
+ qwertyu0879 |      0.5
+ qwertyu0880 |      0.5
+ qwertyu0881 |      0.5
+ qwertyu0882 |      0.5
+ qwertyu0883 |      0.5
+ qwertyu0884 |      0.5
+ qwertyu0885 |      0.5
+ qwertyu0886 |      0.5
+ qwertyu0887 |      0.5
+ qwertyu0889 |      0.5
+ qwertyu0890 |      0.5
+ qwertyu0891 |      0.5
+ qwertyu0892 |      0.5
+ qwertyu0893 |      0.5
+ qwertyu0894 |      0.5
+ qwertyu0895 |      0.5
+ qwertyu0896 |      0.5
+ qwertyu0897 |      0.5
+ qwertyu0898 |      0.5
+ qwertyu0899 |      0.5
+ qwertyu1000 | 0.411765
+(1000 rows)
+
+select t,similarity(t,'gwertyu0988') as sml from test_trgm where t % 'gwertyu0988' order by sml desc, t;
+      t      |   sml    
+-------------+----------
+ qwertyu0988 |      0.6
+ qwertyu0980 | 0.411765
+ qwertyu0981 | 0.411765
+ qwertyu0982 | 0.411765
+ qwertyu0983 | 0.411765
+ qwertyu0984 | 0.411765
+ qwertyu0985 | 0.411765
+ qwertyu0986 | 0.411765
+ qwertyu0987 | 0.411765
+ qwertyu0989 | 0.411765
+ qwertyu0088 | 0.333333
+ qwertyu0098 | 0.333333
+ qwertyu0188 | 0.333333
+ qwertyu0288 | 0.333333
+ qwertyu0388 | 0.333333
+ qwertyu0488 | 0.333333
+ qwertyu0588 | 0.333333
+ qwertyu0688 | 0.333333
+ qwertyu0788 | 0.333333
+ qwertyu0888 | 0.333333
+ qwertyu0900 | 0.333333
+ qwertyu0901 | 0.333333
+ qwertyu0902 | 0.333333
+ qwertyu0903 | 0.333333
+ qwertyu0904 | 0.333333
+ qwertyu0905 | 0.333333
+ qwertyu0906 | 0.333333
+ qwertyu0907 | 0.333333
+ qwertyu0908 | 0.333333
+ qwertyu0909 | 0.333333
+ qwertyu0910 | 0.333333
+ qwertyu0911 | 0.333333
+ qwertyu0912 | 0.333333
+ qwertyu0913 | 0.333333
+ qwertyu0914 | 0.333333
+ qwertyu0915 | 0.333333
+ qwertyu0916 | 0.333333
+ qwertyu0917 | 0.333333
+ qwertyu0918 | 0.333333
+ qwertyu0919 | 0.333333
+ qwertyu0920 | 0.333333
+ qwertyu0921 | 0.333333
+ qwertyu0922 | 0.333333
+ qwertyu0923 | 0.333333
+ qwertyu0924 | 0.333333
+ qwertyu0925 | 0.333333
+ qwertyu0926 | 0.333333
+ qwertyu0927 | 0.333333
+ qwertyu0928 | 0.333333
+ qwertyu0929 | 0.333333
+ qwertyu0930 | 0.333333
+ qwertyu0931 | 0.333333
+ qwertyu0932 | 0.333333
+ qwertyu0933 | 0.333333
+ qwertyu0934 | 0.333333
+ qwertyu0935 | 0.333333
+ qwertyu0936 | 0.333333
+ qwertyu0937 | 0.333333
+ qwertyu0938 | 0.333333
+ qwertyu0939 | 0.333333
+ qwertyu0940 | 0.333333
+ qwertyu0941 | 0.333333
+ qwertyu0942 | 0.333333
+ qwertyu0943 | 0.333333
+ qwertyu0944 | 0.333333
+ qwertyu0945 | 0.333333
+ qwertyu0946 | 0.333333
+ qwertyu0947 | 0.333333
+ qwertyu0948 | 0.333333
+ qwertyu0949 | 0.333333
+ qwertyu0950 | 0.333333
+ qwertyu0951 | 0.333333
+ qwertyu0952 | 0.333333
+ qwertyu0953 | 0.333333
+ qwertyu0954 | 0.333333
+ qwertyu0955 | 0.333333
+ qwertyu0956 | 0.333333
+ qwertyu0957 | 0.333333
+ qwertyu0958 | 0.333333
+ qwertyu0959 | 0.333333
+ qwertyu0960 | 0.333333
+ qwertyu0961 | 0.333333
+ qwertyu0962 | 0.333333
+ qwertyu0963 | 0.333333
+ qwertyu0964 | 0.333333
+ qwertyu0965 | 0.333333
+ qwertyu0966 | 0.333333
+ qwertyu0967 | 0.333333
+ qwertyu0968 | 0.333333
+ qwertyu0969 | 0.333333
+ qwertyu0970 | 0.333333
+ qwertyu0971 | 0.333333
+ qwertyu0972 | 0.333333
+ qwertyu0973 | 0.333333
+ qwertyu0974 | 0.333333
+ qwertyu0975 | 0.333333
+ qwertyu0976 | 0.333333
+ qwertyu0977 | 0.333333
+ qwertyu0978 | 0.333333
+ qwertyu0979 | 0.333333
+ qwertyu0990 | 0.333333
+ qwertyu0991 | 0.333333
+ qwertyu0992 | 0.333333
+ qwertyu0993 | 0.333333
+ qwertyu0994 | 0.333333
+ qwertyu0995 | 0.333333
+ qwertyu0996 | 0.333333
+ qwertyu0997 | 0.333333
+ qwertyu0998 | 0.333333
+ qwertyu0999 | 0.333333
+(110 rows)
+
+select t,similarity(t,'gwertyu1988') as sml from test_trgm where t % 'gwertyu1988' order by sml desc, t;
+      t      |   sml    
+-------------+----------
+ qwertyu0988 | 0.333333
+(1 row)
+
+create index trgm_idx on test_trgm using gist (t gist_trgm_ops);
+set enable_seqscan=off;
+select t,similarity(t,'qwertyu0988') as sml from test_trgm where t % 'qwertyu0988' order by sml desc, t;
+      t      |   sml    
+-------------+----------
+ qwertyu0988 |        1
+ qwertyu0980 | 0.714286
+ qwertyu0981 | 0.714286
+ qwertyu0982 | 0.714286
+ qwertyu0983 | 0.714286
+ qwertyu0984 | 0.714286
+ qwertyu0985 | 0.714286
+ qwertyu0986 | 0.714286
+ qwertyu0987 | 0.714286
+ qwertyu0989 | 0.714286
+ qwertyu0088 |      0.6
+ qwertyu0098 |      0.6
+ qwertyu0188 |      0.6
+ qwertyu0288 |      0.6
+ qwertyu0388 |      0.6
+ qwertyu0488 |      0.6
+ qwertyu0588 |      0.6
+ qwertyu0688 |      0.6
+ qwertyu0788 |      0.6
+ qwertyu0888 |      0.6
+ qwertyu0900 |      0.6
+ qwertyu0901 |      0.6
+ qwertyu0902 |      0.6
+ qwertyu0903 |      0.6
+ qwertyu0904 |      0.6
+ qwertyu0905 |      0.6
+ qwertyu0906 |      0.6
+ qwertyu0907 |      0.6
+ qwertyu0908 |      0.6
+ qwertyu0909 |      0.6
+ qwertyu0910 |      0.6
+ qwertyu0911 |      0.6
+ qwertyu0912 |      0.6
+ qwertyu0913 |      0.6
+ qwertyu0914 |      0.6
+ qwertyu0915 |      0.6
+ qwertyu0916 |      0.6
+ qwertyu0917 |      0.6
+ qwertyu0918 |      0.6
+ qwertyu0919 |      0.6
+ qwertyu0920 |      0.6
+ qwertyu0921 |      0.6
+ qwertyu0922 |      0.6
+ qwertyu0923 |      0.6
+ qwertyu0924 |      0.6
+ qwertyu0925 |      0.6
+ qwertyu0926 |      0.6
+ qwertyu0927 |      0.6
+ qwertyu0928 |      0.6
+ qwertyu0929 |      0.6
+ qwertyu0930 |      0.6
+ qwertyu0931 |      0.6
+ qwertyu0932 |      0.6
+ qwertyu0933 |      0.6
+ qwertyu0934 |      0.6
+ qwertyu0935 |      0.6
+ qwertyu0936 |      0.6
+ qwertyu0937 |      0.6
+ qwertyu0938 |      0.6
+ qwertyu0939 |      0.6
+ qwertyu0940 |      0.6
+ qwertyu0941 |      0.6
+ qwertyu0942 |      0.6
+ qwertyu0943 |      0.6
+ qwertyu0944 |      0.6
+ qwertyu0945 |      0.6
+ qwertyu0946 |      0.6
+ qwertyu0947 |      0.6
+ qwertyu0948 |      0.6
+ qwertyu0949 |      0.6
+ qwertyu0950 |      0.6
+ qwertyu0951 |      0.6
+ qwertyu0952 |      0.6
+ qwertyu0953 |      0.6
+ qwertyu0954 |      0.6
+ qwertyu0955 |      0.6
+ qwertyu0956 |      0.6
+ qwertyu0957 |      0.6
+ qwertyu0958 |      0.6
+ qwertyu0959 |      0.6
+ qwertyu0960 |      0.6
+ qwertyu0961 |      0.6
+ qwertyu0962 |      0.6
+ qwertyu0963 |      0.6
+ qwertyu0964 |      0.6
+ qwertyu0965 |      0.6
+ qwertyu0966 |      0.6
+ qwertyu0967 |      0.6
+ qwertyu0968 |      0.6
+ qwertyu0969 |      0.6
+ qwertyu0970 |      0.6
+ qwertyu0971 |      0.6
+ qwertyu0972 |      0.6
+ qwertyu0973 |      0.6
+ qwertyu0974 |      0.6
+ qwertyu0975 |      0.6
+ qwertyu0976 |      0.6
+ qwertyu0977 |      0.6
+ qwertyu0978 |      0.6
+ qwertyu0979 |      0.6
+ qwertyu0990 |      0.6
+ qwertyu0991 |      0.6
+ qwertyu0992 |      0.6
+ qwertyu0993 |      0.6
+ qwertyu0994 |      0.6
+ qwertyu0995 |      0.6
+ qwertyu0996 |      0.6
+ qwertyu0997 |      0.6
+ qwertyu0998 |      0.6
+ qwertyu0999 |      0.6
+ qwertyu0001 |      0.5
+ qwertyu0002 |      0.5
+ qwertyu0003 |      0.5
+ qwertyu0004 |      0.5
+ qwertyu0005 |      0.5
+ qwertyu0006 |      0.5
+ qwertyu0007 |      0.5
+ qwertyu0008 |      0.5
+ qwertyu0009 |      0.5
+ qwertyu0010 |      0.5
+ qwertyu0011 |      0.5
+ qwertyu0012 |      0.5
+ qwertyu0013 |      0.5
+ qwertyu0014 |      0.5
+ qwertyu0015 |      0.5
+ qwertyu0016 |      0.5
+ qwertyu0017 |      0.5
+ qwertyu0018 |      0.5
+ qwertyu0019 |      0.5
+ qwertyu0020 |      0.5
+ qwertyu0021 |      0.5
+ qwertyu0022 |      0.5
+ qwertyu0023 |      0.5
+ qwertyu0024 |      0.5
+ qwertyu0025 |      0.5
+ qwertyu0026 |      0.5
+ qwertyu0027 |      0.5
+ qwertyu0028 |      0.5
+ qwertyu0029 |      0.5
+ qwertyu0030 |      0.5
+ qwertyu0031 |      0.5
+ qwertyu0032 |      0.5
+ qwertyu0033 |      0.5
+ qwertyu0034 |      0.5
+ qwertyu0035 |      0.5
+ qwertyu0036 |      0.5
+ qwertyu0037 |      0.5
+ qwertyu0038 |      0.5
+ qwertyu0039 |      0.5
+ qwertyu0040 |      0.5
+ qwertyu0041 |      0.5
+ qwertyu0042 |      0.5
+ qwertyu0043 |      0.5
+ qwertyu0044 |      0.5
+ qwertyu0045 |      0.5
+ qwertyu0046 |      0.5
+ qwertyu0047 |      0.5
+ qwertyu0048 |      0.5
+ qwertyu0049 |      0.5
+ qwertyu0050 |      0.5
+ qwertyu0051 |      0.5
+ qwertyu0052 |      0.5
+ qwertyu0053 |      0.5
+ qwertyu0054 |      0.5
+ qwertyu0055 |      0.5
+ qwertyu0056 |      0.5
+ qwertyu0057 |      0.5
+ qwertyu0058 |      0.5
+ qwertyu0059 |      0.5
+ qwertyu0060 |      0.5
+ qwertyu0061 |      0.5
+ qwertyu0062 |      0.5
+ qwertyu0063 |      0.5
+ qwertyu0064 |      0.5
+ qwertyu0065 |      0.5
+ qwertyu0066 |      0.5
+ qwertyu0067 |      0.5
+ qwertyu0068 |      0.5
+ qwertyu0069 |      0.5
+ qwertyu0070 |      0.5
+ qwertyu0071 |      0.5
+ qwertyu0072 |      0.5
+ qwertyu0073 |      0.5
+ qwertyu0074 |      0.5
+ qwertyu0075 |      0.5
+ qwertyu0076 |      0.5
+ qwertyu0077 |      0.5
+ qwertyu0078 |      0.5
+ qwertyu0079 |      0.5
+ qwertyu0080 |      0.5
+ qwertyu0081 |      0.5
+ qwertyu0082 |      0.5
+ qwertyu0083 |      0.5
+ qwertyu0084 |      0.5
+ qwertyu0085 |      0.5
+ qwertyu0086 |      0.5
+ qwertyu0087 |      0.5
+ qwertyu0089 |      0.5
+ qwertyu0090 |      0.5
+ qwertyu0091 |      0.5
+ qwertyu0092 |      0.5
+ qwertyu0093 |      0.5
+ qwertyu0094 |      0.5
+ qwertyu0095 |      0.5
+ qwertyu0096 |      0.5
+ qwertyu0097 |      0.5
+ qwertyu0099 |      0.5
+ qwertyu0100 |      0.5
+ qwertyu0101 |      0.5
+ qwertyu0102 |      0.5
+ qwertyu0103 |      0.5
+ qwertyu0104 |      0.5
+ qwertyu0105 |      0.5
+ qwertyu0106 |      0.5
+ qwertyu0107 |      0.5
+ qwertyu0108 |      0.5
+ qwertyu0109 |      0.5
+ qwertyu0110 |      0.5
+ qwertyu0111 |      0.5
+ qwertyu0112 |      0.5
+ qwertyu0113 |      0.5
+ qwertyu0114 |      0.5
+ qwertyu0115 |      0.5
+ qwertyu0116 |      0.5
+ qwertyu0117 |      0.5
+ qwertyu0118 |      0.5
+ qwertyu0119 |      0.5
+ qwertyu0120 |      0.5
+ qwertyu0121 |      0.5
+ qwertyu0122 |      0.5
+ qwertyu0123 |      0.5
+ qwertyu0124 |      0.5
+ qwertyu0125 |      0.5
+ qwertyu0126 |      0.5
+ qwertyu0127 |      0.5
+ qwertyu0128 |      0.5
+ qwertyu0129 |      0.5
+ qwertyu0130 |      0.5
+ qwertyu0131 |      0.5
+ qwertyu0132 |      0.5
+ qwertyu0133 |      0.5
+ qwertyu0134 |      0.5
+ qwertyu0135 |      0.5
+ qwertyu0136 |      0.5
+ qwertyu0137 |      0.5
+ qwertyu0138 |      0.5
+ qwertyu0139 |      0.5
+ qwertyu0140 |      0.5
+ qwertyu0141 |      0.5
+ qwertyu0142 |      0.5
+ qwertyu0143 |      0.5
+ qwertyu0144 |      0.5
+ qwertyu0145 |      0.5
+ qwertyu0146 |      0.5
+ qwertyu0147 |      0.5
+ qwertyu0148 |      0.5
+ qwertyu0149 |      0.5
+ qwertyu0150 |      0.5
+ qwertyu0151 |      0.5
+ qwertyu0152 |      0.5
+ qwertyu0153 |      0.5
+ qwertyu0154 |      0.5
+ qwertyu0155 |      0.5
+ qwertyu0156 |      0.5
+ qwertyu0157 |      0.5
+ qwertyu0158 |      0.5
+ qwertyu0159 |      0.5
+ qwertyu0160 |      0.5
+ qwertyu0161 |      0.5
+ qwertyu0162 |      0.5
+ qwertyu0163 |      0.5
+ qwertyu0164 |      0.5
+ qwertyu0165 |      0.5
+ qwertyu0166 |      0.5
+ qwertyu0167 |      0.5
+ qwertyu0168 |      0.5
+ qwertyu0169 |      0.5
+ qwertyu0170 |      0.5
+ qwertyu0171 |      0.5
+ qwertyu0172 |      0.5
+ qwertyu0173 |      0.5
+ qwertyu0174 |      0.5
+ qwertyu0175 |      0.5
+ qwertyu0176 |      0.5
+ qwertyu0177 |      0.5
+ qwertyu0178 |      0.5
+ qwertyu0179 |      0.5
+ qwertyu0180 |      0.5
+ qwertyu0181 |      0.5
+ qwertyu0182 |      0.5
+ qwertyu0183 |      0.5
+ qwertyu0184 |      0.5
+ qwertyu0185 |      0.5
+ qwertyu0186 |      0.5
+ qwertyu0187 |      0.5
+ qwertyu0189 |      0.5
+ qwertyu0190 |      0.5
+ qwertyu0191 |      0.5
+ qwertyu0192 |      0.5
+ qwertyu0193 |      0.5
+ qwertyu0194 |      0.5
+ qwertyu0195 |      0.5
+ qwertyu0196 |      0.5
+ qwertyu0197 |      0.5
+ qwertyu0198 |      0.5
+ qwertyu0199 |      0.5
+ qwertyu0200 |      0.5
+ qwertyu0201 |      0.5
+ qwertyu0202 |      0.5
+ qwertyu0203 |      0.5
+ qwertyu0204 |      0.5
+ qwertyu0205 |      0.5
+ qwertyu0206 |      0.5
+ qwertyu0207 |      0.5
+ qwertyu0208 |      0.5
+ qwertyu0209 |      0.5
+ qwertyu0210 |      0.5
+ qwertyu0211 |      0.5
+ qwertyu0212 |      0.5
+ qwertyu0213 |      0.5
+ qwertyu0214 |      0.5
+ qwertyu0215 |      0.5
+ qwertyu0216 |      0.5
+ qwertyu0217 |      0.5
+ qwertyu0218 |      0.5
+ qwertyu0219 |      0.5
+ qwertyu0220 |      0.5
+ qwertyu0221 |      0.5
+ qwertyu0222 |      0.5
+ qwertyu0223 |      0.5
+ qwertyu0224 |      0.5
+ qwertyu0225 |      0.5
+ qwertyu0226 |      0.5
+ qwertyu0227 |      0.5
+ qwertyu0228 |      0.5
+ qwertyu0229 |      0.5
+ qwertyu0230 |      0.5
+ qwertyu0231 |      0.5
+ qwertyu0232 |      0.5
+ qwertyu0233 |      0.5
+ qwertyu0234 |      0.5
+ qwertyu0235 |      0.5
+ qwertyu0236 |      0.5
+ qwertyu0237 |      0.5
+ qwertyu0238 |      0.5
+ qwertyu0239 |      0.5
+ qwertyu0240 |      0.5
+ qwertyu0241 |      0.5
+ qwertyu0242 |      0.5
+ qwertyu0243 |      0.5
+ qwertyu0244 |      0.5
+ qwertyu0245 |      0.5
+ qwertyu0246 |      0.5
+ qwertyu0247 |      0.5
+ qwertyu0248 |      0.5
+ qwertyu0249 |      0.5
+ qwertyu0250 |      0.5
+ qwertyu0251 |      0.5
+ qwertyu0252 |      0.5
+ qwertyu0253 |      0.5
+ qwertyu0254 |      0.5
+ qwertyu0255 |      0.5
+ qwertyu0256 |      0.5
+ qwertyu0257 |      0.5
+ qwertyu0258 |      0.5
+ qwertyu0259 |      0.5
+ qwertyu0260 |      0.5
+ qwertyu0261 |      0.5
+ qwertyu0262 |      0.5
+ qwertyu0263 |      0.5
+ qwertyu0264 |      0.5
+ qwertyu0265 |      0.5
+ qwertyu0266 |      0.5
+ qwertyu0267 |      0.5
+ qwertyu0268 |      0.5
+ qwertyu0269 |      0.5
+ qwertyu0270 |      0.5
+ qwertyu0271 |      0.5
+ qwertyu0272 |      0.5
+ qwertyu0273 |      0.5
+ qwertyu0274 |      0.5
+ qwertyu0275 |      0.5
+ qwertyu0276 |      0.5
+ qwertyu0277 |      0.5
+ qwertyu0278 |      0.5
+ qwertyu0279 |      0.5
+ qwertyu0280 |      0.5
+ qwertyu0281 |      0.5
+ qwertyu0282 |      0.5
+ qwertyu0283 |      0.5
+ qwertyu0284 |      0.5
+ qwertyu0285 |      0.5
+ qwertyu0286 |      0.5
+ qwertyu0287 |      0.5
+ qwertyu0289 |      0.5
+ qwertyu0290 |      0.5
+ qwertyu0291 |      0.5
+ qwertyu0292 |      0.5
+ qwertyu0293 |      0.5
+ qwertyu0294 |      0.5
+ qwertyu0295 |      0.5
+ qwertyu0296 |      0.5
+ qwertyu0297 |      0.5
+ qwertyu0298 |      0.5
+ qwertyu0299 |      0.5
+ qwertyu0300 |      0.5
+ qwertyu0301 |      0.5
+ qwertyu0302 |      0.5
+ qwertyu0303 |      0.5
+ qwertyu0304 |      0.5
+ qwertyu0305 |      0.5
+ qwertyu0306 |      0.5
+ qwertyu0307 |      0.5
+ qwertyu0308 |      0.5
+ qwertyu0309 |      0.5
+ qwertyu0310 |      0.5
+ qwertyu0311 |      0.5
+ qwertyu0312 |      0.5
+ qwertyu0313 |      0.5
+ qwertyu0314 |      0.5
+ qwertyu0315 |      0.5
+ qwertyu0316 |      0.5
+ qwertyu0317 |      0.5
+ qwertyu0318 |      0.5
+ qwertyu0319 |      0.5
+ qwertyu0320 |      0.5
+ qwertyu0321 |      0.5
+ qwertyu0322 |      0.5
+ qwertyu0323 |      0.5
+ qwertyu0324 |      0.5
+ qwertyu0325 |      0.5
+ qwertyu0326 |      0.5
+ qwertyu0327 |      0.5
+ qwertyu0328 |      0.5
+ qwertyu0329 |      0.5
+ qwertyu0330 |      0.5
+ qwertyu0331 |      0.5
+ qwertyu0332 |      0.5
+ qwertyu0333 |      0.5
+ qwertyu0334 |      0.5
+ qwertyu0335 |      0.5
+ qwertyu0336 |      0.5
+ qwertyu0337 |      0.5
+ qwertyu0338 |      0.5
+ qwertyu0339 |      0.5
+ qwertyu0340 |      0.5
+ qwertyu0341 |      0.5
+ qwertyu0342 |      0.5
+ qwertyu0343 |      0.5
+ qwertyu0344 |      0.5
+ qwertyu0345 |      0.5
+ qwertyu0346 |      0.5
+ qwertyu0347 |      0.5
+ qwertyu0348 |      0.5
+ qwertyu0349 |      0.5
+ qwertyu0350 |      0.5
+ qwertyu0351 |      0.5
+ qwertyu0352 |      0.5
+ qwertyu0353 |      0.5
+ qwertyu0354 |      0.5
+ qwertyu0355 |      0.5
+ qwertyu0356 |      0.5
+ qwertyu0357 |      0.5
+ qwertyu0358 |      0.5
+ qwertyu0359 |      0.5
+ qwertyu0360 |      0.5
+ qwertyu0361 |      0.5
+ qwertyu0362 |      0.5
+ qwertyu0363 |      0.5
+ qwertyu0364 |      0.5
+ qwertyu0365 |      0.5
+ qwertyu0366 |      0.5
+ qwertyu0367 |      0.5
+ qwertyu0368 |      0.5
+ qwertyu0369 |      0.5
+ qwertyu0370 |      0.5
+ qwertyu0371 |      0.5
+ qwertyu0372 |      0.5
+ qwertyu0373 |      0.5
+ qwertyu0374 |      0.5
+ qwertyu0375 |      0.5
+ qwertyu0376 |      0.5
+ qwertyu0377 |      0.5
+ qwertyu0378 |      0.5
+ qwertyu0379 |      0.5
+ qwertyu0380 |      0.5
+ qwertyu0381 |      0.5
+ qwertyu0382 |      0.5
+ qwertyu0383 |      0.5
+ qwertyu0384 |      0.5
+ qwertyu0385 |      0.5
+ qwertyu0386 |      0.5
+ qwertyu0387 |      0.5
+ qwertyu0389 |      0.5
+ qwertyu0390 |      0.5
+ qwertyu0391 |      0.5
+ qwertyu0392 |      0.5
+ qwertyu0393 |      0.5
+ qwertyu0394 |      0.5
+ qwertyu0395 |      0.5
+ qwertyu0396 |      0.5
+ qwertyu0397 |      0.5
+ qwertyu0398 |      0.5
+ qwertyu0399 |      0.5
+ qwertyu0400 |      0.5
+ qwertyu0401 |      0.5
+ qwertyu0402 |      0.5
+ qwertyu0403 |      0.5
+ qwertyu0404 |      0.5
+ qwertyu0405 |      0.5
+ qwertyu0406 |      0.5
+ qwertyu0407 |      0.5
+ qwertyu0408 |      0.5
+ qwertyu0409 |      0.5
+ qwertyu0410 |      0.5
+ qwertyu0411 |      0.5
+ qwertyu0412 |      0.5
+ qwertyu0413 |      0.5
+ qwertyu0414 |      0.5
+ qwertyu0415 |      0.5
+ qwertyu0416 |      0.5
+ qwertyu0417 |      0.5
+ qwertyu0418 |      0.5
+ qwertyu0419 |      0.5
+ qwertyu0420 |      0.5
+ qwertyu0421 |      0.5
+ qwertyu0422 |      0.5
+ qwertyu0423 |      0.5
+ qwertyu0424 |      0.5
+ qwertyu0425 |      0.5
+ qwertyu0426 |      0.5
+ qwertyu0427 |      0.5
+ qwertyu0428 |      0.5
+ qwertyu0429 |      0.5
+ qwertyu0430 |      0.5
+ qwertyu0431 |      0.5
+ qwertyu0432 |      0.5
+ qwertyu0433 |      0.5
+ qwertyu0434 |      0.5
+ qwertyu0435 |      0.5
+ qwertyu0436 |      0.5
+ qwertyu0437 |      0.5
+ qwertyu0438 |      0.5
+ qwertyu0439 |      0.5
+ qwertyu0440 |      0.5
+ qwertyu0441 |      0.5
+ qwertyu0442 |      0.5
+ qwertyu0443 |      0.5
+ qwertyu0444 |      0.5
+ qwertyu0445 |      0.5
+ qwertyu0446 |      0.5
+ qwertyu0447 |      0.5
+ qwertyu0448 |      0.5
+ qwertyu0449 |      0.5
+ qwertyu0450 |      0.5
+ qwertyu0451 |      0.5
+ qwertyu0452 |      0.5
+ qwertyu0453 |      0.5
+ qwertyu0454 |      0.5
+ qwertyu0455 |      0.5
+ qwertyu0456 |      0.5
+ qwertyu0457 |      0.5
+ qwertyu0458 |      0.5
+ qwertyu0459 |      0.5
+ qwertyu0460 |      0.5
+ qwertyu0461 |      0.5
+ qwertyu0462 |      0.5
+ qwertyu0463 |      0.5
+ qwertyu0464 |      0.5
+ qwertyu0465 |      0.5
+ qwertyu0466 |      0.5
+ qwertyu0467 |      0.5
+ qwertyu0468 |      0.5
+ qwertyu0469 |      0.5
+ qwertyu0470 |      0.5
+ qwertyu0471 |      0.5
+ qwertyu0472 |      0.5
+ qwertyu0473 |      0.5
+ qwertyu0474 |      0.5
+ qwertyu0475 |      0.5
+ qwertyu0476 |      0.5
+ qwertyu0477 |      0.5
+ qwertyu0478 |      0.5
+ qwertyu0479 |      0.5
+ qwertyu0480 |      0.5
+ qwertyu0481 |      0.5
+ qwertyu0482 |      0.5
+ qwertyu0483 |      0.5
+ qwertyu0484 |      0.5
+ qwertyu0485 |      0.5
+ qwertyu0486 |      0.5
+ qwertyu0487 |      0.5
+ qwertyu0489 |      0.5
+ qwertyu0490 |      0.5
+ qwertyu0491 |      0.5
+ qwertyu0492 |      0.5
+ qwertyu0493 |      0.5
+ qwertyu0494 |      0.5
+ qwertyu0495 |      0.5
+ qwertyu0496 |      0.5
+ qwertyu0497 |      0.5
+ qwertyu0498 |      0.5
+ qwertyu0499 |      0.5
+ qwertyu0500 |      0.5
+ qwertyu0501 |      0.5
+ qwertyu0502 |      0.5
+ qwertyu0503 |      0.5
+ qwertyu0504 |      0.5
+ qwertyu0505 |      0.5
+ qwertyu0506 |      0.5
+ qwertyu0507 |      0.5
+ qwertyu0508 |      0.5
+ qwertyu0509 |      0.5
+ qwertyu0510 |      0.5
+ qwertyu0511 |      0.5
+ qwertyu0512 |      0.5
+ qwertyu0513 |      0.5
+ qwertyu0514 |      0.5
+ qwertyu0515 |      0.5
+ qwertyu0516 |      0.5
+ qwertyu0517 |      0.5
+ qwertyu0518 |      0.5
+ qwertyu0519 |      0.5
+ qwertyu0520 |      0.5
+ qwertyu0521 |      0.5
+ qwertyu0522 |      0.5
+ qwertyu0523 |      0.5
+ qwertyu0524 |      0.5
+ qwertyu0525 |      0.5
+ qwertyu0526 |      0.5
+ qwertyu0527 |      0.5
+ qwertyu0528 |      0.5
+ qwertyu0529 |      0.5
+ qwertyu0530 |      0.5
+ qwertyu0531 |      0.5
+ qwertyu0532 |      0.5
+ qwertyu0533 |      0.5
+ qwertyu0534 |      0.5
+ qwertyu0535 |      0.5
+ qwertyu0536 |      0.5
+ qwertyu0537 |      0.5
+ qwertyu0538 |      0.5
+ qwertyu0539 |      0.5
+ qwertyu0540 |      0.5
+ qwertyu0541 |      0.5
+ qwertyu0542 |      0.5
+ qwertyu0543 |      0.5
+ qwertyu0544 |      0.5
+ qwertyu0545 |      0.5
+ qwertyu0546 |      0.5
+ qwertyu0547 |      0.5
+ qwertyu0548 |      0.5
+ qwertyu0549 |      0.5
+ qwertyu0550 |      0.5
+ qwertyu0551 |      0.5
+ qwertyu0552 |      0.5
+ qwertyu0553 |      0.5
+ qwertyu0554 |      0.5
+ qwertyu0555 |      0.5
+ qwertyu0556 |      0.5
+ qwertyu0557 |      0.5
+ qwertyu0558 |      0.5
+ qwertyu0559 |      0.5
+ qwertyu0560 |      0.5
+ qwertyu0561 |      0.5
+ qwertyu0562 |      0.5
+ qwertyu0563 |      0.5
+ qwertyu0564 |      0.5
+ qwertyu0565 |      0.5
+ qwertyu0566 |      0.5
+ qwertyu0567 |      0.5
+ qwertyu0568 |      0.5
+ qwertyu0569 |      0.5
+ qwertyu0570 |      0.5
+ qwertyu0571 |      0.5
+ qwertyu0572 |      0.5
+ qwertyu0573 |      0.5
+ qwertyu0574 |      0.5
+ qwertyu0575 |      0.5
+ qwertyu0576 |      0.5
+ qwertyu0577 |      0.5
+ qwertyu0578 |      0.5
+ qwertyu0579 |      0.5
+ qwertyu0580 |      0.5
+ qwertyu0581 |      0.5
+ qwertyu0582 |      0.5
+ qwertyu0583 |      0.5
+ qwertyu0584 |      0.5
+ qwertyu0585 |      0.5
+ qwertyu0586 |      0.5
+ qwertyu0587 |      0.5
+ qwertyu0589 |      0.5
+ qwertyu0590 |      0.5
+ qwertyu0591 |      0.5
+ qwertyu0592 |      0.5
+ qwertyu0593 |      0.5
+ qwertyu0594 |      0.5
+ qwertyu0595 |      0.5
+ qwertyu0596 |      0.5
+ qwertyu0597 |      0.5
+ qwertyu0598 |      0.5
+ qwertyu0599 |      0.5
+ qwertyu0600 |      0.5
+ qwertyu0601 |      0.5
+ qwertyu0602 |      0.5
+ qwertyu0603 |      0.5
+ qwertyu0604 |      0.5
+ qwertyu0605 |      0.5
+ qwertyu0606 |      0.5
+ qwertyu0607 |      0.5
+ qwertyu0608 |      0.5
+ qwertyu0609 |      0.5
+ qwertyu0610 |      0.5
+ qwertyu0611 |      0.5
+ qwertyu0612 |      0.5
+ qwertyu0613 |      0.5
+ qwertyu0614 |      0.5
+ qwertyu0615 |      0.5
+ qwertyu0616 |      0.5
+ qwertyu0617 |      0.5
+ qwertyu0618 |      0.5
+ qwertyu0619 |      0.5
+ qwertyu0620 |      0.5
+ qwertyu0621 |      0.5
+ qwertyu0622 |      0.5
+ qwertyu0623 |      0.5
+ qwertyu0624 |      0.5
+ qwertyu0625 |      0.5
+ qwertyu0626 |      0.5
+ qwertyu0627 |      0.5
+ qwertyu0628 |      0.5
+ qwertyu0629 |      0.5
+ qwertyu0630 |      0.5
+ qwertyu0631 |      0.5
+ qwertyu0632 |      0.5
+ qwertyu0633 |      0.5
+ qwertyu0634 |      0.5
+ qwertyu0635 |      0.5
+ qwertyu0636 |      0.5
+ qwertyu0637 |      0.5
+ qwertyu0638 |      0.5
+ qwertyu0639 |      0.5
+ qwertyu0640 |      0.5
+ qwertyu0641 |      0.5
+ qwertyu0642 |      0.5
+ qwertyu0643 |      0.5
+ qwertyu0644 |      0.5
+ qwertyu0645 |      0.5
+ qwertyu0646 |      0.5
+ qwertyu0647 |      0.5
+ qwertyu0648 |      0.5
+ qwertyu0649 |      0.5
+ qwertyu0650 |      0.5
+ qwertyu0651 |      0.5
+ qwertyu0652 |      0.5
+ qwertyu0653 |      0.5
+ qwertyu0654 |      0.5
+ qwertyu0655 |      0.5
+ qwertyu0656 |      0.5
+ qwertyu0657 |      0.5
+ qwertyu0658 |      0.5
+ qwertyu0659 |      0.5
+ qwertyu0660 |      0.5
+ qwertyu0661 |      0.5
+ qwertyu0662 |      0.5
+ qwertyu0663 |      0.5
+ qwertyu0664 |      0.5
+ qwertyu0665 |      0.5
+ qwertyu0666 |      0.5
+ qwertyu0667 |      0.5
+ qwertyu0668 |      0.5
+ qwertyu0669 |      0.5
+ qwertyu0670 |      0.5
+ qwertyu0671 |      0.5
+ qwertyu0672 |      0.5
+ qwertyu0673 |      0.5
+ qwertyu0674 |      0.5
+ qwertyu0675 |      0.5
+ qwertyu0676 |      0.5
+ qwertyu0677 |      0.5
+ qwertyu0678 |      0.5
+ qwertyu0679 |      0.5
+ qwertyu0680 |      0.5
+ qwertyu0681 |      0.5
+ qwertyu0682 |      0.5
+ qwertyu0683 |      0.5
+ qwertyu0684 |      0.5
+ qwertyu0685 |      0.5
+ qwertyu0686 |      0.5
+ qwertyu0687 |      0.5
+ qwertyu0689 |      0.5
+ qwertyu0690 |      0.5
+ qwertyu0691 |      0.5
+ qwertyu0692 |      0.5
+ qwertyu0693 |      0.5
+ qwertyu0694 |      0.5
+ qwertyu0695 |      0.5
+ qwertyu0696 |      0.5
+ qwertyu0697 |      0.5
+ qwertyu0698 |      0.5
+ qwertyu0699 |      0.5
+ qwertyu0700 |      0.5
+ qwertyu0701 |      0.5
+ qwertyu0702 |      0.5
+ qwertyu0703 |      0.5
+ qwertyu0704 |      0.5
+ qwertyu0705 |      0.5
+ qwertyu0706 |      0.5
+ qwertyu0707 |      0.5
+ qwertyu0708 |      0.5
+ qwertyu0709 |      0.5
+ qwertyu0710 |      0.5
+ qwertyu0711 |      0.5
+ qwertyu0712 |      0.5
+ qwertyu0713 |      0.5
+ qwertyu0714 |      0.5
+ qwertyu0715 |      0.5
+ qwertyu0716 |      0.5
+ qwertyu0717 |      0.5
+ qwertyu0718 |      0.5
+ qwertyu0719 |      0.5
+ qwertyu0720 |      0.5
+ qwertyu0721 |      0.5
+ qwertyu0722 |      0.5
+ qwertyu0723 |      0.5
+ qwertyu0724 |      0.5
+ qwertyu0725 |      0.5
+ qwertyu0726 |      0.5
+ qwertyu0727 |      0.5
+ qwertyu0728 |      0.5
+ qwertyu0729 |      0.5
+ qwertyu0730 |      0.5
+ qwertyu0731 |      0.5
+ qwertyu0732 |      0.5
+ qwertyu0733 |      0.5
+ qwertyu0734 |      0.5
+ qwertyu0735 |      0.5
+ qwertyu0736 |      0.5
+ qwertyu0737 |      0.5
+ qwertyu0738 |      0.5
+ qwertyu0739 |      0.5
+ qwertyu0740 |      0.5
+ qwertyu0741 |      0.5
+ qwertyu0742 |      0.5
+ qwertyu0743 |      0.5
+ qwertyu0744 |      0.5
+ qwertyu0745 |      0.5
+ qwertyu0746 |      0.5
+ qwertyu0747 |      0.5
+ qwertyu0748 |      0.5
+ qwertyu0749 |      0.5
+ qwertyu0750 |      0.5
+ qwertyu0751 |      0.5
+ qwertyu0752 |      0.5
+ qwertyu0753 |      0.5
+ qwertyu0754 |      0.5
+ qwertyu0755 |      0.5
+ qwertyu0756 |      0.5
+ qwertyu0757 |      0.5
+ qwertyu0758 |      0.5
+ qwertyu0759 |      0.5
+ qwertyu0760 |      0.5
+ qwertyu0761 |      0.5
+ qwertyu0762 |      0.5
+ qwertyu0763 |      0.5
+ qwertyu0764 |      0.5
+ qwertyu0765 |      0.5
+ qwertyu0766 |      0.5
+ qwertyu0767 |      0.5
+ qwertyu0768 |      0.5
+ qwertyu0769 |      0.5
+ qwertyu0770 |      0.5
+ qwertyu0771 |      0.5
+ qwertyu0772 |      0.5
+ qwertyu0773 |      0.5
+ qwertyu0774 |      0.5
+ qwertyu0775 |      0.5
+ qwertyu0776 |      0.5
+ qwertyu0777 |      0.5
+ qwertyu0778 |      0.5
+ qwertyu0779 |      0.5
+ qwertyu0780 |      0.5
+ qwertyu0781 |      0.5
+ qwertyu0782 |      0.5
+ qwertyu0783 |      0.5
+ qwertyu0784 |      0.5
+ qwertyu0785 |      0.5
+ qwertyu0786 |      0.5
+ qwertyu0787 |      0.5
+ qwertyu0789 |      0.5
+ qwertyu0790 |      0.5
+ qwertyu0791 |      0.5
+ qwertyu0792 |      0.5
+ qwertyu0793 |      0.5
+ qwertyu0794 |      0.5
+ qwertyu0795 |      0.5
+ qwertyu0796 |      0.5
+ qwertyu0797 |      0.5
+ qwertyu0798 |      0.5
+ qwertyu0799 |      0.5
+ qwertyu0800 |      0.5
+ qwertyu0801 |      0.5
+ qwertyu0802 |      0.5
+ qwertyu0803 |      0.5
+ qwertyu0804 |      0.5
+ qwertyu0805 |      0.5
+ qwertyu0806 |      0.5
+ qwertyu0807 |      0.5
+ qwertyu0808 |      0.5
+ qwertyu0809 |      0.5
+ qwertyu0810 |      0.5
+ qwertyu0811 |      0.5
+ qwertyu0812 |      0.5
+ qwertyu0813 |      0.5
+ qwertyu0814 |      0.5
+ qwertyu0815 |      0.5
+ qwertyu0816 |      0.5
+ qwertyu0817 |      0.5
+ qwertyu0818 |      0.5
+ qwertyu0819 |      0.5
+ qwertyu0820 |      0.5
+ qwertyu0821 |      0.5
+ qwertyu0822 |      0.5
+ qwertyu0823 |      0.5
+ qwertyu0824 |      0.5
+ qwertyu0825 |      0.5
+ qwertyu0826 |      0.5
+ qwertyu0827 |      0.5
+ qwertyu0828 |      0.5
+ qwertyu0829 |      0.5
+ qwertyu0830 |      0.5
+ qwertyu0831 |      0.5
+ qwertyu0832 |      0.5
+ qwertyu0833 |      0.5
+ qwertyu0834 |      0.5
+ qwertyu0835 |      0.5
+ qwertyu0836 |      0.5
+ qwertyu0837 |      0.5
+ qwertyu0838 |      0.5
+ qwertyu0839 |      0.5
+ qwertyu0840 |      0.5
+ qwertyu0841 |      0.5
+ qwertyu0842 |      0.5
+ qwertyu0843 |      0.5
+ qwertyu0844 |      0.5
+ qwertyu0845 |      0.5
+ qwertyu0846 |      0.5
+ qwertyu0847 |      0.5
+ qwertyu0848 |      0.5
+ qwertyu0849 |      0.5
+ qwertyu0850 |      0.5
+ qwertyu0851 |      0.5
+ qwertyu0852 |      0.5
+ qwertyu0853 |      0.5
+ qwertyu0854 |      0.5
+ qwertyu0855 |      0.5
+ qwertyu0856 |      0.5
+ qwertyu0857 |      0.5
+ qwertyu0858 |      0.5
+ qwertyu0859 |      0.5
+ qwertyu0860 |      0.5
+ qwertyu0861 |      0.5
+ qwertyu0862 |      0.5
+ qwertyu0863 |      0.5
+ qwertyu0864 |      0.5
+ qwertyu0865 |      0.5
+ qwertyu0866 |      0.5
+ qwertyu0867 |      0.5
+ qwertyu0868 |      0.5
+ qwertyu0869 |      0.5
+ qwertyu0870 |      0.5
+ qwertyu0871 |      0.5
+ qwertyu0872 |      0.5
+ qwertyu0873 |      0.5
+ qwertyu0874 |      0.5
+ qwertyu0875 |      0.5
+ qwertyu0876 |      0.5
+ qwertyu0877 |      0.5
+ qwertyu0878 |      0.5
+ qwertyu0879 |      0.5
+ qwertyu0880 |      0.5
+ qwertyu0881 |      0.5
+ qwertyu0882 |      0.5
+ qwertyu0883 |      0.5
+ qwertyu0884 |      0.5
+ qwertyu0885 |      0.5
+ qwertyu0886 |      0.5
+ qwertyu0887 |      0.5
+ qwertyu0889 |      0.5
+ qwertyu0890 |      0.5
+ qwertyu0891 |      0.5
+ qwertyu0892 |      0.5
+ qwertyu0893 |      0.5
+ qwertyu0894 |      0.5
+ qwertyu0895 |      0.5
+ qwertyu0896 |      0.5
+ qwertyu0897 |      0.5
+ qwertyu0898 |      0.5
+ qwertyu0899 |      0.5
+ qwertyu1000 | 0.411765
+(1000 rows)
+
+select t,similarity(t,'gwertyu0988') as sml from test_trgm where t % 'gwertyu0988' order by sml desc, t;
+      t      |   sml    
+-------------+----------
+ qwertyu0988 |      0.6
+ qwertyu0980 | 0.411765
+ qwertyu0981 | 0.411765
+ qwertyu0982 | 0.411765
+ qwertyu0983 | 0.411765
+ qwertyu0984 | 0.411765
+ qwertyu0985 | 0.411765
+ qwertyu0986 | 0.411765
+ qwertyu0987 | 0.411765
+ qwertyu0989 | 0.411765
+ qwertyu0088 | 0.333333
+ qwertyu0098 | 0.333333
+ qwertyu0188 | 0.333333
+ qwertyu0288 | 0.333333
+ qwertyu0388 | 0.333333
+ qwertyu0488 | 0.333333
+ qwertyu0588 | 0.333333
+ qwertyu0688 | 0.333333
+ qwertyu0788 | 0.333333
+ qwertyu0888 | 0.333333
+ qwertyu0900 | 0.333333
+ qwertyu0901 | 0.333333
+ qwertyu0902 | 0.333333
+ qwertyu0903 | 0.333333
+ qwertyu0904 | 0.333333
+ qwertyu0905 | 0.333333
+ qwertyu0906 | 0.333333
+ qwertyu0907 | 0.333333
+ qwertyu0908 | 0.333333
+ qwertyu0909 | 0.333333
+ qwertyu0910 | 0.333333
+ qwertyu0911 | 0.333333
+ qwertyu0912 | 0.333333
+ qwertyu0913 | 0.333333
+ qwertyu0914 | 0.333333
+ qwertyu0915 | 0.333333
+ qwertyu0916 | 0.333333
+ qwertyu0917 | 0.333333
+ qwertyu0918 | 0.333333
+ qwertyu0919 | 0.333333
+ qwertyu0920 | 0.333333
+ qwertyu0921 | 0.333333
+ qwertyu0922 | 0.333333
+ qwertyu0923 | 0.333333
+ qwertyu0924 | 0.333333
+ qwertyu0925 | 0.333333
+ qwertyu0926 | 0.333333
+ qwertyu0927 | 0.333333
+ qwertyu0928 | 0.333333
+ qwertyu0929 | 0.333333
+ qwertyu0930 | 0.333333
+ qwertyu0931 | 0.333333
+ qwertyu0932 | 0.333333
+ qwertyu0933 | 0.333333
+ qwertyu0934 | 0.333333
+ qwertyu0935 | 0.333333
+ qwertyu0936 | 0.333333
+ qwertyu0937 | 0.333333
+ qwertyu0938 | 0.333333
+ qwertyu0939 | 0.333333
+ qwertyu0940 | 0.333333
+ qwertyu0941 | 0.333333
+ qwertyu0942 | 0.333333
+ qwertyu0943 | 0.333333
+ qwertyu0944 | 0.333333
+ qwertyu0945 | 0.333333
+ qwertyu0946 | 0.333333
+ qwertyu0947 | 0.333333
+ qwertyu0948 | 0.333333
+ qwertyu0949 | 0.333333
+ qwertyu0950 | 0.333333
+ qwertyu0951 | 0.333333
+ qwertyu0952 | 0.333333
+ qwertyu0953 | 0.333333
+ qwertyu0954 | 0.333333
+ qwertyu0955 | 0.333333
+ qwertyu0956 | 0.333333
+ qwertyu0957 | 0.333333
+ qwertyu0958 | 0.333333
+ qwertyu0959 | 0.333333
+ qwertyu0960 | 0.333333
+ qwertyu0961 | 0.333333
+ qwertyu0962 | 0.333333
+ qwertyu0963 | 0.333333
+ qwertyu0964 | 0.333333
+ qwertyu0965 | 0.333333
+ qwertyu0966 | 0.333333
+ qwertyu0967 | 0.333333
+ qwertyu0968 | 0.333333
+ qwertyu0969 | 0.333333
+ qwertyu0970 | 0.333333
+ qwertyu0971 | 0.333333
+ qwertyu0972 | 0.333333
+ qwertyu0973 | 0.333333
+ qwertyu0974 | 0.333333
+ qwertyu0975 | 0.333333
+ qwertyu0976 | 0.333333
+ qwertyu0977 | 0.333333
+ qwertyu0978 | 0.333333
+ qwertyu0979 | 0.333333
+ qwertyu0990 | 0.333333
+ qwertyu0991 | 0.333333
+ qwertyu0992 | 0.333333
+ qwertyu0993 | 0.333333
+ qwertyu0994 | 0.333333
+ qwertyu0995 | 0.333333
+ qwertyu0996 | 0.333333
+ qwertyu0997 | 0.333333
+ qwertyu0998 | 0.333333
+ qwertyu0999 | 0.333333
+(110 rows)
+
+select t,similarity(t,'gwertyu1988') as sml from test_trgm where t % 'gwertyu1988' order by sml desc, t;
+      t      |   sml    
+-------------+----------
+ qwertyu0988 | 0.333333
+(1 row)
+
diff --git a/contrib/pg_trgm/pg_trgm.sql.in b/contrib/pg_trgm/pg_trgm.sql.in
new file mode 100644 (file)
index 0000000..f38abb6
--- /dev/null
@@ -0,0 +1,107 @@
+SET search_path = public;
+
+BEGIN;
+
+create function set_limit(float4)
+returns float4
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict,iscachable);
+
+create function show_limit()
+returns float4
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict,iscachable);
+
+create function show_trgm(text)
+returns _text
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict,iscachable);
+
+create function similarity(text,text)
+returns float4
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict,iscachable);
+
+create function similarity_op(text,text)
+returns bool
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict,iscachable);
+
+CREATE OPERATOR % (
+        LEFTARG = text,
+        RIGHTARG = text,
+        PROCEDURE = similarity_op,
+        COMMUTATOR = '%',
+        RESTRICT = contsel,
+        JOIN = contjoinsel
+);
+
+--gist key
+CREATE FUNCTION gtrgm_in(cstring)
+RETURNS gtrgm
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict);
+
+CREATE FUNCTION gtrgm_out(gtrgm)
+RETURNS cstring
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict);
+
+CREATE TYPE gtrgm (
+        INTERNALLENGTH = -1,
+        INPUT = gtrgm_in,
+        OUTPUT = gtrgm_out
+);
+
+-- support functions
+CREATE FUNCTION gtrgm_consistent(gtrgm,internal,int4)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+CREATE FUNCTION gtrgm_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
+CREATE FUNCTION gtrgm_decompress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
+CREATE FUNCTION gtrgm_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict);
+
+CREATE FUNCTION gtrgm_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
+CREATE FUNCTION gtrgm_union(bytea, internal)
+RETURNS _int4
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
+CREATE FUNCTION gtrgm_same(gtrgm, gtrgm, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
+-- create the operator class
+CREATE OPERATOR CLASS gist_trgm_ops
+FOR TYPE text USING gist
+AS
+        OPERATOR        1       % (text, text),
+        FUNCTION        1       gtrgm_consistent (gtrgm, internal, int4),
+        FUNCTION        2       gtrgm_union (bytea, internal),
+        FUNCTION        3       gtrgm_compress (internal),
+        FUNCTION        4       gtrgm_decompress (internal),
+        FUNCTION        5       gtrgm_penalty (internal, internal, internal),
+        FUNCTION        6       gtrgm_picksplit (internal, internal),
+        FUNCTION        7       gtrgm_same (gtrgm, gtrgm, internal),
+        STORAGE         gtrgm;
+
+
+COMMIT;
diff --git a/contrib/pg_trgm/sql/pg_trgm.sql b/contrib/pg_trgm/sql/pg_trgm.sql
new file mode 100644 (file)
index 0000000..3545220
--- /dev/null
@@ -0,0 +1,30 @@
+\set ECHO none
+\i pg_trgm.sql
+\set ECHO all
+
+select show_trgm('');
+select show_trgm('(*&^$@%@');
+select show_trgm('a b c');
+select show_trgm(' a b c ');
+select show_trgm('aA bB cC');
+select show_trgm(' aA bB cC ');
+select show_trgm('a b C0*%^');
+
+select similarity('wow','WOWa ');
+select similarity('wow',' WOW ');
+
+CREATE TABLE test_trgm(t text);
+
+\copy test_trgm from 'data/trgm.data
+
+select t,similarity(t,'qwertyu0988') as sml from test_trgm where t % 'qwertyu0988' order by sml desc, t;
+select t,similarity(t,'gwertyu0988') as sml from test_trgm where t % 'gwertyu0988' order by sml desc, t;
+select t,similarity(t,'gwertyu1988') as sml from test_trgm where t % 'gwertyu1988' order by sml desc, t;
+
+create index trgm_idx on test_trgm using gist (t gist_trgm_ops);
+set enable_seqscan=off;
+
+select t,similarity(t,'qwertyu0988') as sml from test_trgm where t % 'qwertyu0988' order by sml desc, t;
+select t,similarity(t,'gwertyu0988') as sml from test_trgm where t % 'gwertyu0988' order by sml desc, t;
+select t,similarity(t,'gwertyu1988') as sml from test_trgm where t % 'gwertyu1988' order by sml desc, t;
+
diff --git a/contrib/pg_trgm/trgm.h b/contrib/pg_trgm/trgm.h
new file mode 100644 (file)
index 0000000..a56edca
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef __TRGM_H__
+#define __TRGM_H__
+
+#include "postgres.h"
+
+#include "access/gist.h"
+#include "access/itup.h"
+#include "utils/elog.h"
+#include "utils/palloc.h"
+#include "utils/builtins.h"
+#include "storage/bufpage.h"
+
+/* options */
+#define LPADDING        2
+#define RPADDING        1
+#define KEEPONLYALNUM
+#define IGNORECASE  
+#define DIVUNION
+
+
+typedef char trgm[3];
+
+#define CMPCHAR(a,b) ( ((a)==(b)) ? 0 : ( ((a)<(b)) ? -1 : 1 ) )
+#define CMPPCHAR(a,b,i)  CMPCHAR( *(((char*)(a))+i), *(((char*)(b))+i) ) 
+#define CMPTRGM(a,b) ( CMPPCHAR(a,b,0) ? CMPPCHAR(a,b,0) : ( CMPPCHAR(a,b,1) ? CMPPCHAR(a,b,1) : CMPPCHAR(a,b,2) ) )
+
+#define CPTRGM(a,b) do {                       \
+       *(((char*)(a))+0) = *(((char*)(b))+0);  \
+       *(((char*)(a))+1) = *(((char*)(b))+1);  \
+       *(((char*)(a))+2) = *(((char*)(b))+2);  \
+} while(0);
+
+
+typedef struct {
+       int4    len;
+       uint8   flag;
+       char    data[1];
+} TRGM;
+
+#define TRGMHRDSIZE       (sizeof(int4)+sizeof(uint8))
+
+/* gist */
+#define BITBYTE 8
+#define SIGLENINT  3               /* >122 => key will toast, so very slow!!! */
+#define SIGLEN  ( sizeof(int)*SIGLENINT )
+
+#define SIGLENBIT (SIGLEN*BITBYTE - 1) /* see makesign */ 
+
+typedef char BITVEC[SIGLEN];
+typedef char *BITVECP;
+
+#define LOOPBYTE(a) \
+                for(i=0;i<SIGLEN;i++) {\
+                                a;\
+                }
+
+#define LOOPBIT(a) \
+                for(i=0;i<SIGLENBIT;i++) {\
+                                a;\
+                }
+
+#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
+#define GETBITBYTE(x,i) ( ((char)(x)) >> i & 0x01 )
+#define CLRBIT(x,i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
+#define SETBIT(x,i)   GETBYTE(x,i) |=  ( 0x01 << ( (i) % BITBYTE ) )
+#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
+
+#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
+#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
+
+#define ARRKEY          0x01
+#define SIGNKEY         0x02
+#define ALLISTRUE       0x04
+   
+#define ISARRKEY(x) ( ((TRGM*)x)->flag & ARRKEY )
+#define ISSIGNKEY(x)    ( ((TRGM*)x)->flag & SIGNKEY )
+#define ISALLTRUE(x)    ( ((TRGM*)x)->flag & ALLISTRUE )
+
+#define CALCGTSIZE(flag, len) ( TRGMHRDSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(trgm)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
+#define GETSIGN(x)      ( (BITVECP)( (char*)x+TRGMHRDSIZE ) )
+#define GETARR(x)       ( (trgm*)( (char*)x+TRGMHRDSIZE ) )
+#define ARRNELEM(x) ( ( ((TRGM*)x)->len - TRGMHRDSIZE )/sizeof(trgm) )
+
+extern float4 trgm_limit;
+TRGM* generate_trgm(char *str, int slen);
+float4 cnt_sml(TRGM *trg1, TRGM *trg2);
+
+#endif
diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c
new file mode 100644 (file)
index 0000000..6f30a44
--- /dev/null
@@ -0,0 +1,566 @@
+#include "trgm.h"
+
+#include "access/gist.h"
+#include "access/itup.h"
+#include "access/rtree.h"
+#include "utils/elog.h"
+#include "utils/palloc.h"
+#include "utils/array.h"
+#include "utils/builtins.h"
+#include "storage/bufpage.h"
+#include "access/tuptoaster.h"
+
+PG_FUNCTION_INFO_V1(gtrgm_in);
+Datum          gtrgm_in(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_out);
+Datum          gtrgm_out(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_compress);
+Datum          gtrgm_compress(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_decompress);
+Datum          gtrgm_decompress(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_consistent);
+Datum          gtrgm_consistent(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_union);
+Datum          gtrgm_union(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_same);
+Datum          gtrgm_same(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_penalty);
+Datum          gtrgm_penalty(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(gtrgm_picksplit);
+Datum          gtrgm_picksplit(PG_FUNCTION_ARGS);
+
+#define GETENTRY(vec,pos) ((TRGM *) DatumGetPointer((vec)->vector[(pos)].key))
+
+#define SUMBIT(val) (           \
+       GETBITBYTE(val,0) + \
+       GETBITBYTE(val,1) + \
+       GETBITBYTE(val,2) + \
+       GETBITBYTE(val,3) + \
+       GETBITBYTE(val,4) + \
+       GETBITBYTE(val,5) + \
+       GETBITBYTE(val,6) + \
+       GETBITBYTE(val,7)       \
+)
+
+
+Datum
+gtrgm_in(PG_FUNCTION_ARGS)
+{
+       elog(ERROR, "Not implemented");
+       PG_RETURN_DATUM(0);
+}
+
+Datum
+gtrgm_out(PG_FUNCTION_ARGS)
+{
+       elog(ERROR, "Not implemented");
+       PG_RETURN_DATUM(0);
+}
+
+static void
+makesign(BITVECP sign, TRGM * a)
+{
+       int4            k,
+                               len = ARRNELEM(a);
+       trgm       *ptr = GETARR(a);
+       int4 tmp=0;
+
+       MemSet((void *) sign, 0, sizeof(BITVEC));
+       SETBIT(sign, SIGLENBIT); /*set last unused bit*/
+       for (k = 0; k < len; k++) {
+               CPTRGM( ((char*)&tmp), ptr+k );
+               HASH(sign, tmp);
+       }
+}
+
+Datum
+gtrgm_compress(PG_FUNCTION_ARGS)
+{
+       GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+       GISTENTRY  *retval = entry;
+
+       if (entry->leafkey)
+       {                                                       /* trgm */
+               TRGM   *res;
+               text       *toastedval = (text *) DatumGetPointer(entry->key);
+               text       *val = (text *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+
+               res = generate_trgm(VARDATA(val), VARSIZE(val) - VARHDRSZ);
+               if (val != toastedval)
+                       pfree(val);
+
+               retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+               gistentryinit(*retval, PointerGetDatum(res),
+                                         entry->rel, entry->page,
+                                         entry->offset, res->len, FALSE);
+       }
+       else if (ISSIGNKEY(DatumGetPointer(entry->key)) &&
+                        !ISALLTRUE(DatumGetPointer(entry->key)))
+       {
+               int4            i,
+                                       len;
+               TRGM   *res;
+               BITVECP         sign = GETSIGN(DatumGetPointer(entry->key));
+
+               LOOPBYTE(
+                                if ((sign[i] & 0xff) != 0xff)
+                                PG_RETURN_POINTER(retval);
+               );
+
+               len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
+               res = (TRGM *) palloc(len);
+               res->len = len;
+               res->flag = SIGNKEY | ALLISTRUE;
+
+               retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+               gistentryinit(*retval, PointerGetDatum(res),
+                                         entry->rel, entry->page,
+                                         entry->offset, res->len, FALSE);
+       }
+       PG_RETURN_POINTER(retval);
+}
+
+Datum
+gtrgm_decompress(PG_FUNCTION_ARGS)
+{
+       PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+}
+
+Datum
+gtrgm_consistent(PG_FUNCTION_ARGS)
+{
+       text  *query = (text *) PG_GETARG_TEXT_P(1);
+       TRGM   *key = (TRGM *) DatumGetPointer( ((GISTENTRY *) PG_GETARG_POINTER(0))->key );
+       TRGM   *qtrg = generate_trgm(VARDATA(query), VARSIZE(query) - VARHDRSZ);
+       int res=false;
+
+       if ( GIST_LEAF( (GISTENTRY *) PG_GETARG_POINTER(0) ) ) { /* all leafs contains orig trgm */
+               float4 tmpsml = cnt_sml(key,qtrg);
+                       /* strange bug at freebsd 5.2.1 and gcc 3.3.3 */
+               res = ( *(int*)&tmpsml==*(int*)&trgm_limit || tmpsml > trgm_limit ) ? true : false;
+       } else if ( ISALLTRUE(key) ) { /* non-leaf contains signature */
+               res = true;
+       } else { /* non-leaf contains signature */
+               int4 count=0;
+               int4    k, len = ARRNELEM(qtrg);
+               trgm       *ptr = GETARR(qtrg);
+               BITVECP    sign = GETSIGN(key);
+               int4 tmp=0;
+
+               for (k = 0; k < len; k++) {
+                       CPTRGM( ((char*)&tmp), ptr+k );
+                       count += GETBIT(sign, HASHVAL(tmp));
+               }
+#ifdef DIVUNION
+               res = ( len==count ) ? true : ( ( ( ( ((float4)count) / ((float4)(len-count)) ) ) >= trgm_limit ) ? true : false );
+#else
+               res = (len==0) ? false : ( ( ( ( ((float4)count) / ((float4)len) ) ) >= trgm_limit ) ? true : false );
+#endif
+       }
+
+       PG_FREE_IF_COPY(query,1);
+       pfree(qtrg); 
+
+       PG_RETURN_BOOL(res);
+}
+
+static int4
+unionkey(BITVECP sbase, TRGM * add)
+{
+       int4            i;
+
+       if (ISSIGNKEY(add))
+       {
+               BITVECP         sadd = GETSIGN(add);
+
+               if (ISALLTRUE(add))
+                       return 1;
+
+               LOOPBYTE(
+                                sbase[i] |= sadd[i];
+               );
+       }
+       else
+       {
+               trgm       *ptr = GETARR(add);
+               int4 tmp=0;
+
+               for (i = 0; i < ARRNELEM(add); i++) {
+                       CPTRGM( ((char*)&tmp), ptr+i );
+                       HASH(sbase, tmp);
+               }
+       }
+       return 0;
+}
+
+
+Datum
+gtrgm_union(PG_FUNCTION_ARGS)
+{
+        GistEntryVector      *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+        int4        len = entryvec->n;
+       int                *size = (int *) PG_GETARG_POINTER(1);
+       BITVEC          base;
+       int4            i;
+       int4            flag = 0;
+       TRGM   *result;
+
+       MemSet((void *) base, 0, sizeof(BITVEC));
+       for (i = 0; i < len; i++)
+       {
+               if (unionkey(base, GETENTRY(entryvec, i)))
+               {
+                       flag = ALLISTRUE;
+                       break;
+               }
+       }
+
+       flag |= SIGNKEY;
+       len = CALCGTSIZE(flag, 0);
+       result = (TRGM *) palloc(len);
+       *size = result->len = len;
+       result->flag = flag;
+       if (!ISALLTRUE(result))
+               memcpy((void *) GETSIGN(result), (void *) base, sizeof(BITVEC));
+
+       PG_RETURN_POINTER(result);
+}
+
+Datum
+gtrgm_same(PG_FUNCTION_ARGS)
+{
+       TRGM   *a = (TRGM *) PG_GETARG_POINTER(0);
+       TRGM   *b = (TRGM *) PG_GETARG_POINTER(1);
+       bool       *result = (bool *) PG_GETARG_POINTER(2);
+
+       if (ISSIGNKEY(a))
+       {                                                       /* then b also ISSIGNKEY */
+               if (ISALLTRUE(a) && ISALLTRUE(b))
+                       *result = true;
+               else if (ISALLTRUE(a))
+                       *result = false;
+               else if (ISALLTRUE(b))
+                       *result = false;
+               else
+               {
+                       int4            i;
+                       BITVECP         sa = GETSIGN(a),
+                                               sb = GETSIGN(b);
+
+                       *result = true;
+                       LOOPBYTE(
+                                        if (sa[i] != sb[i])
+                                        {
+                               *result = false;
+                               break;
+                       }
+                       );
+               }
+       }
+       else
+       {                                                       /* a and b ISARRKEY */
+               int4            lena = ARRNELEM(a),
+                                       lenb = ARRNELEM(b);
+
+               if (lena != lenb)
+                       *result = false;
+               else
+               {
+                       trgm       *ptra = GETARR(a),
+                                          *ptrb = GETARR(b);
+                       int4            i;
+
+                       *result = true;
+                       for (i = 0; i < lena; i++)
+                               if (CMPTRGM(ptra+i, ptrb+i))
+                               {
+                                       *result = false;
+                                       break;
+                               }
+               }
+       }
+
+       PG_RETURN_POINTER(result);
+}
+
+static int4
+sizebitvec(BITVECP sign)
+{
+       int4            size = 0,
+                               i;
+
+       LOOPBYTE(
+               size += SUMBIT(*(char *) sign);
+               sign = (BITVECP) (((char *) sign) + 1);
+       );
+       return size;
+}
+
+static int
+hemdistsign(BITVECP  a, BITVECP b) {
+       int i,dist=0;
+
+       LOOPBIT(
+               if ( GETBIT(a,i) != GETBIT(b,i) )
+                       dist++;
+       );
+       return dist;
+}
+
+static int
+hemdist(TRGM   *a, TRGM   *b) {
+       if ( ISALLTRUE(a) ) {
+               if (ISALLTRUE(b))
+                       return 0;
+               else
+                       return SIGLENBIT-sizebitvec(GETSIGN(b));
+       } else if (ISALLTRUE(b))
+               return SIGLENBIT-sizebitvec(GETSIGN(a));
+
+       return hemdistsign( GETSIGN(a), GETSIGN(b) );
+}
+
+Datum
+gtrgm_penalty(PG_FUNCTION_ARGS)
+{
+       GISTENTRY  *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */
+       GISTENTRY  *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
+       float      *penalty = (float *) PG_GETARG_POINTER(2);
+       TRGM   *origval = (TRGM *) DatumGetPointer(origentry->key);
+       TRGM   *newval = (TRGM *) DatumGetPointer(newentry->key);
+       BITVECP         orig = GETSIGN(origval);
+
+       *penalty = 0.0;
+
+       if (ISARRKEY(newval)) {
+               BITVEC sign;
+               makesign(sign, newval);
+
+               if ( ISALLTRUE(origval) ) 
+                       *penalty=((float)(SIGLENBIT-sizebitvec(sign)))/(float)(SIGLENBIT+1);
+               else 
+                       *penalty=hemdistsign(sign,orig);
+       } else {
+               *penalty=hemdist(origval,newval);
+       }
+       PG_RETURN_POINTER(penalty);
+}
+
+typedef struct
+{
+       bool            allistrue;
+       BITVEC          sign;
+}      CACHESIGN;
+
+static void
+fillcache(CACHESIGN * item, TRGM * key)
+{
+       item->allistrue = false;
+       if (ISARRKEY(key))
+               makesign(item->sign, key);
+       else if (ISALLTRUE(key))
+               item->allistrue = true;
+       else
+               memcpy((void *) item->sign, (void *) GETSIGN(key), sizeof(BITVEC));
+}
+
+#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+typedef struct
+{
+       OffsetNumber pos;
+       int4            cost;
+} SPLITCOST;
+
+static int
+comparecost(const void *a, const void *b)
+{
+       if (((SPLITCOST *) a)->cost == ((SPLITCOST *) b)->cost)
+               return 0;
+       else
+               return (((SPLITCOST *) a)->cost > ((SPLITCOST *) b)->cost) ? 1 : -1;
+}
+
+
+static int
+hemdistcache(CACHESIGN   *a, CACHESIGN   *b) {
+       if ( a->allistrue ) {
+               if (b->allistrue)
+                       return 0;
+               else
+                       return SIGLENBIT-sizebitvec(b->sign);
+       } else if (b->allistrue)
+               return SIGLENBIT-sizebitvec(a->sign);
+
+       return hemdistsign( a->sign, b->sign );
+}
+
+Datum
+gtrgm_picksplit(PG_FUNCTION_ARGS)
+{
+        GistEntryVector      *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+        OffsetNumber maxoff = entryvec->n - 2;
+       GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
+       OffsetNumber k,
+                               j;
+       TRGM   *datum_l,
+                          *datum_r;
+       BITVECP         union_l,
+                               union_r;
+       int4            size_alpha,
+                               size_beta;
+       int4            size_waste,
+                               waste = -1;
+       int4            nbytes;
+       OffsetNumber seed_1 = 0,
+                               seed_2 = 0;
+       OffsetNumber *left,
+                          *right;
+       BITVECP         ptr;
+       int                     i;
+       CACHESIGN  *cache;
+       SPLITCOST  *costvector;
+
+       nbytes = (maxoff + 2) * sizeof(OffsetNumber);
+       v->spl_left = (OffsetNumber *) palloc(nbytes);
+       v->spl_right = (OffsetNumber *) palloc(nbytes);
+
+       cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2));
+       fillcache(&cache[FirstOffsetNumber], GETENTRY(entryvec, FirstOffsetNumber));
+
+       for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) {
+               for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) {
+                       if (k == FirstOffsetNumber)
+                               fillcache(&cache[j], GETENTRY(entryvec, j));
+
+                       size_waste=hemdistcache(&(cache[j]),&(cache[k]));
+                       if (size_waste > waste) {
+                               waste = size_waste;
+                               seed_1 = k;
+                               seed_2 = j;
+                       }
+               }
+       }
+
+       left = v->spl_left;
+       v->spl_nleft = 0;
+       right = v->spl_right;
+       v->spl_nright = 0;
+
+       if (seed_1 == 0 || seed_2 == 0) {
+               seed_1 = 1;
+               seed_2 = 2;
+       }
+
+       /* form initial .. */
+       if (cache[seed_1].allistrue) {
+               datum_l = (TRGM *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
+               datum_l->len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
+               datum_l->flag = SIGNKEY | ALLISTRUE;
+       } else {
+               datum_l = (TRGM *) palloc(CALCGTSIZE(SIGNKEY, 0));
+               datum_l->len = CALCGTSIZE(SIGNKEY, 0);
+               datum_l->flag = SIGNKEY;
+               memcpy((void *) GETSIGN(datum_l), (void *) cache[seed_1].sign, sizeof(BITVEC));
+       }
+       if (cache[seed_2].allistrue) {
+               datum_r = (TRGM *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
+               datum_r->len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
+               datum_r->flag = SIGNKEY | ALLISTRUE;
+       } else {
+               datum_r = (TRGM *) palloc(CALCGTSIZE(SIGNKEY, 0));
+               datum_r->len = CALCGTSIZE(SIGNKEY, 0);
+               datum_r->flag = SIGNKEY;
+               memcpy((void *) GETSIGN(datum_r), (void *) cache[seed_2].sign, sizeof(BITVEC));
+       }
+
+       union_l=GETSIGN(datum_l);
+       union_r=GETSIGN(datum_r);
+       maxoff = OffsetNumberNext(maxoff);
+       fillcache(&cache[maxoff], GETENTRY(entryvec, maxoff));
+       /* sort before ... */
+       costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+       for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) {
+               costvector[j - 1].pos = j;
+               size_alpha = hemdistcache(&(cache[seed_1]), &(cache[j]));
+               size_beta  = hemdistcache(&(cache[seed_2]), &(cache[j]));
+               costvector[j - 1].cost = abs(size_alpha - size_beta);
+       }
+       qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
+
+       for (k = 0; k < maxoff; k++) {
+               j = costvector[k].pos;
+               if (j == seed_1) {
+                       *left++ = j;
+                       v->spl_nleft++;
+                       continue;
+               } else if (j == seed_2) {
+                       *right++ = j;
+                       v->spl_nright++;
+                       continue;
+               }
+
+               if (ISALLTRUE(datum_l) || cache[j].allistrue) {
+                       if ( ISALLTRUE(datum_l) && cache[j].allistrue )
+                               size_alpha=0;
+                       else
+                               size_alpha = SIGLENBIT-sizebitvec(  
+                                       ( cache[j].allistrue ) ? GETSIGN(datum_l) : GETSIGN(cache[j].sign)  
+                               );
+               } else {
+                       size_alpha=hemdistsign(cache[j].sign,GETSIGN(datum_l));
+               }
+
+               if (ISALLTRUE(datum_r) || cache[j].allistrue) {
+                       if ( ISALLTRUE(datum_r) && cache[j].allistrue )
+                               size_beta=0;
+                       else
+                               size_beta = SIGLENBIT-sizebitvec(  
+                                       ( cache[j].allistrue ) ? GETSIGN(datum_r) : GETSIGN(cache[j].sign)  
+                               );
+               } else {
+                       size_beta=hemdistsign(cache[j].sign,GETSIGN(datum_r));
+               }
+
+               if (size_alpha  < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.1)) {
+                       if (ISALLTRUE(datum_l) || cache[j].allistrue) {
+                               if (! ISALLTRUE(datum_l) )
+                                       MemSet((void *) GETSIGN(datum_l), 0xff, sizeof(BITVEC));
+                       } else {
+                               ptr=cache[j].sign;
+                               LOOPBYTE(
+                                       union_l[i] |= ptr[i];
+                               );
+                       }
+                       *left++ = j;
+                       v->spl_nleft++;
+               } else {
+                       if (ISALLTRUE(datum_r) || cache[j].allistrue) {
+                               if (! ISALLTRUE(datum_r) )
+                                       MemSet((void *) GETSIGN(datum_r), 0xff, sizeof(BITVEC));
+                       } else {
+                               ptr=cache[j].sign;
+                               LOOPBYTE(
+                                       union_r[i] |= ptr[i];
+                               );
+                       }
+                       *right++ = j;
+                       v->spl_nright++;
+               }
+       }
+
+       *right = *left = FirstOffsetNumber;
+       pfree(costvector);
+       pfree(cache);
+       v->spl_ldatum = PointerGetDatum(datum_l);
+       v->spl_rdatum = PointerGetDatum(datum_r);
+
+       PG_RETURN_POINTER(v);
+}
diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c
new file mode 100644 (file)
index 0000000..01ece90
--- /dev/null
@@ -0,0 +1,269 @@
+#include "trgm.h"
+#include <ctype.h>
+#include "utils/array.h"
+#include "catalog/pg_type.h"
+
+float4 trgm_limit = 0.3;
+
+PG_FUNCTION_INFO_V1(set_limit);
+Datum set_limit(PG_FUNCTION_ARGS);
+Datum
+set_limit(PG_FUNCTION_ARGS) {
+       float4 nlimit = PG_GETARG_FLOAT4(0);
+       if ( nlimit < 0 || nlimit > 1.0 ) 
+               elog(ERROR,"Wrong limit, should be between 0 and 1");
+       trgm_limit = nlimit;
+       PG_RETURN_FLOAT4(trgm_limit);
+}
+
+PG_FUNCTION_INFO_V1(show_limit);
+Datum show_limit(PG_FUNCTION_ARGS);
+Datum
+show_limit(PG_FUNCTION_ARGS) {
+       PG_RETURN_FLOAT4(trgm_limit);
+}
+
+#define WORDWAIT        0
+#define INWORD          1
+
+static int
+comp_trgm(const void *a, const void *b) {
+       return CMPTRGM(a,b);
+}
+
+static int
+unique_array (trgm *a, int len) {
+       trgm *curend, *tmp;
+
+       curend = tmp = a;
+       while (tmp - a < len)
+               if ( CMPTRGM(tmp, curend) ) {
+                       curend++;
+                       CPTRGM(curend,tmp);
+                       tmp++;
+               } else
+                       tmp++;
+       return curend + 1 - a;
+}
+
+
+TRGM*
+generate_trgm(char *str, int slen) {
+       TRGM*   trg;
+       char    *buf,*sptr,*bufptr;
+       trgm    *tptr;
+       int     state=WORDWAIT;
+       int wl,len;
+
+       trg = (TRGM*) palloc(TRGMHRDSIZE+sizeof(trgm) * (slen/2 + 1) * 3);
+       trg->flag = ARRKEY;
+       trg->len = TRGMHRDSIZE;
+
+       if ( slen+LPADDING+RPADDING<3 || slen == 0 )
+               return trg;
+
+       tptr = GETARR(trg);
+
+       buf = palloc(sizeof(char) * (slen+4));
+       sptr = str;
+
+       if ( LPADDING > 0 ) {
+               *buf = ' ';
+               if ( LPADDING > 1 )
+                       *(buf+1) = ' ';
+       }
+
+       bufptr = buf+LPADDING;
+       while( sptr-str < slen ) {
+               if ( state == WORDWAIT ) {
+                       if ( 
+#ifdef KEEPONLYALNUM
+                               isalnum((unsigned char)*sptr)
+#else
+                               !isspace( (unsigned char)*sptr )
+#endif
+                               ) {
+                               *bufptr = *sptr; /* start put word in buffer */
+                               bufptr++;
+                               state = INWORD;
+                               if ( sptr-str == slen-1 /* last char */ )
+                                       goto gettrg;
+                       }
+               } else {
+                       if (
+#ifdef KEEPONLYALNUM
+                               !isalnum((unsigned char)*sptr)
+#else
+                               isspace( (unsigned char)*sptr )                 
+#endif
+                               ) {
+gettrg:
+                               /* word in buffer, so count trigrams */
+                               *bufptr = ' ';
+                               *(bufptr+1) = ' ';
+                               wl = bufptr - (buf+LPADDING) - 2 + LPADDING + RPADDING;
+                               if ( wl<=0 ) {
+                                       bufptr = buf+LPADDING;
+                                       state = WORDWAIT;
+                                       sptr++;
+                                       continue;
+                               }
+
+#ifdef IGNORECASE
+                               do { /* lower word */
+                                       int wwl = bufptr-buf;
+                                       bufptr = buf+LPADDING;
+                                       while( bufptr-buf < wwl ) {
+                                               *bufptr = tolower( (unsigned char) *bufptr );
+                                               bufptr++;
+                                       }
+                               } while(0);
+#endif
+                               bufptr = buf;
+                               /* set trigrams */
+                               while( bufptr-buf < wl ) {
+                                       CPTRGM(tptr, bufptr);
+                                       bufptr++;
+                                       tptr++;
+                               }
+                               bufptr = buf+LPADDING;
+                               state = WORDWAIT;
+                       } else {
+                               *bufptr = *sptr; /* put in buffer */
+                               bufptr++;
+                               if ( sptr-str == slen-1 )
+                                       goto gettrg;
+                       }
+               }
+               sptr++;
+       }
+
+       pfree(buf);
+
+       if ( (len=tptr-GETARR(trg)) == 0 ) 
+               return trg;
+
+       if ( len>0 ) {
+               qsort( (void*)GETARR(trg), len, sizeof(trgm), comp_trgm );
+               len = unique_array( GETARR(trg), len );
+       } 
+
+       trg->len = CALCGTSIZE(ARRKEY, len);
+
+       return trg;
+}
+
+
+PG_FUNCTION_INFO_V1(show_trgm);
+Datum show_trgm(PG_FUNCTION_ARGS);
+Datum
+show_trgm(PG_FUNCTION_ARGS) {
+       text       *in = PG_GETARG_TEXT_P(0);
+       TRGM    *trg;
+       Datum *d;
+       ArrayType *a;
+       trgm *ptr;
+
+       trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ);
+       d = (Datum*)palloc( sizeof(Datum)*(1+ARRNELEM(trg)) );
+
+       ptr = GETARR(trg);
+       while( ptr-GETARR(trg) < ARRNELEM(trg) ) {
+               text *item=(text*)palloc(VARHDRSZ + 3);
+               VARATT_SIZEP(item) = VARHDRSZ+3;
+               CPTRGM(VARDATA(item), ptr);
+               d[ ptr-GETARR(trg) ] = PointerGetDatum(item);
+               ptr++;
+       }
+
+       a = construct_array(
+               d,
+               ARRNELEM(trg),
+               TEXTOID,
+               -1,
+               false,
+               'i'
+       );
+
+       ptr = GETARR(trg);
+       while( ptr-GETARR(trg) < ARRNELEM(trg) ) {
+               pfree(DatumGetPointer(d[ ptr-GETARR(trg) ]));
+               ptr++;
+       }
+       
+       pfree(d);
+       pfree(trg);
+       PG_FREE_IF_COPY(in,0);
+
+       PG_RETURN_POINTER(a);
+}
+
+float4
+cnt_sml(TRGM *trg1, TRGM *trg2) {
+       trgm    *ptr1, *ptr2;
+       int count=0;
+       int len1, len2;
+       
+       ptr1 = GETARR(trg1);
+       ptr2 = GETARR(trg2);
+       
+       len1 = ARRNELEM(trg1);
+       len2 = ARRNELEM(trg2);
+
+       while( ptr1 - GETARR(trg1) < len1 && ptr2 - GETARR(trg2) < len2 ) {
+               int res = CMPTRGM(ptr1,ptr2);
+               if ( res < 0 ) {
+                       ptr1++;
+               } else if ( res > 0 ) {
+                       ptr2++;
+               } else {
+                       ptr1++;
+                       ptr2++;
+                       count++;
+               }
+       }
+
+#ifdef DIVUNION
+       return ( ( ((float4)count) / ((float4)(len1+len2-count)) ) );
+#else
+       return ( ((float)count) / ((float)( (len1>len2) ? len1 : len2 )) );
+#endif
+
+}
+
+PG_FUNCTION_INFO_V1(similarity);
+Datum similarity(PG_FUNCTION_ARGS);
+Datum
+similarity(PG_FUNCTION_ARGS) {
+       text       *in1 = PG_GETARG_TEXT_P(0);
+       text       *in2 = PG_GETARG_TEXT_P(1);
+       TRGM    *trg1, *trg2;
+       float4 res;
+
+       trg1 = generate_trgm(VARDATA(in1), VARSIZE(in1) - VARHDRSZ);
+       trg2 = generate_trgm(VARDATA(in2), VARSIZE(in2) - VARHDRSZ);
+
+       res = cnt_sml(trg1,trg2);
+       
+       pfree(trg1);
+       pfree(trg2);
+       PG_FREE_IF_COPY(in1,0);
+       PG_FREE_IF_COPY(in2,1);
+       
+       PG_RETURN_FLOAT4(res);
+}
+
+PG_FUNCTION_INFO_V1(similarity_op);
+Datum similarity_op(PG_FUNCTION_ARGS);
+Datum
+similarity_op(PG_FUNCTION_ARGS) {
+       float4 res=DatumGetFloat4( DirectFunctionCall2(
+               similarity,
+               PG_GETARG_DATUM(0),
+               PG_GETARG_DATUM(1)
+       ) );
+       PG_RETURN_BOOL( res >= trgm_limit );
+}
+
+