togostanza 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/togostanza/application.rb +0 -16
- data/lib/togostanza/stanza/base.rb +0 -2
- data/lib/togostanza/version.rb +1 -1
- data/lib/togostanza.rb +0 -10
- metadata +2 -4
- data/lib/togostanza/stanza/search_query.rb +0 -87
- data/lib/togostanza/stanza/text_search.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09f09d3dd56cdf9a5299e8ae8500e8b04091bc2f
|
4
|
+
data.tar.gz: dad69b327df8f08983390439b91de9992076c9a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c4d2275cc2e31db6b8693c1c414ae92487d8647825323686f91eb14026bd6ab98a084a3c3423e083aebb4b7e2c6c85b92e3dcdf1c1829a0cffc03d14381dee
|
7
|
+
data.tar.gz: fab2e05345d3b10ba32a682be54a57f1c7408f7c8985a800020d03ac228e48ec8141a8693ddb2f682188c050f97b59f325c957077f1a21e51ff87070c84a67dd
|
@@ -56,22 +56,6 @@ module TogoStanza
|
|
56
56
|
render :html, @stanza.help, layout_engine: :haml
|
57
57
|
end
|
58
58
|
|
59
|
-
get '/:id/text_search' do |id|
|
60
|
-
@stanza = Stanza.find(id).new
|
61
|
-
stanza_uri = request.env['REQUEST_URI'].gsub(/\/text_search.*/, '')
|
62
|
-
|
63
|
-
begin
|
64
|
-
identifiers = @stanza.text_search(params[:q]).map {|param_hash|
|
65
|
-
parameters = Rack::Utils.build_query(param_hash)
|
66
|
-
"#{stanza_uri}?#{parameters}"
|
67
|
-
}
|
68
|
-
|
69
|
-
json enabled: true, count: identifiers.size, urls: identifiers
|
70
|
-
rescue NoSearchDeclarationError
|
71
|
-
json enabled: false, count: 0, urls: []
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
59
|
get '/:id/metadata.json' do |id|
|
76
60
|
@stanza = Stanza.find(id).new
|
77
61
|
|
@@ -158,7 +158,6 @@ module TogoStanza::Stanza
|
|
158
158
|
autoload :Grouping, 'togostanza/stanza/grouping'
|
159
159
|
autoload :Markdown, 'togostanza/stanza/markdown'
|
160
160
|
autoload :Querying, 'togostanza/stanza/querying'
|
161
|
-
autoload :TextSearch, 'togostanza/stanza/text_search'
|
162
161
|
|
163
162
|
class Context < Hashie::Mash
|
164
163
|
def respond_to_missing?(*)
|
@@ -171,7 +170,6 @@ module TogoStanza::Stanza
|
|
171
170
|
extend ExpressionMap::Macro
|
172
171
|
include Querying
|
173
172
|
include Grouping
|
174
|
-
include TextSearch
|
175
173
|
|
176
174
|
define_expression_map :properties
|
177
175
|
define_expression_map :resources
|
data/lib/togostanza/version.rb
CHANGED
data/lib/togostanza.rb
CHANGED
@@ -8,20 +8,10 @@ module TogoStanza
|
|
8
8
|
autoload :Stanza, 'togostanza/stanza'
|
9
9
|
|
10
10
|
class << self
|
11
|
-
attr_accessor :text_search_method
|
12
|
-
|
13
|
-
def configure
|
14
|
-
yield self
|
15
|
-
end
|
16
|
-
|
17
11
|
def sprockets
|
18
12
|
@sprockets ||= Sprockets::Environment.new.tap {|sprockets|
|
19
13
|
sprockets.append_path File.expand_path('../../assets', __FILE__)
|
20
14
|
}
|
21
15
|
end
|
22
16
|
end
|
23
|
-
|
24
|
-
configure do |config|
|
25
|
-
config.text_search_method = :regex
|
26
|
-
end
|
27
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: togostanza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keita Urashima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -286,8 +286,6 @@ files:
|
|
286
286
|
- lib/togostanza/stanza/grouping.rb
|
287
287
|
- lib/togostanza/stanza/markdown.rb
|
288
288
|
- lib/togostanza/stanza/querying.rb
|
289
|
-
- lib/togostanza/stanza/search_query.rb
|
290
|
-
- lib/togostanza/stanza/text_search.rb
|
291
289
|
- lib/togostanza/version.rb
|
292
290
|
- spec/dummy/app.rb
|
293
291
|
- spec/dummy/bar_stanza/help.md
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
module TogoStanza::Stanza
|
4
|
-
class SearchQuery
|
5
|
-
def initialize(query)
|
6
|
-
@raw = query
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :raw
|
10
|
-
|
11
|
-
def to_filter(method, var_name)
|
12
|
-
"FILTER (#{to_clause(method, var_name)})"
|
13
|
-
end
|
14
|
-
|
15
|
-
def tokens
|
16
|
-
@tokens ||= begin
|
17
|
-
scanner = StringScanner.new(@raw)
|
18
|
-
scanner.skip /\s+/
|
19
|
-
|
20
|
-
parse(scanner)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def to_clause(method, var_name)
|
27
|
-
case method.to_s
|
28
|
-
when 'regex', 'contains'
|
29
|
-
tokens.each_with_object('') {|token, acc|
|
30
|
-
case token
|
31
|
-
when :lparen
|
32
|
-
acc << '('
|
33
|
-
when :rparen
|
34
|
-
acc << ')'
|
35
|
-
when :or
|
36
|
-
acc << ' || '
|
37
|
-
when :and
|
38
|
-
acc << ' && '
|
39
|
-
else
|
40
|
-
acc << "#{method}(?#{var_name}, #{token.inspect})"
|
41
|
-
end
|
42
|
-
}
|
43
|
-
when 'bif_contains'
|
44
|
-
clause = tokens.each_with_object('') {|token, acc|
|
45
|
-
case token
|
46
|
-
when :lparen
|
47
|
-
acc << '('
|
48
|
-
when :rparen
|
49
|
-
acc << ')'
|
50
|
-
when :or
|
51
|
-
acc << ' OR '
|
52
|
-
when :and
|
53
|
-
acc << ' AND '
|
54
|
-
else
|
55
|
-
acc << token.inspect
|
56
|
-
end
|
57
|
-
}
|
58
|
-
|
59
|
-
"bif:contains(?#{var_name}, '#{clause}')"
|
60
|
-
else
|
61
|
-
raise ArgumentError, method
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def parse(scanner, tokens = [])
|
66
|
-
scanner.skip /\s+\z/
|
67
|
-
|
68
|
-
return tokens if scanner.eos?
|
69
|
-
|
70
|
-
if scanner.scan(/"((?:[^\\"]|\\.)*)"/)
|
71
|
-
tokens << scanner[1].gsub(/\\(.)/, '\1')
|
72
|
-
elsif scanner.scan(/\(\s*/)
|
73
|
-
tokens << :lparen
|
74
|
-
elsif scanner.scan(/\s*\)/)
|
75
|
-
tokens << :rparen
|
76
|
-
elsif scanner.scan(/\s*OR\s*/)
|
77
|
-
tokens << :or
|
78
|
-
elsif scanner.scan(/\s*AND\s*|\s+/)
|
79
|
-
tokens << :and
|
80
|
-
else
|
81
|
-
tokens << scanner.scan(/\S+(?<!\))/)
|
82
|
-
end
|
83
|
-
|
84
|
-
parse(scanner, tokens)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'togostanza/stanza/search_query'
|
2
|
-
|
3
|
-
class TogoStanza::NoSearchDeclarationError < StandardError; end
|
4
|
-
|
5
|
-
module TogoStanza::Stanza
|
6
|
-
module TextSearch
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
def text_search_filter(var_name, query)
|
10
|
-
query.to_filter(TogoStanza.text_search_method, var_name)
|
11
|
-
end
|
12
|
-
|
13
|
-
def text_search(input)
|
14
|
-
raise TogoStanza::NoSearchDeclarationError unless self.class.method_defined?(:search_declarations)
|
15
|
-
|
16
|
-
query = SearchQuery.new(input)
|
17
|
-
|
18
|
-
return [] if query.tokens.empty?
|
19
|
-
|
20
|
-
search_declarations.each_value.flat_map {|block|
|
21
|
-
instance_exec(query, &block)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
def search(symbol, &block)
|
27
|
-
unless method_defined?(:search_declarations)
|
28
|
-
# テキスト検索宣言の初期化
|
29
|
-
instance_eval do
|
30
|
-
class_attribute :search_declarations
|
31
|
-
self.search_declarations = {}
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
search_declarations[symbol] = block
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|