spotlight_search 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +63 -1
- data/lib/spotlight_search.rb +2 -0
- data/lib/spotlight_search/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fcbc12f0614877e2fc4dd201b0885d74c6ae169b4cbb56760ee3db5bc1f11ce4
|
|
4
|
+
data.tar.gz: c5a8e1299b3b4cc5b2ae8113e66e8afb1e6a08b57cadf526c45780b935b808ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90221663054cdbff4fcdc9293998a272aee5926548912fed9ad98441b8e294a18cb24b5dc871d78cf52eb27e90d5f8b57aa43ab7aaa4143928335ba3add7c56f
|
|
7
|
+
data.tar.gz: 126fc9efce631043f391d16f23af181963817648f113d230124e80e56e383fb5b4d9dd98fe3d5fc9c65f2da1d076a98186c9ed1d8cb9989e1c6552cc4989e040
|
data/README.md
CHANGED
|
@@ -22,7 +22,69 @@ Or install it yourself as:
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
After installing the gem to the project, there are few places you will have to make changes.
|
|
26
|
+
|
|
27
|
+
### Controller
|
|
28
|
+
|
|
29
|
+
**STEP - 1**
|
|
30
|
+
|
|
31
|
+
First step is to add the search method to the index action.
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
@filtered_result = @workshop.filter_by(params[:page], filter_params.to_h, sort_params.to_h)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`filter_by` is the search method which accepts 3 arguments. `page`, `filter_params`, `sort_params`.
|
|
38
|
+
All 3 params are sent from the JS which is handled by the gem.
|
|
39
|
+
|
|
40
|
+
**STEP - 2**
|
|
41
|
+
|
|
42
|
+
Second Step is to add the permitted params. Since the JS is taking up values from HTML,
|
|
43
|
+
we do not want all params to be accepted. Permit only the scopes that you want to allow.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
def filter_params
|
|
47
|
+
params.require(:filters).permit(:search) if params[:filters]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def sort_params
|
|
51
|
+
params.require(:sort).permit(:sort_column, :sort_direction) if params[:sort]
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### HTML
|
|
56
|
+
**STEP - 1 Search**
|
|
57
|
+
|
|
58
|
+
First step is to add the input box to search. Here there are few elements that should be placed mandatorily.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
.filters.w-100 data-filter-url="/admin/workshops" data-replacement-class="workshops_table"
|
|
62
|
+
.col-md-4.input-group.search
|
|
63
|
+
input#workshop-search-filter.form-control.filter-box name=("search_term_for_workshops ") placeholder=("Search Workshops") type="text" data-behaviour="filter" data-scope="search" data-type="input-filter"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The elements that should be placed mandatorily are
|
|
67
|
+
|
|
68
|
+
* `.filters` All search input / select filter should be nested inside this class name.
|
|
69
|
+
* `data-filter-url` Is mandatory, this is the search URL, Mostly this will hit the index action.
|
|
70
|
+
* `data-replacement-class` After ajax this is the class name where the data will get appended.
|
|
71
|
+
* `data-behaviour="filter"` If the input behaviour is set to filter then this will get added to ajax
|
|
72
|
+
* `data-scope="search"` This is the model scope name, The helper method will call this when filter is applied.
|
|
73
|
+
* `data-type="input-filter"` This is to tell if the element is input or select other value is `data-type="select-filter"`
|
|
74
|
+
|
|
75
|
+
**STEP - 2 Pagination**
|
|
76
|
+
|
|
77
|
+
We will add the paginate helper to the bottom of the partial which gets replaced.
|
|
78
|
+
```
|
|
79
|
+
= cm_paginate(@filtered_result.facets)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**STEP - 3 Sort**
|
|
83
|
+
|
|
84
|
+
If any of the header needs to be sorted, then we will add the following helper
|
|
85
|
+
```
|
|
86
|
+
th = sortable "name", "Name", @filtered_result.sort[:sort_column], @filtered_result.sort[:sort_direction]
|
|
87
|
+
```
|
|
26
88
|
|
|
27
89
|
## Development
|
|
28
90
|
|
data/lib/spotlight_search.rb
CHANGED
|
@@ -14,6 +14,8 @@ module SpotlightSearch
|
|
|
14
14
|
filtered_result.data = raw_data.page(page).per(30)
|
|
15
15
|
filtered_result.facets = self.paginate(page, raw_data.size)
|
|
16
16
|
filtered_result.sort = sort_params
|
|
17
|
+
filtered_result.facets.sort = sort_params
|
|
18
|
+
|
|
17
19
|
return filtered_result
|
|
18
20
|
end
|
|
19
21
|
|