human-ql 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.rdoc +10 -0
- data/README.rdoc +1 -0
- data/Rakefile +7 -0
- data/lib/human-ql/base.rb +1 -1
- data/lib/human-ql/postgresql_custom_parser.rb +2 -2
- data/test/test_postgresql_fuzz.rb +2 -2
- data/test/test_postgresql_generator.rb +75 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98be83fa893f858ada46ea6938e4bf217662acc2
|
4
|
+
data.tar.gz: 56ae63c63848dca766c6ea66091e87409588710f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb36220c0a286185221e5b21a3592797ab72ce5924991a6f08376e96507c6f7e64d69945baa4a0260c5bea49f8da3ea9e91332409eb68f68523814fc32de992c
|
7
|
+
data.tar.gz: 560f9b4ce26140065beb8c2456e8227d34076e766eec8dddc447f8ece34c5dbe96de95f8041d8840c2bcd8d3ded1b86223fba091a0dd42fc8ec337d516c2bd50
|
data/History.rdoc
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 1.0.2 (2017-3-28)
|
2
|
+
|
3
|
+
* HumanQL::PostgreSQLCustomParser now treats backslashes and embedded
|
4
|
+
nulls as whitespace since these characters were found to be
|
5
|
+
significant to the PG tsquery parser.
|
6
|
+
|
7
|
+
* Additional phrase and text match tests in TestPostgreSQLGenerator.
|
8
|
+
|
9
|
+
* Travis CI config including PostgreSQL 9.6
|
10
|
+
|
1
11
|
=== 1.0.1 (2017-3-21)
|
2
12
|
|
3
13
|
* Drop more tokens, keep more characters in PostgreSQLCustomParser,
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
data/lib/human-ql/base.rb
CHANGED
@@ -58,13 +58,13 @@ module HumanQL
|
|
58
58
|
# whitespace. This can't include anything part of HumanQL,
|
59
59
|
# e.g. ':' as used for scopes, so deal with the remainder
|
60
60
|
# below.
|
61
|
-
self.spaces = /[[:space:]
|
61
|
+
self.spaces = /[[:space:]*!<>\0\\]+/.freeze
|
62
62
|
else
|
63
63
|
# Disable quote tokens
|
64
64
|
self.lquote = nil
|
65
65
|
self.rquote = nil
|
66
66
|
# As above but add DQUOTE as well.
|
67
|
-
self.spaces = /[[:space:]
|
67
|
+
self.spaces = /[[:space:]*!<>\0\\"]+/.freeze
|
68
68
|
end
|
69
69
|
|
70
70
|
# Use by custom #norm_phrase_tokens as a superset of the
|
@@ -64,8 +64,8 @@ class TestPostgresqlFuzz < Minitest::Test
|
|
64
64
|
# Starting point query
|
65
65
|
GENERIC_Q = 'ape | ( boy -"cat dog" )'.freeze
|
66
66
|
|
67
|
-
#
|
68
|
-
RANDOM_C = '({"
|
67
|
+
# Additional characters which could conceivably cause trouble
|
68
|
+
RANDOM_C = ( '({"a !:*\n\t ,^#:/-0.123e-9)&<>' + "\0\'\\" ).freeze
|
69
69
|
|
70
70
|
PASSES.times do |i|
|
71
71
|
define_method( "test_fuzz_#{i}" ) do
|
@@ -61,6 +61,22 @@ class TestPostgresqlGenerator < Minitest::Test
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def assert_tsq_match( tsq, text )
|
65
|
+
if DB
|
66
|
+
rt = DB[ "select to_tsvector(?) @@ to_tsquery(?) as m",
|
67
|
+
text, tsq ].first[ :m ]
|
68
|
+
assert_equal( true, rt )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def refute_tsq_match( tsq, text )
|
73
|
+
if DB
|
74
|
+
rt = DB[ "select to_tsvector(?) @@ to_tsquery(?) as m",
|
75
|
+
text, tsq ].first[ :m ]
|
76
|
+
assert_equal( false, rt )
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
64
80
|
def test_gen_term
|
65
81
|
assert_gen( 'ape', 'ape' )
|
66
82
|
assert_tsq( "'ape'", 'ape' )
|
@@ -87,6 +103,65 @@ class TestPostgresqlGenerator < Minitest::Test
|
|
87
103
|
assert_tsq( "'boy'", '": boy"' )
|
88
104
|
end
|
89
105
|
|
106
|
+
def test_phrase_or
|
107
|
+
skip( "For postgresql 9.6+" ) unless pg_gte_9_6?
|
108
|
+
# '<->' has precendence over '|'
|
109
|
+
assert_gen( "(ape <-> boy | dog <-> girl)",
|
110
|
+
'"ape boy" or "dog girl"' )
|
111
|
+
|
112
|
+
assert_tsq( tsq = "'ape' <-> 'boy' | 'dog' <-> 'girl'",
|
113
|
+
'"ape boy" or "dog girl"' )
|
114
|
+
|
115
|
+
refute_tsq_match( tsq, 'boy girl', )
|
116
|
+
refute_tsq_match( tsq, 'girl dog', )
|
117
|
+
|
118
|
+
assert_tsq_match( tsq, 'ape boy', )
|
119
|
+
assert_tsq_match( tsq, 'ape boy cat', )
|
120
|
+
assert_tsq_match( tsq, 'dog girl', )
|
121
|
+
assert_tsq_match( tsq, 'ape dog girl', )
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_phrase_stopword
|
125
|
+
assert_tsq( tsq = "'cat' <2> 'dog'", '"cat _ dog"' )
|
126
|
+
|
127
|
+
assert_tsq_match( tsq, 'cat goose dog' )
|
128
|
+
|
129
|
+
# '<2>' is exact, not up to...
|
130
|
+
refute_tsq_match( tsq, 'cat dog', )
|
131
|
+
refute_tsq_match( tsq, 'cat girl goose dog', )
|
132
|
+
|
133
|
+
# to_tsvector('cat a dog') -> 'cat':1 'dog':3
|
134
|
+
# to_tsvector('cat _ dog') -> 'cat':1 'dog':2
|
135
|
+
|
136
|
+
assert_tsq_match( tsq, 'cat a dog', )
|
137
|
+
refute_tsq_match( tsq, 'cat _ dog', )
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_phrase_apostrophe
|
141
|
+
skip( "For postgresql 9.6+" ) unless pg_gte_9_6?
|
142
|
+
|
143
|
+
# As of 9.6.2 this phrase won't match itself.
|
144
|
+
assert_gen( "cat's <-> rat", %{"cat's rat"} )
|
145
|
+
assert_tsq( tsq = "'cat' <-> 'rat'", %{"cat's rat"} )
|
146
|
+
|
147
|
+
assert_tsq_match( tsq, "cat rat", )
|
148
|
+
|
149
|
+
# to_tsvector('cat''s rat') -> 'cat':1 'rat':3
|
150
|
+
refute_tsq_match( tsq, "cat's rat", )
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_phrase_and
|
154
|
+
skip( "For postgresql 9.6+" ) unless pg_gte_9_6?
|
155
|
+
assert_gen( "johnson <-> johnson", '"johnson & johnson"' )
|
156
|
+
assert_tsq( tsq = "'johnson' <-> 'johnson'", '"johnson & johnson"' )
|
157
|
+
|
158
|
+
# to_tsvector('johnson & johnson') -> 'johnson':1,2
|
159
|
+
assert_tsq_match( tsq, "Johnson & Johnson", )
|
160
|
+
|
161
|
+
# to_tsvector('Johnson A Johnson') -> 'johnson':1,3
|
162
|
+
refute_tsq_match( tsq, "Johnson A Johnson", )
|
163
|
+
end
|
164
|
+
|
90
165
|
def test_gen_empty
|
91
166
|
assert_gen( nil, '' )
|
92
167
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human-ql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Kellum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 5.8.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.3.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: sequel
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|