quest_search 0.0.6 → 0.0.7

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.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in quest.gemspec
4
4
  gemspec
5
+
6
+ gem "unicode_utils"
data/Rakefile CHANGED
@@ -1 +1,25 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ #!/usr/bin/env rake
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+ begin
10
+ require 'rdoc/task'
11
+ rescue LoadError
12
+ require 'rdoc/rdoc'
13
+ require 'rake/rdoctask'
14
+ RDoc::Task = Rake::RDocTask
15
+ end
16
+
17
+ RDoc::Task.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'QuestSearch'
20
+ rdoc.options << '--line-numbers'
21
+ rdoc.rdoc_files.include('README.rdoc')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ Bundler::GemHelper.install_tasks
@@ -1,3 +1,5 @@
1
+ require 'unicode_utils/downcase'
2
+
1
3
  module QuestSearch
2
4
  module QuestSearchOn
3
5
  extend ActiveSupport::Concern
@@ -9,20 +11,19 @@ module QuestSearch
9
11
  end
10
12
 
11
13
  options = fields.extract_options!
12
-
13
14
  @order = options[:order] || "id desc"
14
15
 
15
- cattr_accessor :quest_search_fields
16
+ cattr_accessor :quest_search_fields, :quest_search_index_field
16
17
 
17
18
  self.quest_search_fields = fields
19
+ self.quest_search_index_field = options[:quest_search_index_field] || :quest_search_index
20
+ self.before_save :update_quest_search_index
18
21
  end
19
22
 
20
23
  def quest_search_for(query, page_no = 1, page_size = 2**32, sort = nil)
21
- words = query.to_s.split " "
24
+ words = ::UnicodeUtils.downcase(query.to_s).split " "
22
25
  conditions = words.map do |w|
23
- self.quest_search_fields.map do |f|
24
- replace_bind_variables("#{f} like ?", ["%#{w}%"])
25
- end.join " OR "
26
+ replace_bind_variables("#{self.quest_search_index_field} like ?", ["%#{w}%"])
26
27
  end.join " OR "
27
28
 
28
29
  offset = (page_no * page_size) - page_size
@@ -32,6 +33,8 @@ module QuestSearch
32
33
 
33
34
  results = self.where(conditions).order(@order)
34
35
 
36
+ raise results.inspect
37
+
35
38
  if !sort
36
39
  results.sort do |a, b|
37
40
  b.points_for(query) <=> a.points_for(query)
@@ -59,7 +62,7 @@ module QuestSearch
59
62
  end
60
63
 
61
64
  def points_for(query)
62
- query = query.to_s.downcase
65
+ query = ::UnicodeUtils.downcase(query.to_s)
63
66
  @quest_search_relevance ||= {}
64
67
  return @quest_search_relevance[query] if @quest_search_relevance[query]
65
68
  words = query.split " "
@@ -72,7 +75,7 @@ module QuestSearch
72
75
  matches = 0
73
76
 
74
77
  points = self.quest_search_fields.map do |field|
75
- content = self.send(field).to_s.downcase
78
+ content = ::UnicodeUtils.downcase(self.send(field).to_s)
76
79
 
77
80
  matches = content.scan(w).size
78
81
 
@@ -99,6 +102,16 @@ module QuestSearch
99
102
 
100
103
  @quest_search_relevance[query] = points
101
104
  end
105
+
106
+ private
107
+
108
+ def update_quest_search_index
109
+ full_text = self.quest_search_fields.map do |field|
110
+ ::UnicodeUtils.downcase self.send(field).to_s
111
+ end.join "\n"
112
+ self.send "#{self.quest_search_index_field}=", full_text
113
+ end
114
+
102
115
  end
103
116
  end
104
117
 
@@ -1,3 +1,3 @@
1
1
  module QuestSearch
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quest_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-29 00:00:00.000000000 Z
12
+ date: 2011-12-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Quest is a gem that lets you search your model in a simple and intuitive
15
15
  way.
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project: quest_search
50
- rubygems_version: 1.8.10
50
+ rubygems_version: 1.8.12
51
51
  signing_key:
52
52
  specification_version: 3
53
53
  summary: Extremely naive full text search implementation for ActiveRecord based on