faceted_search 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/app/models/faceted_search/facets/full_tree.rb +22 -0
- data/app/models/faceted_search/facets/list.rb +2 -2
- data/app/models/faceted_search/facets.rb +5 -1
- data/app/views/faceted_search/_facets.html.erb +8 -7
- data/app/views/faceted_search/facets/_full_tree.html.erb +8 -0
- data/app/views/faceted_search/facets/_list.html.erb +16 -11
- data/app/views/faceted_search/facets/_text.html.erb +21 -18
- data/app/views/faceted_search/facets/_tree.html.erb +30 -24
- data/app/views/faceted_search/facets/full_tree/_values.html.erb +16 -0
- data/lib/faceted_search/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40e1b27cf5c4266abfb4adeb45a75e915985334d6b57027e126f0dde3df31703
|
4
|
+
data.tar.gz: cd236dc85e1405e760b481b54a412e0379bda78f87e4c4d84ce5ce96ea856c11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a78d0cc408c4428e5764e6fd4df090a6a298288054ed18c9dfa8e3ac31f8df55ee57f696fbd885dc2d664dfb284f8bf549442478468968e6fd4b4b56a9bda8a
|
7
|
+
data.tar.gz: 49a64dfd21621fff301272072fa0d0529b244d775da075c2ff19a92bc45a1c983f5249b63ac0dc845f1a8291c505afe719105c1bc2d2f86a121d684a6bf8c087
|
data/README.md
CHANGED
@@ -49,6 +49,13 @@ Create a model defining your facets:
|
|
49
49
|
children.order(:title)
|
50
50
|
}
|
51
51
|
}
|
52
|
+
# Other tree option, shows all values
|
53
|
+
# filter_with_full_tree :categories, {
|
54
|
+
# habtm: true,
|
55
|
+
# children_scope: Proc.new { |children|
|
56
|
+
# children.order(:title)
|
57
|
+
# }
|
58
|
+
# }
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
@@ -82,5 +89,23 @@ If you need, you can add an anchor to the links:
|
|
82
89
|
<%= render 'faceted_search/facets', facets: @facets, anchor: "#identifier" %>
|
83
90
|
|
84
91
|
|
92
|
+
## Note about full tree
|
93
|
+
|
94
|
+
Tagging must be logical in order to use filter_with_full_tree.
|
95
|
+
With these categories:
|
96
|
+
|
97
|
+
Blues
|
98
|
+
Chicago blues
|
99
|
+
Delta Blues
|
100
|
+
Memphis Blues
|
101
|
+
Jazz
|
102
|
+
Free jazz
|
103
|
+
Swing
|
104
|
+
Latin jazz
|
105
|
+
|
106
|
+
If something is tagged as "Delta blues", it MUST be tagged as "Blues" as well.
|
107
|
+
Otherwise, it creates very odd comportments (selecting "Blues" does not show the object, whereas it is "Delta blues").
|
108
|
+
There is no inference whatsoever, so the data MUST be clean.
|
109
|
+
|
85
110
|
## License
|
86
111
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FacetedSearch
|
2
|
+
class Facets::FullTree < Facets::DefaultList
|
3
|
+
def children_scope
|
4
|
+
@options[:children_scope] ||= Proc.new { |children| children }
|
5
|
+
end
|
6
|
+
|
7
|
+
def child_values(value)
|
8
|
+
filtered children_scope.call(value.children)
|
9
|
+
end
|
10
|
+
|
11
|
+
def values
|
12
|
+
filtered source.root
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def filtered(list)
|
18
|
+
joined_table = facets.model_table_name.to_sym
|
19
|
+
list.joins(joined_table).where(joined_table => { id: facets.results }).distinct
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module FacetedSearch
|
2
2
|
class Facets::List < Facets::DefaultList
|
3
3
|
|
4
|
-
# Show all values that have corresponding results.
|
4
|
+
# Show all values that have corresponding results with the current params.
|
5
5
|
# This is a regular SQL inner join.
|
6
6
|
def values
|
7
7
|
unless @values
|
8
8
|
joined_table = facets.model_table_name.to_sym
|
9
|
-
@values = source.all.joins(joined_table).where(joined_table => { id: facets.
|
9
|
+
@values = source.all.joins(joined_table).where(joined_table => { id: facets.results }).distinct
|
10
10
|
end
|
11
11
|
@values
|
12
12
|
end
|
@@ -32,7 +32,7 @@ module FacetedSearch
|
|
32
32
|
list.each do |facet|
|
33
33
|
scope = facet.add_scope(scope)
|
34
34
|
end
|
35
|
-
scope
|
35
|
+
scope.distinct
|
36
36
|
end
|
37
37
|
|
38
38
|
def model_table_name
|
@@ -53,6 +53,10 @@ module FacetedSearch
|
|
53
53
|
add_facet Tree, value, options
|
54
54
|
end
|
55
55
|
|
56
|
+
def filter_with_full_tree(value, options = {})
|
57
|
+
add_facet FullTree, value, options
|
58
|
+
end
|
59
|
+
|
56
60
|
def params_for(value)
|
57
61
|
@params[value] if @params.has_key? value
|
58
62
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
<%
|
2
2
|
anchor ||= ''
|
3
|
+
reset ||= 'Reset'
|
3
4
|
%>
|
4
5
|
<ul class="faceted__facets list-unstyled">
|
5
6
|
<% facets.list.each do |facet| %>
|
6
|
-
|
7
|
-
<% unless facet.title.blank? %>
|
8
|
-
<b><%= facet.title %></b>
|
9
|
-
<% end %>
|
10
|
-
<%= render facet.kind.underscore, facet: facet, anchor: anchor %>
|
11
|
-
</li>
|
7
|
+
<%= render facet.kind.underscore, facet: facet, anchor: anchor %>
|
12
8
|
<% end %>
|
13
|
-
<li class="faceted__facet__reinit"
|
9
|
+
<li class="faceted__facet__reinit">
|
10
|
+
<a href="<%= facets.path%>">
|
11
|
+
<i class="fas fa-ban"></i>
|
12
|
+
<%= reset %>
|
13
|
+
</a>
|
14
|
+
</li>
|
14
15
|
</ul>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% if facet.values.any? %>
|
2
|
+
<li>
|
3
|
+
<% unless facet.title.blank? %><b><%= facet.title %></b><% end %>
|
4
|
+
<ol class="faceted__facet__full_tree list-unstyled ">
|
5
|
+
<%= render 'faceted_search/facets/full_tree/values', values: facet.values, facet: facet %>
|
6
|
+
</ol>
|
7
|
+
</li>
|
8
|
+
<% end %>
|
@@ -1,11 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
<% if facet.values.any? %>
|
2
|
+
<li>
|
3
|
+
<% unless facet.title.blank? %><b><%= facet.title %></b><% end %>
|
4
|
+
<ol class="faceted__facet__list list-unstyled">
|
5
|
+
<% facet.values.each do |value| %>
|
6
|
+
<%
|
7
|
+
identifier = value.send facet.find_by
|
8
|
+
display_value = facet.display_method.call(value)
|
9
|
+
%>
|
10
|
+
<li class="faceted__facet__list__value<%= '--selected' if facet.value_selected?(identifier) %>">
|
11
|
+
<%= link_to display_value, facet.facets.path_for(facet, identifier) + anchor %>
|
12
|
+
</li>
|
13
|
+
<% end %>
|
14
|
+
</ol>
|
15
|
+
</li>
|
16
|
+
<% end %>
|
@@ -1,18 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<% facet.facets.
|
4
|
-
|
5
|
-
<%
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
<li>
|
2
|
+
<% unless facet.title.blank? %><b><%= facet.title %></b><% end %>
|
3
|
+
<% value = params[:facets][facet.name] if params[:facets] && params[:facets].has_key?(facet.name) %>
|
4
|
+
<form action="<%= anchor %>" class="faceted__facet__text form-inline">
|
5
|
+
<% facet.facets.list.each do |f| %>
|
6
|
+
<% next if f == facet %>
|
7
|
+
<% next if f.params.blank? %>
|
8
|
+
<input type="hidden"
|
9
|
+
name="facets[<%= f.name %>]"
|
10
|
+
value="<%= f.params %>" />
|
11
|
+
<% end %>
|
12
|
+
<input type="search"
|
13
|
+
name="facets[<%= facet.name %>]"
|
14
|
+
placeholder="<%= facet.placeholder %>"
|
15
|
+
value="<%= value %>"
|
16
|
+
class="form-control" />
|
17
|
+
<input type="submit"
|
18
|
+
class="btn btn-light"
|
19
|
+
value="OK" />
|
20
|
+
</form>
|
21
|
+
</li>
|
@@ -1,26 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
<% if facet.values.any? %>
|
2
|
+
<li>
|
3
|
+
<% unless facet.title.blank? %><b><%= facet.title %></b><% end %>
|
4
|
+
<div class="faceted__facet__tree<% if facet.selected_object %> faceted__facet__tree--selected<% end %>">
|
5
|
+
<% if facet.selected_object %>
|
6
|
+
<%
|
7
|
+
display_value = facet.display_method.call(facet.selected_object)
|
8
|
+
identifier = facet.selected_object.send facet.find_by
|
9
|
+
path = facet.facets.path_for(facet, identifier)
|
10
|
+
%>
|
11
|
+
<div class="faceted__facet__tree__back">
|
12
|
+
<%= link_to path do %>
|
13
|
+
<i class="fas fa-arrow-left"></i> <%= display_value %>
|
14
|
+
<% end %>
|
15
|
+
</div>
|
11
16
|
<% end %>
|
12
|
-
</div>
|
13
|
-
<% end %>
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
</
|
18
|
+
<ol class="faceted__facet__tree__values list-unstyled ">
|
19
|
+
<% facet.values.each do |value| %>
|
20
|
+
<%
|
21
|
+
display_value = facet.display_method.call(value)
|
22
|
+
identifier = value.send facet.find_by
|
23
|
+
path = facet.facets.path_for(facet, identifier)
|
24
|
+
%>
|
25
|
+
<li class="faceted__facet__tree__value">
|
26
|
+
<%= link_to display_value, path %>
|
27
|
+
</li>
|
28
|
+
<% end %>
|
29
|
+
</ol>
|
30
|
+
</div>
|
31
|
+
</li>
|
32
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% values.each do |value| %>
|
2
|
+
<%
|
3
|
+
display_value = facet.display_method.call(value)
|
4
|
+
identifier = value.send facet.find_by
|
5
|
+
path = facet.facets.path_for(facet, identifier)
|
6
|
+
%>
|
7
|
+
<li class="faceted__facet__full_tree__value<%= '--selected' if facet.value_selected?(identifier) %>">
|
8
|
+
<%= link_to display_value, path %>
|
9
|
+
<% child_values = facet.child_values(value) %>
|
10
|
+
<% if child_values.any? %>
|
11
|
+
<ol>
|
12
|
+
<%= render 'faceted_search/facets/full_tree/values', values: child_values, facet: facet %>
|
13
|
+
</ol>
|
14
|
+
<% end %>
|
15
|
+
</li>
|
16
|
+
<% end %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faceted_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-04-
|
13
|
+
date: 2019-04-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -125,13 +125,16 @@ files:
|
|
125
125
|
- app/models/faceted_search/facets.rb
|
126
126
|
- app/models/faceted_search/facets/default.rb
|
127
127
|
- app/models/faceted_search/facets/default_list.rb
|
128
|
+
- app/models/faceted_search/facets/full_tree.rb
|
128
129
|
- app/models/faceted_search/facets/list.rb
|
129
130
|
- app/models/faceted_search/facets/text.rb
|
130
131
|
- app/models/faceted_search/facets/tree.rb
|
131
132
|
- app/views/faceted_search/_facets.html.erb
|
133
|
+
- app/views/faceted_search/facets/_full_tree.html.erb
|
132
134
|
- app/views/faceted_search/facets/_list.html.erb
|
133
135
|
- app/views/faceted_search/facets/_text.html.erb
|
134
136
|
- app/views/faceted_search/facets/_tree.html.erb
|
137
|
+
- app/views/faceted_search/facets/full_tree/_values.html.erb
|
135
138
|
- lib/faceted_search.rb
|
136
139
|
- lib/faceted_search/engine.rb
|
137
140
|
- lib/faceted_search/railtie.rb
|