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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51ffc03488bc280dbdb361e86b029a56c6deac74
4
- data.tar.gz: d02aac690117c9849b08a89558dece5c06db8a6c
3
+ metadata.gz: 98be83fa893f858ada46ea6938e4bf217662acc2
4
+ data.tar.gz: 56ae63c63848dca766c6ea66091e87409588710f
5
5
  SHA512:
6
- metadata.gz: c5f2be15113a044056f332b114c8ce768e71c3a3db4699812df2b46334446a68ceaec2dbd081044f707cf208b4722c565bd2bfaa0ccf24b7601bb65be0ee7679
7
- data.tar.gz: c4a773aedd6a5aeb7a5517115f1a266be27edab6a1741db739cfcc7585bda4594b30f824e4f19e8c2b8d54c3beb61038933bfa580a1da83d86d95406bbf139c7
6
+ metadata.gz: cb36220c0a286185221e5b21a3592797ab72ce5924991a6f08376e96507c6f7e64d69945baa4a0260c5bea49f8da3ea9e91332409eb68f68523814fc32de992c
7
+ data.tar.gz: 560f9b4ce26140065beb8c2456e8227d34076e766eec8dddc447f8ece34c5dbe96de95f8041d8840c2bcd8d3ded1b86223fba091a0dd42fc8ec337d516c2bd50
@@ -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,
@@ -2,6 +2,7 @@
2
2
 
3
3
  * http://github.com/dekellum/human-ql
4
4
  * http://rdoc.gravitext.com/human-ql/
5
+ * {<img src="https://travis-ci.org/dekellum/human-ql.svg?branch=dev" />}[https://travis-ci.org/dekellum/human-ql]
5
6
 
6
7
  == Description
7
8
 
data/Rakefile CHANGED
@@ -12,3 +12,10 @@ task :publish_rdoc => [ :clean, :rerdoc ] do
12
12
  aws s3 sync --acl public-read doc/ s3://rdoc.gravitext.com/human-ql/
13
13
  SH
14
14
  end
15
+
16
+ task :rdoc do
17
+ sh <<-SH
18
+ rm -rf doc/fonts
19
+ cp rdoc_css/*.css doc/css/
20
+ SH
21
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module HumanQL
18
18
 
19
- VERSION='1.0.1'
19
+ VERSION='1.0.2'
20
20
 
21
21
  end
@@ -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:]*!<>]+/.freeze
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:]*!<>"]+/.freeze
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
- # Characters which are likely to cause trouble
68
- RANDOM_C = '({"\'a !:* ,^#:/-0.123e-9)<>'.freeze
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.1
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-21 00:00:00.000000000 Z
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