dusen 0.5 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 28383a66956bb8c3378bb0033387475fca743a53
|
4
|
+
data.tar.gz: 4b5dc66350c2c31cd070307a54b60296f8ed8dee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76ead2fcf071262ae45ea9d710c51150a668d6639752fa6750c4fa7908a11cd562eddb166be657d11d72dfe21009dcb8bcb16740ea29d39c2662cc871efc9936
|
7
|
+
data.tar.gz: a93bc1087afd7ddb94fc955dc0f0323d1fb8c581503c7659615b5738158fe70779eead5cf958ef3c5a7bea69b46f7e15a20278a3ff68652333c531d4683c12fd
|
data/lib/dusen/syntax.rb
CHANGED
@@ -21,20 +21,8 @@ module Dusen
|
|
21
21
|
query = query.condensed
|
22
22
|
matches = find_parsed_query(root_scope, query.include)
|
23
23
|
if query.exclude.any?
|
24
|
-
|
25
|
-
|
26
|
-
# extract conditions that were added by exclude tokens
|
27
|
-
sql = exclude_matches.to_sql
|
28
|
-
root_pattern = /\A#{Regexp.quote root_scope.to_sql}/
|
29
|
-
sql =~ root_pattern or raise "Could not find ..."
|
30
|
-
sql = sql.sub(root_pattern, '')
|
31
|
-
|
32
|
-
# negate conditions
|
33
|
-
sql = sql.sub(/^\s*WHERE\s*/i, '')
|
34
|
-
sql = sql.sub(/^\s*AND\s*/i, '')
|
35
|
-
sql = "NOT COALESCE(#{sql}, 0)"
|
36
|
-
|
37
|
-
matches.scoped(:conditions => sql)
|
24
|
+
inverted_exclude_scope = build_exclude_scope(root_scope, query.exclude)
|
25
|
+
matches.merge(inverted_exclude_scope)
|
38
26
|
else
|
39
27
|
matches
|
40
28
|
end
|
@@ -73,5 +61,23 @@ module Dusen
|
|
73
61
|
scope
|
74
62
|
end
|
75
63
|
|
64
|
+
def build_exclude_scope(root_scope, exclude_query)
|
65
|
+
root_scope_without_conditions = root_scope.except(:where)
|
66
|
+
exclude_scope = find_parsed_query(root_scope_without_conditions, exclude_query)
|
67
|
+
exclude_scope_conditions = exclude_scope.where_values.reduce(:and)
|
68
|
+
if exclude_scope_conditions.present?
|
69
|
+
# where_values.reduce(:and) returns a string if only one where_value given
|
70
|
+
# and a Arel::Node for more than one where_value
|
71
|
+
unless exclude_scope_conditions.is_a?(String)
|
72
|
+
exclude_scope_conditions = exclude_scope_conditions.to_sql
|
73
|
+
end
|
74
|
+
inverted_sql = "NOT COALESCE (" + exclude_scope_conditions + ",0)"
|
75
|
+
exclude_scope.except(:where).where(inverted_sql)
|
76
|
+
else
|
77
|
+
# we cannot build an inverted scope if no where-conditions are present
|
78
|
+
root_scope
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
76
82
|
end
|
77
83
|
end
|
data/lib/dusen/version.rb
CHANGED
data/spec/rails-3.0/Gemfile.lock
CHANGED
data/spec/rails-3.2/Gemfile.lock
CHANGED
@@ -5,10 +5,16 @@ class Recipe < ActiveRecord::Base
|
|
5
5
|
has_many :ingredients, :class_name => 'Recipe::Ingredient', :inverse_of => :recipe
|
6
6
|
belongs_to :category, :class_name => 'Recipe::Category', :inverse_of => :recipes
|
7
7
|
|
8
|
-
search_syntax
|
9
|
-
|
10
8
|
search_text do
|
11
9
|
[name, category.andand.name, ingredients.collect(&:name)]
|
12
10
|
end
|
13
11
|
|
12
|
+
search_syntax do
|
13
|
+
|
14
|
+
search_by :category do |scope, category_name|
|
15
|
+
scope.joins(:category).where('recipe_categories.name = ?', category_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
14
20
|
end
|
@@ -132,6 +132,14 @@ shared_examples_for 'model with search syntax' do
|
|
132
132
|
subject.search('Sunny -Power').to_a.should == [match]
|
133
133
|
end
|
134
134
|
|
135
|
+
it 'should work if search_by contains a join' do
|
136
|
+
category1 = Recipe::Category.create!(:name => 'Rice')
|
137
|
+
category2= Recipe::Category.create!(:name => 'Barbecue')
|
138
|
+
match = Recipe.create!(:name => 'Martini Chicken', :category => category1)
|
139
|
+
no_match = Recipe.create!(:name => 'Barbecue Chicken', :category => category2)
|
140
|
+
Recipe.search('category:-Barbecue').to_a.should == [match]
|
141
|
+
end
|
142
|
+
|
135
143
|
end
|
136
144
|
|
137
145
|
context 'when the given query is blank' do
|
metadata
CHANGED
@@ -1,65 +1,52 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dusen
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
version: "0.5"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Henning Koch
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: activerecord
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 0
|
32
|
-
version: "3.0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
33
20
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: edge_rider
|
37
21
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: edge_rider
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 29
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
- 2
|
47
|
-
- 5
|
32
|
+
- !ruby/object:Gem::Version
|
48
33
|
version: 0.2.5
|
49
34
|
type: :runtime
|
50
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.5
|
51
41
|
description: Comprehensive full text search for ActiveRecord and MySQL
|
52
42
|
email: henning.koch@makandra.de
|
53
43
|
executables: []
|
54
|
-
|
55
44
|
extensions: []
|
56
|
-
|
57
45
|
extra_rdoc_files: []
|
58
|
-
|
59
|
-
|
60
|
-
- .
|
61
|
-
- .
|
62
|
-
- .travis.yml
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- ".ruby-version"
|
49
|
+
- ".travis.yml"
|
63
50
|
- LICENSE
|
64
51
|
- README.md
|
65
52
|
- Rakefile
|
@@ -137,39 +124,28 @@ files:
|
|
137
124
|
- spec/shared/spec/dusen/parser_spec.rb
|
138
125
|
- spec/shared/spec/dusen/query_spec.rb
|
139
126
|
- spec/shared/spec/dusen/util_spec.rb
|
140
|
-
has_rdoc: true
|
141
127
|
homepage: https://github.com/makandra/dusen
|
142
|
-
licenses:
|
128
|
+
licenses:
|
143
129
|
- MIT
|
130
|
+
metadata: {}
|
144
131
|
post_install_message:
|
145
132
|
rdoc_options: []
|
146
|
-
|
147
|
-
require_paths:
|
133
|
+
require_paths:
|
148
134
|
- lib
|
149
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
-
|
151
|
-
requirements:
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
152
137
|
- - ">="
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
version: "0"
|
158
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
-
none: false
|
160
|
-
requirements:
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
161
142
|
- - ">="
|
162
|
-
- !ruby/object:Gem::Version
|
163
|
-
|
164
|
-
segments:
|
165
|
-
- 0
|
166
|
-
version: "0"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
167
145
|
requirements: []
|
168
|
-
|
169
146
|
rubyforge_project:
|
170
|
-
rubygems_version:
|
147
|
+
rubygems_version: 2.2.2
|
171
148
|
signing_key:
|
172
|
-
specification_version:
|
149
|
+
specification_version: 4
|
173
150
|
summary: Comprehensive full text search for ActiveRecord and MySQL
|
174
151
|
test_files: []
|
175
|
-
|