clortho 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +20 -0
- data/README.md +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/clortho.gemspec +69 -0
- data/lib/clortho.rb +100 -0
- data/test/helper.rb +26 -0
- data/test/models/post.rb +20 -0
- data/test/test_clortho.rb +98 -0
- metadata +141 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem "mongo_mapper", "~> 0.9.0"
|
14
|
+
gem "taggregator"
|
15
|
+
gem "pry"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.9)
|
5
|
+
activesupport (= 3.0.9)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.5.0)
|
8
|
+
activesupport (3.0.9)
|
9
|
+
bson (1.3.1)
|
10
|
+
builder (2.1.2)
|
11
|
+
coderay (0.9.8)
|
12
|
+
git (1.2.5)
|
13
|
+
i18n (0.5.0)
|
14
|
+
jeweler (1.6.4)
|
15
|
+
bundler (~> 1.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
method_source (0.6.0)
|
19
|
+
ruby_parser (>= 2.0.5)
|
20
|
+
mongo (1.3.1)
|
21
|
+
bson (>= 1.3.1)
|
22
|
+
mongo_mapper (0.9.1)
|
23
|
+
activemodel (~> 3.0)
|
24
|
+
activesupport (~> 3.0)
|
25
|
+
plucky (~> 0.3.8)
|
26
|
+
plucky (0.3.8)
|
27
|
+
mongo (~> 1.3)
|
28
|
+
pry (0.9.3)
|
29
|
+
coderay (>= 0.9.8)
|
30
|
+
method_source (>= 0.6.0)
|
31
|
+
ruby_parser (>= 2.0.5)
|
32
|
+
slop (~> 1.9.0)
|
33
|
+
rake (0.9.2)
|
34
|
+
rcov (0.9.9)
|
35
|
+
ruby_parser (2.0.6)
|
36
|
+
sexp_processor (~> 3.0)
|
37
|
+
sexp_processor (3.0.5)
|
38
|
+
shoulda (2.11.3)
|
39
|
+
slop (1.9.1)
|
40
|
+
taggregator (0.0.2.dev)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 1.0.0)
|
47
|
+
jeweler (~> 1.6.4)
|
48
|
+
mongo_mapper (~> 0.9.0)
|
49
|
+
pry
|
50
|
+
rcov
|
51
|
+
shoulda
|
52
|
+
taggregator
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Mark Coates
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Clortho
|
2
|
+
|
3
|
+
![Vince Clortho, The Keymaster](http://i51.tinypic.com/1685svm.jpg)
|
4
|
+
|
5
|
+
**The Keywordmaster** (for MongoMapper)
|
6
|
+
|
7
|
+
## Contributing to *clortho*
|
8
|
+
|
9
|
+
* Check out the latest `master` to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
10
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
11
|
+
* Fork the project
|
12
|
+
* Start a feature/bugfix branch
|
13
|
+
* Commit and push until you are happy with your contribution
|
14
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
+
|
17
|
+
## Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2011 Mark Coates. Released under the MIT license. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "clortho"
|
18
|
+
gem.homepage = "http://github.com/oddlyzen/clortho"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Clortho: the Key(word) Master adds search to your MongoMapper classes.}
|
21
|
+
gem.description = %Q{Clortho makes keyword and full-text search a breeze for MongoMapper users.}
|
22
|
+
gem.email = "mark.coates@gmail.com"
|
23
|
+
gem.authors = ["Mark Coates"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "clortho #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/clortho.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{clortho}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mark Coates"]
|
12
|
+
s.date = %q{2011-08-02}
|
13
|
+
s.description = %q{Clortho makes keyword and full-text search a breeze for MongoMapper users.}
|
14
|
+
s.email = %q{mark.coates@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"clortho.gemspec",
|
28
|
+
"lib/clortho.rb",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/models/post.rb",
|
31
|
+
"test/test_clortho.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/oddlyzen/clortho}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.6.2}
|
37
|
+
s.summary = %q{Clortho: the Key(word) Master adds search to your MongoMapper classes.}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
44
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
45
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
46
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<mongo_mapper>, ["~> 0.9.0"])
|
48
|
+
s.add_development_dependency(%q<taggregator>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
54
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_dependency(%q<mongo_mapper>, ["~> 0.9.0"])
|
56
|
+
s.add_dependency(%q<taggregator>, [">= 0"])
|
57
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
s.add_dependency(%q<mongo_mapper>, ["~> 0.9.0"])
|
65
|
+
s.add_dependency(%q<taggregator>, [">= 0"])
|
66
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/clortho.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Plugins
|
3
|
+
|
4
|
+
module Clortho
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class_inheritable_accessor :searchable_with_options
|
9
|
+
write_inheritable_attribute :searchable_with_options, []
|
10
|
+
set_callback :create, :before, :inject_default_keywords
|
11
|
+
extend ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module ExclusionConstants
|
15
|
+
# Helper verbs, sometimes referred to as "forms of the verb (to) 'be'", usually offer no added meaning
|
16
|
+
VERBS = %w(have has had do does did be am is are was were having
|
17
|
+
been can could shall should will would may might must being)
|
18
|
+
# Article adjectives are normally fluff and offer no additional context or meaning
|
19
|
+
ADJECTIVES = %w(a an the)
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
|
24
|
+
def searchable(*args)
|
25
|
+
options = args.extract_options!
|
26
|
+
|
27
|
+
args.each do |arg|
|
28
|
+
key :"#{arg}_keywords", String, default: ""
|
29
|
+
key :"#{arg}_keywords_array", Array, default: []
|
30
|
+
|
31
|
+
searchable_with_options << [arg.to_sym, options]
|
32
|
+
|
33
|
+
class_eval <<-CODE
|
34
|
+
class << self
|
35
|
+
def search_#{arg}_keywords_for(*keywords)
|
36
|
+
records = []
|
37
|
+
keywords.each do |word|
|
38
|
+
records << self.all.select{ |record| record[:'#{arg}_keywords_array'].include?(word.downcase) }
|
39
|
+
end
|
40
|
+
records.flatten.uniq
|
41
|
+
end
|
42
|
+
end
|
43
|
+
CODE
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
module InstanceMethods
|
50
|
+
|
51
|
+
@defaults_set = false
|
52
|
+
|
53
|
+
def inject_default_keywords
|
54
|
+
searchable_with_options.each do |field|
|
55
|
+
if !self.send(field[0]).nil?
|
56
|
+
keywords = !field[1][:exclude].nil? ? filter_on_exclusions(field, self.send(field[0])) : self.send(field[0])
|
57
|
+
keywords = filter_and_normalize(keywords)
|
58
|
+
self.send("#{field[0].to_s}_keywords=".to_sym, keywords) if keywords
|
59
|
+
self.send("#{field[0].to_s}_keywords_array=".to_sym, keywords.split.each{ |kw| kw.downcase }) if keywords
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def filter_on_exclusions(field_and_options, keywords)
|
65
|
+
field, options = field_and_options
|
66
|
+
if options[:exclude]
|
67
|
+
|
68
|
+
options[:exclude].each do |exclusion|
|
69
|
+
if exclusion.is_a? String
|
70
|
+
keywords.gsub!(exclusion.to_s, '')
|
71
|
+
elsif exclusion.is_a? Symbol
|
72
|
+
klass = self.class
|
73
|
+
ex = exclusion.to_s.upcase.to_sym
|
74
|
+
if Clortho::ExclusionConstants::const_get(ex)
|
75
|
+
Clortho::ExclusionConstants::const_get(ex).each do |e|
|
76
|
+
keywords.gsub!(e, '')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
# strip punctuation and extra spaces
|
83
|
+
unless keywords.nil?
|
84
|
+
filter_out_punctuation(keywords)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def filter_out_punctuation(text)
|
89
|
+
text.gsub(/\b\W/, ' ').strip.gsub(/\s+/, ' ')
|
90
|
+
end
|
91
|
+
|
92
|
+
def filter_and_normalize(text)
|
93
|
+
filter_out_punctuation(text).downcase
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'active_support'
|
4
|
+
require 'pry'
|
5
|
+
require 'mongo_mapper'
|
6
|
+
require 'bundler'
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
require 'test/unit'
|
15
|
+
require 'shoulda'
|
16
|
+
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
require 'clortho'
|
20
|
+
|
21
|
+
MongoMapper.database = 'testing_clortho'
|
22
|
+
|
23
|
+
require 'models/post'
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
end
|
data/test/models/post.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Post
|
2
|
+
include MongoMapper::Document
|
3
|
+
include MongoMapper::Plugins::Clortho
|
4
|
+
|
5
|
+
key :title, String
|
6
|
+
key :body, String
|
7
|
+
key :summary, String
|
8
|
+
key :authors, Array
|
9
|
+
key :about, String
|
10
|
+
|
11
|
+
searchable :summary # works with one...
|
12
|
+
searchable :body, :title # ...or multiple arguments...
|
13
|
+
searchable :about, :exclude => [:verbs, :adjectives, 'lipsum'] # or options like :exclude.
|
14
|
+
|
15
|
+
LIPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus porttitor, ipsum a commodo aliquet,
|
16
|
+
velit ligula porttitor eros, sit amet consequat purus massa sit amet quam. Aliquam: tempus magna faucibus
|
17
|
+
lacus ultricies rhoncus. In ut metus purus, at venenatis est. Donec vel--elementum turpis. Nullam feugiat
|
18
|
+
massa quis elit egestas."
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestClortho < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@fields = ['about', 'summary', 'body', 'title']
|
6
|
+
@posts = [
|
7
|
+
(@fridge = Post.new( title: 'Is your refrigerator running? Better catch it',
|
8
|
+
body: Post::LIPSUM,
|
9
|
+
about: 'Hello were having the lipsum a world',
|
10
|
+
authors: ['Thomas Mann', 'Jim Byrd'])),
|
11
|
+
(@colonial = Post.new( title: 'The Colonial: In Full Swing',
|
12
|
+
body: Post::LIPSUM,
|
13
|
+
about: 'Hello were having the lipsum a world',
|
14
|
+
authors: ['Rebecca Simmons']))
|
15
|
+
]
|
16
|
+
save_posts
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'have a all searchable fields, both as a string and array' do
|
20
|
+
@posts.each do |post|
|
21
|
+
@fields.each do |word|
|
22
|
+
assert post.respond_to? :"#{word}_keywords"
|
23
|
+
assert post.respond_to? :"#{word}_keywords_array"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'have fields that never evaluate to nil unless supplied field is nil' do
|
29
|
+
@posts.each do |post|
|
30
|
+
@fields.each do |word|
|
31
|
+
assert !(post.send :"#{word}_keywords").nil?
|
32
|
+
assert !(post.send :"#{word}_keywords_array").nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'have body_keywords equal to LIPSUM' do
|
38
|
+
stripsum = Post::LIPSUM.downcase.gsub(/\b\W/, ' ').strip.gsub(/\s+/, ' ')
|
39
|
+
assert_equal stripsum, @colonial.body_keywords
|
40
|
+
assert_equal stripsum, @fridge.body_keywords
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'have about_keywords equal to "Hello world"' do
|
44
|
+
assert_equal "hello world", @colonial.about_keywords
|
45
|
+
assert_equal "hello world", @fridge.about_keywords
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'allow searches for specific keywords' do
|
49
|
+
assert_equal Post.search_body_keywords_for('ipsum').count, 2
|
50
|
+
assert_equal Post.search_about_keywords_for('ipsum').count, 0
|
51
|
+
assert_equal Post.search_title_keywords_for('refrigerator').count, 1
|
52
|
+
end
|
53
|
+
|
54
|
+
# need to strip out punctuation in keywords
|
55
|
+
should 'strip out punctuation from array entries' do
|
56
|
+
@colonial.body_keywords_array.each do |keyword|
|
57
|
+
flunk if keyword =~ /^A-Za-z0-9\s/
|
58
|
+
end
|
59
|
+
@fridge.body_keywords_array.each do |keyword|
|
60
|
+
flunk if keyword =~ /^A-Za-z0-9\s/
|
61
|
+
end
|
62
|
+
assert true
|
63
|
+
end
|
64
|
+
|
65
|
+
should 'strip out helper verbs and article adjectives from the about keywords' do
|
66
|
+
MongoMapper::Plugins::Clortho::ExclusionConstants::VERBS.each do |v|
|
67
|
+
flunk if /v.to_s/ =~ @colonial.about_keywords
|
68
|
+
flunk if /v.to_s/ =~ @fridge.about_keywords
|
69
|
+
end
|
70
|
+
assert true
|
71
|
+
end
|
72
|
+
|
73
|
+
should 'allow searching for multiple keywords' do
|
74
|
+
assert_equal Post.search_body_keywords_for('ipsum', 'sit').count, 2
|
75
|
+
assert_equal Post.search_about_keywords_for('ipsum', 'sit').count, 0
|
76
|
+
assert_equal Post.search_title_keywords_for('refrigerator', 'Colonial').count, 2
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'allow case-insensitive searching for keywords' do
|
80
|
+
assert_equal Post.search_title_keywords_for('ReFrIgErAtOr', 'ColoniaL').count, 2
|
81
|
+
assert_equal Post.search_about_keywords_for('IpSuM', 'SIT').count, 0
|
82
|
+
assert_equal Post.search_body_keywords_for('ipsUM', 'sIT').count, 2
|
83
|
+
end
|
84
|
+
|
85
|
+
should 'strip out -- from between two words (i.e., word--again)' do
|
86
|
+
assert @fridge.body_keywords !=~ /\-\-/
|
87
|
+
assert @colonial.body_keywords !=~ /\-\-/
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
Post.destroy_all
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
def save_posts
|
96
|
+
@posts.each{ |post| post.save }
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clortho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Coates
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-02 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: shoulda
|
17
|
+
requirement: &2168779100 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2168779100
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &2168778160 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2168778160
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jeweler
|
39
|
+
requirement: &2168776700 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.6.4
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2168776700
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rcov
|
50
|
+
requirement: &2168775020 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2168775020
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: mongo_mapper
|
61
|
+
requirement: &2168773200 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.9.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2168773200
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: taggregator
|
72
|
+
requirement: &2168771100 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2168771100
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: pry
|
83
|
+
requirement: &2168769420 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *2168769420
|
92
|
+
description: Clortho makes keyword and full-text search a breeze for MongoMapper users.
|
93
|
+
email: mark.coates@gmail.com
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files:
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
files:
|
100
|
+
- .document
|
101
|
+
- Gemfile
|
102
|
+
- Gemfile.lock
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- VERSION
|
107
|
+
- clortho.gemspec
|
108
|
+
- lib/clortho.rb
|
109
|
+
- test/helper.rb
|
110
|
+
- test/models/post.rb
|
111
|
+
- test/test_clortho.rb
|
112
|
+
has_rdoc: true
|
113
|
+
homepage: http://github.com/oddlyzen/clortho
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: 3180382170967961300
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.6.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: ! 'Clortho: the Key(word) Master adds search to your MongoMapper classes.'
|
141
|
+
test_files: []
|