search_lingo 2.0.0.pre3 → 2.0.0

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
  SHA256:
3
- metadata.gz: 3a72223dbfe08f7309fc060e7bb30afd3e4941810ba9f52fcf50340d6573db74
4
- data.tar.gz: c560f79d14abbf7daa9a570ac0594184afb0aca4f69acf66ed86f4af15c6d5be
3
+ metadata.gz: d697959cb461bb00ba17b4dbd3fe71037db81c65d3253fc22c42c27b69228f2e
4
+ data.tar.gz: 2a96f4b480d60d052bd1bf7f7ae02f645386144dbebccfacaa9ecfbf56fbbd30
5
5
  SHA512:
6
- metadata.gz: 343f682d46cf9ea34fafa75499790e0e0a0474e812c8c00cce81fe75b3f2f1b5de66975d0e2d975f4eca8e12deeedf2e9b927ebcce425fef9871d5405b686023
7
- data.tar.gz: 725c8dca98f88dd630475c200e7b2ecb0347cb191df5d10e7e0dae9ac0c3e3d815e2830966f2bf18c6bd5448842a78a946a5ec6e60a6e58acaf83aa586adc6d8
6
+ metadata.gz: aa98221d0840199c0ed21f96412f39fd82567210d8f99d1b2767a0b8f718ba2f1039f1624e7f9d04a63bd7b0c6a22d00ecbe81ddb4c8986322dfdda99da84b4f
7
+ data.tar.gz: 3ecc60bea0e32cc52548bbe5999e80704bc52e89ec0218f3076473220c14f8f4b2a5214bd8dadca5490b90a2229291dea960289819f53c9689bb4f3ab8859ac7
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.7
4
- - 2.4.4
5
- - 2.5.1
3
+ - 2.3.8
4
+ - 2.4.5
5
+ - 2.5.3
@@ -33,7 +33,7 @@ module SearchLingo
33
33
  # end
34
34
  # end
35
35
  class AbstractSearch
36
- attr_reader :query, :scope
36
+ attr_reader :query, :scope, :logger
37
37
 
38
38
  ##
39
39
  # Instantiates a new search object. +query+ is the string that is to be
@@ -42,9 +42,10 @@ module SearchLingo
42
42
  # should be sent, e.g., an +ActiveRecord::Relation+.
43
43
  #
44
44
  # MySearchClass.new 'foo bar: baz "froz quux"', Task.all
45
- def initialize(query, scope)
46
- @query = query || ''
47
- @scope = scope
45
+ def initialize(query, scope, logger: nil)
46
+ @query = query || ''
47
+ @scope = scope
48
+ @logger = logger
48
49
  end
49
50
 
50
51
  ##
@@ -98,26 +99,12 @@ module SearchLingo
98
99
  ##
99
100
  # Load search results by composing query string tokens into a query chain.
100
101
  #
101
- # @query is borken down into tokens, and each token is passed through the
102
- # list of defined parsers. If a parser is successful, +:match+ is thrown,
103
- # processing moves on to the next token. If none of the parsers succeed and
104
- # the token is compound, the token is simplified and reprocessed as before.
105
- # If still no parser succeeds, fall back on +#default_parse+.
102
+ # @query is broken down into tokens and parses each one in turn. The
103
+ # results of parsing each token are chained onto the end of +scope+ to
104
+ # compose the query.
106
105
  def load_results
107
106
  tokenizer.reduce(scope) do |chain, token|
108
- catch(:match) do
109
- # 1. Try each parser with token until :match is thrown.
110
- parse token, chain
111
-
112
- # 2. If :match not thrown and token is compund, simplify and retry.
113
- if token.compound?
114
- token = tokenizer.simplify
115
- parse token, chain
116
- end
117
-
118
- # 3. If :match still not thrown, fall back on default parser.
119
- default_parse token, chain
120
- end
107
+ parse token, chain
121
108
  end
122
109
  end
123
110
 
@@ -127,6 +114,26 @@ module SearchLingo
127
114
  @tokenizer ||= Tokenizer.new query
128
115
  end
129
116
 
117
+ ##
118
+ # Passes +token+ and +chain+ through the array of parsers until +:match+ is
119
+ # thrown. If none of the parsers match and the token is compound,
120
+ # simplifies the token and reruns the parsers. If no parsers match after
121
+ # the second pass or if the token was not compound, falls back on
122
+ # `#default_parse`.
123
+ def parse(token, chain)
124
+ catch(:match) do
125
+ run_parsers token, chain
126
+
127
+ if token.compound?
128
+ token = tokenizer.simplify
129
+ run_parsers token, chain
130
+ end
131
+
132
+ logger&.debug "default_parse token=#{token.inspect}"
133
+ default_parse token, chain
134
+ end
135
+ end
136
+
130
137
  ##
131
138
  # Passes +token+ to each parser in turn. If a parser succeeds, throws
132
139
  # +:match+ with the result.
@@ -134,10 +141,13 @@ module SearchLingo
134
141
  # A parser succeeds if +call+ returns a truthy value. A successful parser
135
142
  # will typically send something to +chain+ and return the result. In this
136
143
  # way, the tokens of the search are reduced into a composed query.
137
- def parse(token, chain)
144
+ def run_parsers(token, chain)
138
145
  parsers.each do |parser|
139
146
  result = parser.call token, chain
140
- throw :match, result if result
147
+ if result
148
+ logger&.debug "parser:#{parser.inspect} token=#{token.inspect}"
149
+ throw :match, result
150
+ end
141
151
  end
142
152
  nil
143
153
  end
@@ -39,11 +39,7 @@ module SearchLingo
39
39
  def initialize(column, modifier: nil, &block)
40
40
  @column = column
41
41
  @prefix = /#{modifier}:[[:space:]]*/ if modifier
42
- @append = if block_given?
43
- block
44
- else
45
- ->(chain) { chain }
46
- end
42
+ @append = block_given? ? block : ->(chain) { chain }
47
43
  end
48
44
 
49
45
  ##
@@ -63,7 +59,7 @@ module SearchLingo
63
59
  format '#<%<cls>s @prefix=%<prefix>s @column=%<column>s>',
64
60
  cls: self.class,
65
61
  prefix: prefix.inspect,
66
- column: column.inspect
62
+ column: "#{column.relation.name}.#{column.name}".inspect
67
63
  end
68
64
 
69
65
  private
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module SearchLingo
4
- VERSION = '2.0.0.pre3'
4
+ VERSION = '2.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_lingo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Parker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-06 00:00:00.000000000 Z
11
+ date: 2018-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -185,12 +185,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  version: '2.3'
186
186
  required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  requirements:
188
- - - ">"
188
+ - - ">="
189
189
  - !ruby/object:Gem::Version
190
- version: 1.3.1
190
+ version: '0'
191
191
  requirements: []
192
192
  rubyforge_project:
193
- rubygems_version: 2.7.7
193
+ rubygems_version: 2.7.8
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: Framework for defining and parsing search queries.