pages_sphinx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +30 -0
- data/Rakefile +10 -0
- data/app/indices/page_file_index.rb +9 -0
- data/app/indices/page_index.rb +29 -0
- data/app/indices/user_index.rb +11 -0
- data/lib/pages_sphinx.rb +15 -0
- data/lib/pages_sphinx/category_extension.rb +11 -0
- data/lib/pages_sphinx/engine.rb +15 -0
- data/lib/pages_sphinx/page_extension.rb +39 -0
- data/lib/pages_sphinx/page_file_extension.rb +11 -0
- data/lib/pages_sphinx/pages_controller_extension.rb +40 -0
- data/lib/pages_sphinx/user_extension.rb +11 -0
- data/lib/pages_sphinx/version.rb +5 -0
- data/lib/rails/generators/pages_sphinx/install/install_generator.rb +29 -0
- data/lib/rails/generators/pages_sphinx/install/templates/thinking_sphinx.yml +8 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ffb058adcfa1d0c7b0240625381820dc3f502486
|
4
|
+
data.tar.gz: 6f8ed67b3036b8913710b58cfe2bc286ec1ee230
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64858c58e457c483dab56e94931f2ef41f4afdfaf9bb3b0bd8a3d3189c9cc006a502c1281b7a0cc428fb1fe43d9b7936ef5c2f1ed3188ef11ca446f3be22cee7
|
7
|
+
data.tar.gz: f47fc41a675bfe380aaa45b677d0d261450bf44d08e531c927390f272e2323990dcf0cc3c54cb33e7799f0c47f0957f6c2a4f93b6eb3412b0d31d4ff4f1373c1
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# PagesSphinx
|
2
|
+
|
3
|
+
Adds fulltext search support to Pages using ThinkingSphinx.
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
To get started, add it to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "pages_sphinx"
|
11
|
+
```
|
12
|
+
|
13
|
+
Next, run the installer to generate the configuration file:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bin/rails g pages_sphinx:install
|
17
|
+
```
|
18
|
+
|
19
|
+
You can now start the process and index your content:
|
20
|
+
|
21
|
+
```ssh
|
22
|
+
bin/rails ts:configure
|
23
|
+
bin/rails ts:start
|
24
|
+
bin/rails ts:generate
|
25
|
+
```
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
Pages is licensed under the
|
30
|
+
[MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ThinkingSphinx::Index.define :page, with: :real_time do
|
4
|
+
indexes localization_values
|
5
|
+
indexes category_names
|
6
|
+
indexes tag_list
|
7
|
+
indexes author.name, as: :author_name
|
8
|
+
indexes author.email, as: :author_email
|
9
|
+
indexes comment_names
|
10
|
+
indexes comment_bodies
|
11
|
+
indexes file_names
|
12
|
+
indexes file_filenames
|
13
|
+
|
14
|
+
has category_ids, type: :integer, multi: true
|
15
|
+
has tag_ids, type: :integer, multi: true
|
16
|
+
|
17
|
+
has published_at, type: :timestamp
|
18
|
+
has created_at, type: :timestamp
|
19
|
+
has updated_at, type: :timestamp
|
20
|
+
has user_id, type: :integer
|
21
|
+
has parent_page_id, type: :integer
|
22
|
+
has status, type: :integer
|
23
|
+
has template, type: :string
|
24
|
+
has autopublish, type: :boolean
|
25
|
+
has feed_enabled, type: :boolean
|
26
|
+
has published, type: :boolean
|
27
|
+
|
28
|
+
set_property group_concat_max_len: 16.megabytes
|
29
|
+
end
|
data/lib/pages_sphinx.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "thinking-sphinx"
|
4
|
+
|
5
|
+
load "pages_sphinx/category_extension.rb"
|
6
|
+
load "pages_sphinx/page_extension.rb"
|
7
|
+
load "pages_sphinx/page_file_extension.rb"
|
8
|
+
load "pages_sphinx/pages_controller_extension.rb"
|
9
|
+
load "pages_sphinx/user_extension.rb"
|
10
|
+
|
11
|
+
load "pages_sphinx/engine.rb"
|
12
|
+
load "pages_sphinx/version.rb"
|
13
|
+
|
14
|
+
module PagesSphinx
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesSphinx
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
initializer :extend_pages do |_config|
|
6
|
+
Category.send(:include, PagesSphinx::CategoryExtension)
|
7
|
+
Page.send(:include, PagesSphinx::PageExtension)
|
8
|
+
PageFile.send(:include, PagesSphinx::PageFileExtension)
|
9
|
+
User.send(:include, PagesSphinx::UserExtension)
|
10
|
+
PagesCore::Frontend::PagesController.send(
|
11
|
+
:include, PagesSphinx::PagesControllerExtension
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesSphinx
|
4
|
+
module PageExtension
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
after_save ThinkingSphinx::RealTime.callback_for(:page)
|
9
|
+
end
|
10
|
+
|
11
|
+
def localization_values
|
12
|
+
localizations.map(&:value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def category_names
|
16
|
+
categories.map(&:name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def comment_names
|
20
|
+
comments.map(&:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def comment_bodies
|
24
|
+
comments.map(&:body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_names
|
28
|
+
files.map(&:name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_filenames
|
32
|
+
files.map(&:filename)
|
33
|
+
end
|
34
|
+
|
35
|
+
def published
|
36
|
+
published?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesSphinx
|
4
|
+
module PagesControllerExtension
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def search
|
8
|
+
@search_query = params[:q] || params[:query] || ""
|
9
|
+
@search_category_id = params[:category_id]
|
10
|
+
|
11
|
+
@pages = Page.search(
|
12
|
+
normalize_search_query(@search_query),
|
13
|
+
search_options(category_id: @search_category_id)
|
14
|
+
)
|
15
|
+
@pages.each { |p| p.localize!(locale) }
|
16
|
+
@pages
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def normalize_search_query(str)
|
22
|
+
str.split(/\s+/)
|
23
|
+
.map { |p| "#{p}*" }
|
24
|
+
.join(" ")
|
25
|
+
end
|
26
|
+
|
27
|
+
def search_options(category_id: nil)
|
28
|
+
options = {
|
29
|
+
page: (params[:page] || 1).to_i,
|
30
|
+
per_page: 20,
|
31
|
+
include: [:localizations, :categories, :image, :author],
|
32
|
+
order: :published_at,
|
33
|
+
sort_mode: :desc,
|
34
|
+
with: { status: 2, autopublish: 0 }
|
35
|
+
}
|
36
|
+
options[:with][:category_ids] = category_id unless category_id.blank?
|
37
|
+
options
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesSphinx
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Creates the PagesSphinx configuration"
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
def read_configuration!
|
10
|
+
@sphinx_port ||= ask_with_fallback("Sphinx port?", "3312")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_sphinx_config
|
14
|
+
template "thinking_sphinx.yml", File.join("config/thinking_sphinx.yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ask_with_fallback(question, default)
|
20
|
+
result = ask(question + " [#{default}]")
|
21
|
+
if result.blank?
|
22
|
+
default
|
23
|
+
else
|
24
|
+
result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pages_sphinx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Inge Jørgensen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mysql2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.18.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.18.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.5.1
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.5'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.5.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: factory_girl
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '4.5'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 4.5.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '4.5'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 4.5.0
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: shoulda-matchers
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.1'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.1.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '3.1'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 3.1.0
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: rails
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 4.2.0
|
108
|
+
- - "<"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 5.1.0
|
111
|
+
type: :runtime
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.2.0
|
118
|
+
- - "<"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 5.1.0
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: thinking-sphinx
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '3.2'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 3.2.0
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.2'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 3.2.0
|
141
|
+
description: Adds ThinkingSphinx to Pages
|
142
|
+
email:
|
143
|
+
- inge@anyone.no
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- README.md
|
149
|
+
- Rakefile
|
150
|
+
- app/indices/page_file_index.rb
|
151
|
+
- app/indices/page_index.rb
|
152
|
+
- app/indices/user_index.rb
|
153
|
+
- lib/pages_sphinx.rb
|
154
|
+
- lib/pages_sphinx/category_extension.rb
|
155
|
+
- lib/pages_sphinx/engine.rb
|
156
|
+
- lib/pages_sphinx/page_extension.rb
|
157
|
+
- lib/pages_sphinx/page_file_extension.rb
|
158
|
+
- lib/pages_sphinx/pages_controller_extension.rb
|
159
|
+
- lib/pages_sphinx/user_extension.rb
|
160
|
+
- lib/pages_sphinx/version.rb
|
161
|
+
- lib/rails/generators/pages_sphinx/install/install_generator.rb
|
162
|
+
- lib/rails/generators/pages_sphinx/install/templates/thinking_sphinx.yml
|
163
|
+
homepage: https://github.com/anyone-oslo/pages_sphinx
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: 1.9.2
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project: "."
|
183
|
+
rubygems_version: 2.4.5
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Sphinx support for Pages
|
187
|
+
test_files: []
|