smart_search 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/smart_search.rb +53 -29
  2. metadata +1 -1
@@ -10,36 +10,38 @@ module SmartSearch
10
10
 
11
11
  module ClassMethods
12
12
  def smart_search(options = {:on => [], :conditions => nil, :group => nil, :order => "created_at"})
13
- # Check if search_tags exists
14
- unless is_smart_search?
15
- cattr_accessor :condition_default, :group_default, :tags, :order
16
- send :include, InstanceMethods
17
- if self.column_names.index("search_tags").nil?
18
- ::AddSearchTags.add_to_table(self.table_name)
19
- end
20
- self.send(:before_save, :create_search_tags)
21
-
22
- # options zuweisen
23
- if options[:conditions].is_a?(String) && !options[:conditions].blank?
24
- self.condition_default = options[:conditions]
25
- elsif !options[:conditions].nil?
26
- raise ArgumentError, ":conditions must be a valid SQL Query"
13
+ if table_exists?
14
+ # Check if search_tags exists
15
+ unless is_smart_search?
16
+ cattr_accessor :condition_default, :group_default, :tags, :order
17
+ send :include, InstanceMethods
18
+ if self.column_names.index("search_tags").nil?
19
+ ::AddSearchTags.add_to_table(self.table_name)
27
20
  end
21
+ self.send(:before_save, :create_search_tags)
22
+
23
+ # options zuweisen
24
+ if options[:conditions].is_a?(String) && !options[:conditions].blank?
25
+ self.condition_default = options[:conditions]
26
+ elsif !options[:conditions].nil?
27
+ raise ArgumentError, ":conditions must be a valid SQL Query"
28
+ end
28
29
 
29
- if self.column_names.include?("created_at")
30
- self.order = options[:order] || "created_at"
31
- else
32
- self.order = options[:order] || "id"
33
- end
30
+ if self.column_names.include?("created_at")
31
+ self.order = options[:order] || "created_at"
32
+ else
33
+ self.order = options[:order] || "id"
34
+ end
34
35
 
35
- if options[:group].is_a?(String) && !options[:group].blank?
36
- self.group_default = options[:group]
37
- elsif !options[:group].nil?
38
- raise ArgumentError, ":group must be a valid SQL Query"
39
- end
36
+ if options[:group].is_a?(String) && !options[:group].blank?
37
+ self.group_default = options[:group]
38
+ elsif !options[:group].nil?
39
+ raise ArgumentError, ":group must be a valid SQL Query"
40
+ end
40
41
 
41
- self.tags = options[:on] || []
42
- end
42
+ self.tags = options[:on] || []
43
+ end
44
+ end
43
45
  end
44
46
 
45
47
  def is_smart_search?
@@ -47,7 +49,7 @@ module SmartSearch
47
49
  end
48
50
 
49
51
  def result_template_path
50
- "/smart/search/results/#{self.name.split("::").last.underscore}"
52
+ "/search/results/#{self.name.split("::").last.underscore}"
51
53
  end
52
54
 
53
55
  def find_by_tags(tags = "", conditions = {}, group_by = nil)
@@ -147,8 +149,30 @@ module SmartSearch
147
149
 
148
150
  end
149
151
 
150
-
152
+
153
+ class Config
154
+
155
+ cattr_accessor :search_models
156
+ cattr_accessor :public_models
157
+
158
+ self.search_models = []
159
+ self.public_models = []
160
+
161
+ def self.get_search_models
162
+ self.search_models.map {|m| m.constantize}
163
+ end
164
+
165
+ def self.get_public_models
166
+ self.public_models.map {|m| m.constantize}
167
+ end
168
+
169
+ end
170
+
171
+
172
+ class SmartSearchEngine < Rails::Engine
173
+ end
174
+
151
175
  end
152
176
 
153
177
 
154
- ActiveRecord::Base.send(:include, SmartSearch)
178
+ ActiveRecord::Base.send(:include, SmartSearch)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: