naive-search 0.1
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/MIT-LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +37 -0
- data/lib/generators/naive_search/migration/migration_generator.rb +24 -0
- data/lib/generators/templates/add_naive_search_index.rb +9 -0
- data/lib/naive_search.rb +4 -0
- data/lib/naive_search/naive_search_on.rb +62 -0
- data/lib/naive_search/version.rb +3 -0
- data/lib/tasks/naive_search_tasks.rake +4 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/hotel.rb +3 -0
- data/test/dummy/app/models/person.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20111107144413_create_people.rb +10 -0
- data/test/dummy/db/migrate/20111107212128_add_naive_search_index_to_person.rb +9 -0
- data/test/dummy/db/migrate/20111108071246_create_hotels.rb +10 -0
- data/test/dummy/db/migrate/20111108082054_add_naive_search_index_to_hotel.rb +9 -0
- data/test/dummy/db/schema.rb +34 -0
- data/test/dummy/db/seeds.rb +14 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +5 -0
- data/test/dummy/log/test.log +3599 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/hotels.yml +11 -0
- data/test/dummy/test/fixtures/people.yml +11 -0
- data/test/dummy/test/unit/hotel_test.rb +7 -0
- data/test/dummy/test/unit/person_test.rb +7 -0
- data/test/naive_search_test.rb +49 -0
- data/test/test_helper.rb +10 -0
- metadata +167 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
2
|
+
|
3
|
+
# This model initially had no columns defined. If you add columns to the
|
4
|
+
# model remove the '{}' from the fixture names and add the columns immediately
|
5
|
+
# below each fixture, per the syntax in the comments below
|
6
|
+
#
|
7
|
+
one: {}
|
8
|
+
# column: value
|
9
|
+
#
|
10
|
+
two: {}
|
11
|
+
# column: value
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
2
|
+
|
3
|
+
# This model initially had no columns defined. If you add columns to the
|
4
|
+
# model remove the '{}' from the fixture names and add the columns immediately
|
5
|
+
# below each fixture, per the syntax in the comments below
|
6
|
+
#
|
7
|
+
one: {}
|
8
|
+
# column: value
|
9
|
+
#
|
10
|
+
two: {}
|
11
|
+
# column: value
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NaiveSearchTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
[
|
6
|
+
{ :name => "Arnold", :surname => "Bentley", :description => "tall, skinny, dark, minnie's husband" },
|
7
|
+
{ :name => "Minnie", :surname => "Bentley", :description => "short, fat, arnold's wife" },
|
8
|
+
{ :name => "Robert", :surname => "Bentley", :description => "short, skinny, arnold's brother" },
|
9
|
+
{ :name => "Dennis", :surname => "Donaghue", :description => "ugly, annoying, minne's brother" },
|
10
|
+
{ :name => "Stan", :surname => "Donaghue", :description => "tall, handsome, minnie's dad" },
|
11
|
+
{ :name => "Tina", :surname => "Donaghue", :description => "tall, sweet, minnie's mom" },
|
12
|
+
{ :name => "Dan", :surname => "Bentley", :description => "short, stupid, arnold's dad" },
|
13
|
+
{ :name => "Julia", :surname => "Bentley", :description => "short, weird, arnold's mom" }
|
14
|
+
].each do |attrs|
|
15
|
+
Person.create(attrs)
|
16
|
+
end
|
17
|
+
|
18
|
+
[
|
19
|
+
{ :name => "Holiday Inn", :description => "cheap, dirty, great breakfast", :rate => 95 },
|
20
|
+
{ :name => "Holiday Lodge", :description => "cheap, clean, simple breakfast", :rate => 100 },
|
21
|
+
{ :name => "Holiday Motel", :description => "nice, simple, great breakfast", :rate => 90 },
|
22
|
+
{ :name => "Holiday Stay", :description => "moderate, simple, nice breakfast", :rate => 130 }
|
23
|
+
].each do |attrs|
|
24
|
+
Hotel.create(attrs)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "result order" do
|
29
|
+
hotels = Hotel.search_for("cheap great breakfast").map(&:name)
|
30
|
+
assert_equal ["Holiday Inn", "Holiday Motel", "Holiday Lodge", "Holiday Stay"], hotels, "should order matches by relevance #1"
|
31
|
+
|
32
|
+
hotels = Hotel.search_for("cheap clean").map(&:name)
|
33
|
+
assert_equal "Holiday Lodge", hotels.first, "should order matches by relevance #2"
|
34
|
+
end
|
35
|
+
|
36
|
+
test "relevance" do
|
37
|
+
relevance_arnold_bentley = Person.order("id asc").map{|p| p.relevance_for "arnold bentley" }
|
38
|
+
assert_equal [6, 4, 4, 0, 0, 0, 4, 4], relevance_arnold_bentley, "should calculate correct relevance for 'arnold bentley'"
|
39
|
+
|
40
|
+
relevance_bentley = Person.order("id asc").map{|p| p.relevance_for "bentley" }
|
41
|
+
assert_equal [6, 6, 6, 0, 0, 0, 6, 6], relevance_bentley, "should calculate correct relevance for 'bentley'"
|
42
|
+
|
43
|
+
relevance_great_breakfast = Hotel.order("id asc").map{|h| h.relevance_for "great breakfast" }
|
44
|
+
assert_equal [4, 1, 4, 1], relevance_great_breakfast, "should calculate correct relevance for 'great breakfast'"
|
45
|
+
|
46
|
+
relevance_nice_breakfast = Hotel.order("id asc").map{|h| h.relevance_for "nice breakfast" }
|
47
|
+
assert_equal [1, 1, 2, 4], relevance_nice_breakfast, "should calculate correct relevance for 'nice breakfast'"
|
48
|
+
end
|
49
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: naive-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomas Jogin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &2153316120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153316120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sqlite3
|
27
|
+
requirement: &2153315440 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153315440
|
36
|
+
description: Provides very simple full text searching for ActiveRecord, without depending
|
37
|
+
on any particular SQL-feature, search server or anything like that.
|
38
|
+
email:
|
39
|
+
- tomas@jogin.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- lib/generators/naive_search/migration/migration_generator.rb
|
45
|
+
- lib/generators/templates/add_naive_search_index.rb
|
46
|
+
- lib/naive_search/naive_search_on.rb
|
47
|
+
- lib/naive_search/version.rb
|
48
|
+
- lib/naive_search.rb
|
49
|
+
- lib/tasks/naive_search_tasks.rake
|
50
|
+
- MIT-LICENSE
|
51
|
+
- Rakefile
|
52
|
+
- README.rdoc
|
53
|
+
- test/dummy/app/assets/javascripts/application.js
|
54
|
+
- test/dummy/app/assets/stylesheets/application.css
|
55
|
+
- test/dummy/app/controllers/application_controller.rb
|
56
|
+
- test/dummy/app/helpers/application_helper.rb
|
57
|
+
- test/dummy/app/models/hotel.rb
|
58
|
+
- test/dummy/app/models/person.rb
|
59
|
+
- test/dummy/app/views/layouts/application.html.erb
|
60
|
+
- test/dummy/config/application.rb
|
61
|
+
- test/dummy/config/boot.rb
|
62
|
+
- test/dummy/config/database.yml
|
63
|
+
- test/dummy/config/environment.rb
|
64
|
+
- test/dummy/config/environments/development.rb
|
65
|
+
- test/dummy/config/environments/production.rb
|
66
|
+
- test/dummy/config/environments/test.rb
|
67
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
68
|
+
- test/dummy/config/initializers/inflections.rb
|
69
|
+
- test/dummy/config/initializers/mime_types.rb
|
70
|
+
- test/dummy/config/initializers/secret_token.rb
|
71
|
+
- test/dummy/config/initializers/session_store.rb
|
72
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
73
|
+
- test/dummy/config/locales/en.yml
|
74
|
+
- test/dummy/config/routes.rb
|
75
|
+
- test/dummy/config.ru
|
76
|
+
- test/dummy/db/development.sqlite3
|
77
|
+
- test/dummy/db/migrate/20111107144413_create_people.rb
|
78
|
+
- test/dummy/db/migrate/20111107212128_add_naive_search_index_to_person.rb
|
79
|
+
- test/dummy/db/migrate/20111108071246_create_hotels.rb
|
80
|
+
- test/dummy/db/migrate/20111108082054_add_naive_search_index_to_hotel.rb
|
81
|
+
- test/dummy/db/schema.rb
|
82
|
+
- test/dummy/db/seeds.rb
|
83
|
+
- test/dummy/db/test.sqlite3
|
84
|
+
- test/dummy/log/development.log
|
85
|
+
- test/dummy/log/test.log
|
86
|
+
- test/dummy/public/404.html
|
87
|
+
- test/dummy/public/422.html
|
88
|
+
- test/dummy/public/500.html
|
89
|
+
- test/dummy/public/favicon.ico
|
90
|
+
- test/dummy/Rakefile
|
91
|
+
- test/dummy/script/rails
|
92
|
+
- test/dummy/test/fixtures/hotels.yml
|
93
|
+
- test/dummy/test/fixtures/people.yml
|
94
|
+
- test/dummy/test/unit/hotel_test.rb
|
95
|
+
- test/dummy/test/unit/person_test.rb
|
96
|
+
- test/naive_search_test.rb
|
97
|
+
- test/test_helper.rb
|
98
|
+
homepage: http://github.com/tjogin/naive_search
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.11
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Naive full text search ordered by relevance for ActiveRecord
|
122
|
+
test_files:
|
123
|
+
- test/dummy/app/assets/javascripts/application.js
|
124
|
+
- test/dummy/app/assets/stylesheets/application.css
|
125
|
+
- test/dummy/app/controllers/application_controller.rb
|
126
|
+
- test/dummy/app/helpers/application_helper.rb
|
127
|
+
- test/dummy/app/models/hotel.rb
|
128
|
+
- test/dummy/app/models/person.rb
|
129
|
+
- test/dummy/app/views/layouts/application.html.erb
|
130
|
+
- test/dummy/config/application.rb
|
131
|
+
- test/dummy/config/boot.rb
|
132
|
+
- test/dummy/config/database.yml
|
133
|
+
- test/dummy/config/environment.rb
|
134
|
+
- test/dummy/config/environments/development.rb
|
135
|
+
- test/dummy/config/environments/production.rb
|
136
|
+
- test/dummy/config/environments/test.rb
|
137
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
138
|
+
- test/dummy/config/initializers/inflections.rb
|
139
|
+
- test/dummy/config/initializers/mime_types.rb
|
140
|
+
- test/dummy/config/initializers/secret_token.rb
|
141
|
+
- test/dummy/config/initializers/session_store.rb
|
142
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
143
|
+
- test/dummy/config/locales/en.yml
|
144
|
+
- test/dummy/config/routes.rb
|
145
|
+
- test/dummy/config.ru
|
146
|
+
- test/dummy/db/development.sqlite3
|
147
|
+
- test/dummy/db/migrate/20111107144413_create_people.rb
|
148
|
+
- test/dummy/db/migrate/20111107212128_add_naive_search_index_to_person.rb
|
149
|
+
- test/dummy/db/migrate/20111108071246_create_hotels.rb
|
150
|
+
- test/dummy/db/migrate/20111108082054_add_naive_search_index_to_hotel.rb
|
151
|
+
- test/dummy/db/schema.rb
|
152
|
+
- test/dummy/db/seeds.rb
|
153
|
+
- test/dummy/db/test.sqlite3
|
154
|
+
- test/dummy/log/development.log
|
155
|
+
- test/dummy/log/test.log
|
156
|
+
- test/dummy/public/404.html
|
157
|
+
- test/dummy/public/422.html
|
158
|
+
- test/dummy/public/500.html
|
159
|
+
- test/dummy/public/favicon.ico
|
160
|
+
- test/dummy/Rakefile
|
161
|
+
- test/dummy/script/rails
|
162
|
+
- test/dummy/test/fixtures/hotels.yml
|
163
|
+
- test/dummy/test/fixtures/people.yml
|
164
|
+
- test/dummy/test/unit/hotel_test.rb
|
165
|
+
- test/dummy/test/unit/person_test.rb
|
166
|
+
- test/naive_search_test.rb
|
167
|
+
- test/test_helper.rb
|