trestle-search 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6e66c7976251e2847893227f257d2d71928c01ec
4
- data.tar.gz: 806335714fe6464a0d15f8787d8752b8e49dbf82
2
+ SHA256:
3
+ metadata.gz: 3b0d81acc19c8af1130e82598e8a8c6692ea1d303874f9ddc4b44a91b816447b
4
+ data.tar.gz: c806a1734cd63cebc00e78c19f2191da54ef56675eb11ca7e50fac1b55039d19
5
5
  SHA512:
6
- metadata.gz: 598078f2d1171666b33708e3cc8b3258006307234f5acc6b32c0b803e93aeafad702c63953da1dfb5f0dbb98d61e8148a8003ba1c957f552136cb1cab52f61ea
7
- data.tar.gz: 8dccd48ea03cfdadaa8cddb29d4bb4c3a673804423922135aa9d775091b9c5a4a9e481b6dbd7e3ae2b182e173611aca035430db3441bf6b895f97b2e1540edf6
6
+ metadata.gz: 36f4856d6b27759116fd98f589fff5101e283c9f2d66d7525791424df9678cd2496cccab3fdc5eb2ac2a4936eda31b63d601094201e623a965f9e208314e4824
7
+ data.tar.gz: 91022be5e6490aad23d6c9adc8cc751a5e3d5bf599550160e18c1b9e8c7832685539928a0924d6c3506e26b818b5656dbe0fb90620d0a5bfc6e352f00e82e8bd
data/README.md CHANGED
@@ -17,17 +17,19 @@ To enable search capabilities within an admin resource, define a `search` block:
17
17
 
18
18
  ```ruby
19
19
  Trestle.resource(:articles) do
20
- search do |q|
21
- Article.where("title ILIKE ?", "%#{q}%")
20
+ search do |query|
21
+ if query
22
+ Article.where("title ILIKE ?", "%#{query}%")
23
+ else
24
+ Article.all
25
+ end
22
26
  end
23
27
  end
24
28
  ```
25
29
 
26
- The search block accepts one or two parameters; the first is the string value of the search query. The second, optional parameter is the full `params` hash.
27
-
28
- The search block will be called instead of the default (or custom) `collection` block when the `q` query parameter is present (i.e. when a search query has been entered). It must return a chainable scope.
30
+ The search block accepts one or two parameters; the first is the string value of the search query. The second, optional parameter is the full `params` hash. The block should return a chainable scope.
29
31
 
30
- The original collection block can be called to avoid redefining scopes. For example:
32
+ The search block overrides the default (or custom) `collection` block. However the original collection block can be called to avoid redefining scopes. For example:
31
33
 
32
34
  ```ruby
33
35
  Trestle.resource(:articles) do
@@ -36,12 +38,20 @@ Trestle.resource(:articles) do
36
38
  end
37
39
 
38
40
  search do |q|
39
- collection.where("title ILIKE ?", "%#{q}%")
41
+ q ? collection.where("title ILIKE ?", "%#{q}%") : collection
40
42
  end
41
43
  end
42
44
  ```
43
45
 
44
46
 
47
+ ## Integration Examples
48
+
49
+ 1. [ActiveRecord (ILIKE)](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-ActiveRecord-(ILIKE))
50
+ 2. [PgSearch](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-PgSearch)
51
+ 3. [Chewy](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-Chewy)
52
+ 4. [Sunspot](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-Sunspot)
53
+
54
+
45
55
  ## License
46
56
 
47
57
  The gem is available as open source under the terms of the [LGPLv3 License](https://opensource.org/licenses/LGPL-3.0).
data/config/locale/en.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  en:
2
2
  admin:
3
3
  search:
4
- placeholder: Search
5
- results: Search Results
4
+ placeholder: "Search"
5
+ results: "Search Results"
@@ -0,0 +1,5 @@
1
+ pl:
2
+ admin:
3
+ search:
4
+ placeholder: "Szukaj"
5
+ results: "Wyniki wyszukiwania"
@@ -0,0 +1,5 @@
1
+ pt-BR:
2
+ admin:
3
+ search:
4
+ placeholder: "Pesquisar"
5
+ results: "Resultados da Pesquisa"
@@ -1,5 +1,7 @@
1
1
  require "trestle/search/version"
2
2
 
3
+ require "trestle"
4
+
3
5
  module Trestle
4
6
  module Search
5
7
  extend ActiveSupport::Autoload
@@ -7,6 +9,11 @@ module Trestle
7
9
  autoload :Builder
8
10
  autoload :Controller
9
11
  autoload :Resource
12
+
13
+ autoload_under "adapters" do
14
+ autoload :ChewyAdapter
15
+ autoload :SunspotAdapter
16
+ end
10
17
  end
11
18
  end
12
19
 
@@ -0,0 +1,9 @@
1
+ module Trestle
2
+ module Search
3
+ module ChewyAdapter
4
+ def finalize_collection(query)
5
+ query.records
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Trestle
2
+ module Search
3
+ module SunspotAdapter
4
+ def merge_scopes(scope, other)
5
+ other
6
+ end
7
+
8
+ def count(search)
9
+ search.execute.hits.total_count
10
+ end
11
+
12
+ def sort(search, field, order)
13
+ search.build do
14
+ order_by(field, order)
15
+ end
16
+ end
17
+
18
+ def paginate(search, params)
19
+ search.build do
20
+ paginate(page: params[:page], per_page: 25)
21
+ end
22
+ end
23
+
24
+ def finalize_collection(search)
25
+ search.execute.results
26
+ end
27
+ end
28
+ end
29
+ end
@@ -4,17 +4,15 @@ module Trestle
4
4
  attr_writer :search
5
5
 
6
6
  def initialize_collection(params)
7
- query_param = params[:q]
8
-
9
- if searchable? && query_param.present?
10
- search(query_param, params)
7
+ if searchable?
8
+ search(params[:q], params)
11
9
  else
12
10
  super(params)
13
11
  end
14
12
  end
15
13
 
16
14
  def search(query, params)
17
- instance_exec(query, params, &@search)
15
+ instance_exec(query.presence, params, &@search)
18
16
  end
19
17
 
20
18
  def searchable?
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Search
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "trestle", "~> 0.8"
21
+ spec.add_dependency "trestle", "~> 0.8", ">= 0.8.7"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.12"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trestle-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pohlenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-31 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trestle
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.7
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.7
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -84,7 +90,11 @@ files:
84
90
  - app/views/trestle/search/_search.html.erb
85
91
  - config/initializers/trestle.rb
86
92
  - config/locale/en.yml
93
+ - config/locale/pl.yml
94
+ - config/locale/pt-BR.yml
87
95
  - lib/trestle/search.rb
96
+ - lib/trestle/search/adapters/chewy_adapter.rb
97
+ - lib/trestle/search/adapters/sunspot_adapter.rb
88
98
  - lib/trestle/search/builder.rb
89
99
  - lib/trestle/search/controller.rb
90
100
  - lib/trestle/search/engine.rb
@@ -111,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
121
  version: '0'
112
122
  requirements: []
113
123
  rubyforge_project:
114
- rubygems_version: 2.6.12
124
+ rubygems_version: 2.7.3
115
125
  signing_key:
116
126
  specification_version: 4
117
127
  summary: Search plugin for the Trestle admin framework