solarsearch 0.0.9 → 0.0.10
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/VERSION +1 -1
- data/app/controllers/article_controller.rb +1 -1
- data/app/controllers/{article_statuses_controller.rb → article_status_controller.rb} +1 -1
- data/app/helpers/article_status_helper.rb +3 -0
- data/app/models/user.rb +11 -4
- data/app/views/{article_statuses → article_status}/index.html.haml +1 -1
- data/lib/solarsearch/rails/routing.rb +1 -1
- data/solarsearch.gemspec +7 -5
- data/test/functional/article_controller_test.rb +32 -14
- data/test/functional/article_status_controller_test.rb +43 -0
- data/test/unit/user_test.rb +30 -0
- metadata +7 -5
- data/app/helpers/article_statuses_helper.rb +0 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
@@ -19,7 +19,7 @@ class ArticleController < ApplicationController
|
|
19
19
|
if params[:q]
|
20
20
|
query = params[:q]
|
21
21
|
search = Sunspot.search(Article) do
|
22
|
-
keywords query
|
22
|
+
keywords "#{query} #{User::QUERY_AUGMENT_PARTIAL}"
|
23
23
|
paginate(:page => page)
|
24
24
|
order_by(:published_at, :desc)
|
25
25
|
end
|
data/app/models/user.rb
CHANGED
@@ -27,9 +27,12 @@ class User < ActiveRecord::Base
|
|
27
27
|
EMAIL_MAX_LENGTH = 50
|
28
28
|
USERNAME_RANGE = USERNAME_MIN_LENGTH..USERNAME_MAX_LENGTH
|
29
29
|
PASSWORD_RANGE = PASSWORD_MIN_LENGTH..PASSWORD_MAX_LENGTH
|
30
|
+
|
31
|
+
#configuration settings
|
30
32
|
MAX_NUMBER_OF_ARTICLES_PER_NEWSUPDATE = 10
|
31
|
-
MAX_SIZE_OF_A_MAIL_IN_CHARACTERS =
|
33
|
+
MAX_SIZE_OF_A_MAIL_IN_CHARACTERS = 20000
|
32
34
|
NEWSUPDATE_RECENT_NUMBER_OF_DAYS = 120
|
35
|
+
QUERY_AUGMENT_PARTIAL = ''
|
33
36
|
|
34
37
|
=begin
|
35
38
|
validates_uniqueness_of :username, :email
|
@@ -95,7 +98,9 @@ class User < ActiveRecord::Base
|
|
95
98
|
set_all_articles += article_update
|
96
99
|
end
|
97
100
|
arr_all_articles = set_all_articles.to_a
|
98
|
-
arr_all_articles = arr_all_articles.find_all
|
101
|
+
arr_all_articles = arr_all_articles.find_all do |article|
|
102
|
+
article_condition.call(article)
|
103
|
+
end if article_condition
|
99
104
|
arr_all_articles.sort! { |article1, article2| article2.published_at <=> article1.published_at }
|
100
105
|
arr_all_articles = arr_all_articles[0, MAX_NUMBER_OF_ARTICLES_PER_NEWSUPDATE]
|
101
106
|
arr_all_articles
|
@@ -105,7 +110,7 @@ class User < ActiveRecord::Base
|
|
105
110
|
searchquery = search_keyword.query
|
106
111
|
self_user = self
|
107
112
|
search = Sunspot.search(Article) do
|
108
|
-
keywords searchquery
|
113
|
+
keywords "#{searchquery} #{QUERY_AUGMENT_PARTIAL}"
|
109
114
|
with(:published_at).greater_than Time.now - NEWSUPDATE_RECENT_NUMBER_OF_DAYS.day
|
110
115
|
dynamic :status do
|
111
116
|
without Article.give_user_status_symbol(self_user, ArticleStatus::STATUS_VIEWED), true
|
@@ -114,7 +119,9 @@ class User < ActiveRecord::Base
|
|
114
119
|
order_by(:published_at, :desc)
|
115
120
|
paginate(:page => 1, :per_page => MAX_NUMBER_OF_ARTICLES_PER_NEWSUPDATE)
|
116
121
|
end
|
117
|
-
|
122
|
+
#FIXME: This is for debugging purposes, trying to catch a hardly reproducably bug, which I dont understand why happens
|
123
|
+
STDERR << search.results.to_a.to_s
|
124
|
+
search.results.to_a
|
118
125
|
end
|
119
126
|
|
120
127
|
def can_be_modified_by(user)
|
@@ -7,5 +7,5 @@
|
|
7
7
|
- article = article_status.article
|
8
8
|
%li
|
9
9
|
= t :article_status_line, :article_status => h(ArticleStatus::WORD_FOR_STATUS[article_status.status]), :status_update_date => h(I18n.localize(article_status.updated_at, :format => :short))
|
10
|
-
= link_to
|
10
|
+
= link_to h(article.title[0, ArticleStatusHelper::MAX_ARTICLE_TITLE_VIEW_SIZE]), :controller => 'article', :action => 'show', :id => article
|
11
11
|
= will_paginate @article_statuses
|
@@ -3,7 +3,7 @@ module SolarSearch #:nodoc:
|
|
3
3
|
module MapperExtensions
|
4
4
|
def solarsearch_routes
|
5
5
|
@set.draw do |map|
|
6
|
-
map.myevents 'myevents', :controller => '
|
6
|
+
map.myevents 'myevents', :controller => 'article_status', :action => 'index'
|
7
7
|
|
8
8
|
map.tester 'tester', :controller => 'infosources', :action => 'tester'
|
9
9
|
map.mynews 'mynews', :controller => 'search_keywords', :action => 'newsupdate'
|
data/solarsearch.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{solarsearch}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gyorgy Frivolt"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-01}
|
13
13
|
s.description = %q{Have a search motor built on the top of Solr, a highly customizable, scalable and well performing search engine. You are only few steps away from creating your own search motor.}
|
14
14
|
s.email = %q{gyorgy.frivolt@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,13 +24,13 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"app/controllers/article_controller.rb",
|
27
|
-
"app/controllers/
|
27
|
+
"app/controllers/article_status_controller.rb",
|
28
28
|
"app/controllers/infosources_controller.rb",
|
29
29
|
"app/controllers/search_keywords_controller.rb",
|
30
30
|
"app/controllers/user_sessions_controller.rb",
|
31
31
|
"app/controllers/users_controller.rb",
|
32
32
|
"app/helpers/article_helper.rb",
|
33
|
-
"app/helpers/
|
33
|
+
"app/helpers/article_status_helper.rb",
|
34
34
|
"app/helpers/infosources_helper.rb",
|
35
35
|
"app/helpers/layout_helper.rb",
|
36
36
|
"app/helpers/search_keywords_helper.rb",
|
@@ -53,7 +53,7 @@ Gem::Specification.new do |s|
|
|
53
53
|
"app/views/article/_search_form.html.haml",
|
54
54
|
"app/views/article/search.html.haml",
|
55
55
|
"app/views/article/show.html.haml",
|
56
|
-
"app/views/
|
56
|
+
"app/views/article_status/index.html.haml",
|
57
57
|
"app/views/infosources/edit.html.haml",
|
58
58
|
"app/views/infosources/index.html.haml",
|
59
59
|
"app/views/infosources/new.html.haml",
|
@@ -100,6 +100,7 @@ Gem::Specification.new do |s|
|
|
100
100
|
"test/content_scrapper.rb",
|
101
101
|
"test/database.yml",
|
102
102
|
"test/functional/article_controller_test.rb",
|
103
|
+
"test/functional/article_status_controller_test.rb",
|
103
104
|
"test/functional/email_controller_test.rb",
|
104
105
|
"test/functional/infosources_controller_test.rb",
|
105
106
|
"test/functional/restricted_logged_exceptions_controller_test.rb",
|
@@ -135,6 +136,7 @@ Gem::Specification.new do |s|
|
|
135
136
|
"test/functional/infosources_controller_test.rb",
|
136
137
|
"test/functional/article_controller_test.rb",
|
137
138
|
"test/functional/restricted_logged_exceptions_controller_test.rb",
|
139
|
+
"test/functional/article_status_controller_test.rb",
|
138
140
|
"test/functional/user_sessions_controller_test.rb",
|
139
141
|
"test/functional/email_controller_test.rb",
|
140
142
|
"test/test_helper.rb",
|
@@ -18,22 +18,40 @@ class ArticleControllerTest < ActionController::TestCase
|
|
18
18
|
should_render_template :show
|
19
19
|
end
|
20
20
|
|
21
|
-
context "on
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
context "on common search setup" do
|
22
|
+
|
23
|
+
setup { Sunspot.remove_all! }
|
24
|
+
|
25
|
+
context "on searching accented characters" do
|
26
|
+
setup do
|
27
|
+
User::QUERY_AUGMENT_PARTIAL = ''
|
28
|
+
2.times { Article.make }
|
29
|
+
(Article::per_page + 1).times { Article.make(:accent_in_body) }
|
30
|
+
Sunspot.commit
|
31
|
+
get :search, :q => Sham.accented_word
|
32
|
+
end
|
33
|
+
should_respond_with :success
|
34
|
+
should "have articles value set" do
|
35
|
+
articles = assigns(:articles)
|
36
|
+
assert_not_nil assigns(:articles)
|
37
|
+
assert_equal 1, articles.current_page
|
38
|
+
assert_equal Article::per_page + 1, articles.total_entries
|
39
|
+
end
|
40
|
+
should_render_template :search
|
28
41
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
|
43
|
+
context "on searching with query augment string" do
|
44
|
+
setup do
|
45
|
+
User::QUERY_AUGMENT_PARTIAL = '-wedontwantthis'
|
46
|
+
@article = Article.make
|
47
|
+
Article.make(:body => "#{@article.body} wedontwantthis")
|
48
|
+
Sunspot.commit
|
49
|
+
get :search, :q => @article.body
|
50
|
+
end
|
51
|
+
should "find only one result" do
|
52
|
+
assert_match (I18n.t :search_summary_number_of_articles, :articles_total => 1), @response.body
|
53
|
+
end
|
35
54
|
end
|
36
|
-
should_render_template :search
|
37
55
|
end
|
38
56
|
#TODO should be tested for cases when the user is not logged in
|
39
57
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ArticleStatusControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
context "for logged in user" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
activate_authlogic
|
9
|
+
UserSession.create(@user = User.make)
|
10
|
+
@article = Article.make
|
11
|
+
end
|
12
|
+
|
13
|
+
context "on GET to index on empty list of statuses" do
|
14
|
+
setup { get :index }
|
15
|
+
should_respond_with :success
|
16
|
+
should_render_template :index
|
17
|
+
should "assign article_statuses" do
|
18
|
+
assert_not_nil assigns(:article_statuses)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "on GET to index on one article status set" do
|
23
|
+
setup do
|
24
|
+
@article_status = ArticleStatus.new
|
25
|
+
@article_status.user = @user
|
26
|
+
@article_status.article = @article
|
27
|
+
@article_status.status = ArticleStatus::STATUS_VIEWED
|
28
|
+
@article_status.save
|
29
|
+
get :index
|
30
|
+
end
|
31
|
+
should_respond_with :success
|
32
|
+
should_render_template :index
|
33
|
+
should "have article status containing an element" do
|
34
|
+
assert !assigns(:article_statuses).empty?
|
35
|
+
end
|
36
|
+
should "contain reference to the article" do
|
37
|
+
assert_match(@article.body[0, ArticleStatusHelper::MAX_ARTICLE_TITLE_VIEW_SIZE], @response.body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#TODO should be tested for cases when the user is not logged in
|
42
|
+
end
|
43
|
+
end
|
data/test/unit/user_test.rb
CHANGED
@@ -28,6 +28,22 @@ class UserTest < ActiveSupport::TestCase
|
|
28
28
|
setup do
|
29
29
|
Sunspot.remove_all!
|
30
30
|
@user = User.make
|
31
|
+
User::QUERY_AUGMENT_PARTIAL = ''
|
32
|
+
end
|
33
|
+
|
34
|
+
context "on empty set of collected articles" do
|
35
|
+
setup do
|
36
|
+
ActionMailer::Base.deliveries = []
|
37
|
+
query = SearchKeyword.make(:user => @user)
|
38
|
+
Sunspot.commit
|
39
|
+
end
|
40
|
+
should "not collect any articles" do
|
41
|
+
assert_equal 0, @user.collect_recent_articles.count
|
42
|
+
end
|
43
|
+
should "not post any article" do
|
44
|
+
@user.post_recent_news
|
45
|
+
assert_did_not_send_email
|
46
|
+
end
|
31
47
|
end
|
32
48
|
|
33
49
|
context "for results having a common item for two search queries" do
|
@@ -85,6 +101,7 @@ class UserTest < ActiveSupport::TestCase
|
|
85
101
|
articles[iteration] = Article.make(:body => query,
|
86
102
|
:published_at => (Time.now - iteration.day))
|
87
103
|
end
|
104
|
+
Sunspot.commit
|
88
105
|
end
|
89
106
|
should "sort the recent articles fetched for one source" do
|
90
107
|
recent_articles = @user.recent_articles_for_search_keyword(@search_keyword)
|
@@ -108,6 +125,7 @@ class UserTest < ActiveSupport::TestCase
|
|
108
125
|
@search_keyword = SearchKeyword.make(:user => @user, :query => 'spam')
|
109
126
|
Article.make(:body => "spam #{'x'*User::MAX_SIZE_OF_A_MAIL_IN_CHARACTERS}",
|
110
127
|
:published_at => Time.now)
|
128
|
+
Sunspot.commit
|
111
129
|
end
|
112
130
|
should "filter the long articles out, we do not want to send spams" do
|
113
131
|
collected_articles = @user.collect_recent_articles do |article|
|
@@ -120,5 +138,17 @@ class UserTest < ActiveSupport::TestCase
|
|
120
138
|
assert_did_not_send_email
|
121
139
|
end
|
122
140
|
end
|
141
|
+
|
142
|
+
context "on query augmenting partial" do
|
143
|
+
setup do
|
144
|
+
User::QUERY_AUGMENT_PARTIAL = '-dontwantthis'
|
145
|
+
@search_keyword = SearchKeyword.make(:user => @user)
|
146
|
+
Article.make(:body => "#{@search_keyword.query} dontwantthis", :published_at => Time.now)
|
147
|
+
Sunspot.commit
|
148
|
+
end
|
149
|
+
should "not find the article as it was excluded by query augmentation" do
|
150
|
+
assert @user.recent_articles_for_search_keyword(@search_keyword).empty?
|
151
|
+
end
|
152
|
+
end
|
123
153
|
end
|
124
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solarsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gyorgy Frivolt
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-01 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -179,13 +179,13 @@ files:
|
|
179
179
|
- Rakefile
|
180
180
|
- VERSION
|
181
181
|
- app/controllers/article_controller.rb
|
182
|
-
- app/controllers/
|
182
|
+
- app/controllers/article_status_controller.rb
|
183
183
|
- app/controllers/infosources_controller.rb
|
184
184
|
- app/controllers/search_keywords_controller.rb
|
185
185
|
- app/controllers/user_sessions_controller.rb
|
186
186
|
- app/controllers/users_controller.rb
|
187
187
|
- app/helpers/article_helper.rb
|
188
|
-
- app/helpers/
|
188
|
+
- app/helpers/article_status_helper.rb
|
189
189
|
- app/helpers/infosources_helper.rb
|
190
190
|
- app/helpers/layout_helper.rb
|
191
191
|
- app/helpers/search_keywords_helper.rb
|
@@ -208,7 +208,7 @@ files:
|
|
208
208
|
- app/views/article/_search_form.html.haml
|
209
209
|
- app/views/article/search.html.haml
|
210
210
|
- app/views/article/show.html.haml
|
211
|
-
- app/views/
|
211
|
+
- app/views/article_status/index.html.haml
|
212
212
|
- app/views/infosources/edit.html.haml
|
213
213
|
- app/views/infosources/index.html.haml
|
214
214
|
- app/views/infosources/new.html.haml
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- test/content_scrapper.rb
|
256
256
|
- test/database.yml
|
257
257
|
- test/functional/article_controller_test.rb
|
258
|
+
- test/functional/article_status_controller_test.rb
|
258
259
|
- test/functional/email_controller_test.rb
|
259
260
|
- test/functional/infosources_controller_test.rb
|
260
261
|
- test/functional/restricted_logged_exceptions_controller_test.rb
|
@@ -312,6 +313,7 @@ test_files:
|
|
312
313
|
- test/functional/infosources_controller_test.rb
|
313
314
|
- test/functional/article_controller_test.rb
|
314
315
|
- test/functional/restricted_logged_exceptions_controller_test.rb
|
316
|
+
- test/functional/article_status_controller_test.rb
|
315
317
|
- test/functional/user_sessions_controller_test.rb
|
316
318
|
- test/functional/email_controller_test.rb
|
317
319
|
- test/test_helper.rb
|