recommendable 2.2.1 → 2.2.2
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/lib/recommendable/ratable.rb +4 -2
- data/lib/recommendable/rater/recommender.rb +10 -2
- data/lib/recommendable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47774cd75a72e1b2b326d535fc8dd5899481191dead0b71c0ced41d8f41ad81f
|
4
|
+
data.tar.gz: 117743d3c8bd0b1a5d217f16f35a2e101c2e56da5a6400ad128c2d6b00427d08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be8f704d0b9cc3329573da17d526f0c07bb5a27ee1792ca1446956850eb556b8b0fb9b4f12d964d9a8999157123d4f75c5b771c4184b452169754e1d4f71c20d
|
7
|
+
data.tar.gz: b4665e65e201f8d7f742792be24a92cbc347d296abaa95db07bbc080e468db4e7c53889722c4d034dcc512cd1f41943a28d269cc728e77c26bd90bbec1692e4a
|
@@ -43,11 +43,13 @@ module Recommendable
|
|
43
43
|
|
44
44
|
# Query for the top-N items sorted by score
|
45
45
|
#
|
46
|
-
# @param [
|
46
|
+
# @param [Hash] options a hash of options to modify which items are returned
|
47
|
+
# @option options [Integer] :count the number of items to fetch (defaults to 1)
|
48
|
+
# @option options [Integer] :offset an offset to allow paging through results
|
47
49
|
# @return [Array] the top items belonging to this class, sorted by score
|
48
50
|
def self.top(options = {})
|
49
51
|
if options.is_a?(Integer)
|
50
|
-
options = { :count => options}
|
52
|
+
options = { :count => options }
|
51
53
|
warn "[DEPRECATION] Recommenable::Ratable.top now takes an options hash. Please call `.top(count: #{options[:count]})` instead of just `.top(#{options[:count]})`"
|
52
54
|
end
|
53
55
|
options.reverse_merge!(:count => 1, :offset => 0)
|
@@ -8,8 +8,9 @@ module Recommendable
|
|
8
8
|
# @return [Array] An array of instances of your user class
|
9
9
|
def similar_raters(limit = 10, offset = 0)
|
10
10
|
ids = Recommendable.redis.zrevrange(Recommendable::Helpers::RedisKeyMapper.similarity_set_for(id), 0, -1)
|
11
|
+
ids = sanitize_ids(ids, self.class)
|
11
12
|
|
12
|
-
order = ids.map { |id| "#{Recommendable.config.user_class.quoted_table_name}.#{Recommendable.config.user_class.quoted_primary_key} =
|
13
|
+
order = ids.map { |id| "#{Recommendable.config.user_class.quoted_table_name}.#{Recommendable.config.user_class.quoted_primary_key} = ? DESC" }.join(', ')
|
13
14
|
order = self.class.send(:sanitize_sql_for_assignment, [order, *ids])
|
14
15
|
|
15
16
|
Recommendable.query(self.class, ids).order(order).limit(limit).offset(offset)
|
@@ -26,14 +27,21 @@ module Recommendable
|
|
26
27
|
|
27
28
|
ids = Recommendable.redis.zrevrange(recommended_set, 0, -1, :with_scores => true)
|
28
29
|
ids = ids.select { |id, score| score > 0 }.map { |pair| pair.first }
|
30
|
+
ids = sanitize_ids(ids, klass)
|
29
31
|
|
30
|
-
order = ids.map { |id| "#{klass.quoted_table_name}.#{klass.quoted_primary_key} =
|
32
|
+
order = ids.map { |id| "#{klass.quoted_table_name}.#{klass.quoted_primary_key} = ? DESC" }.join(', ')
|
31
33
|
order = klass.send(:sanitize_sql_for_assignment, [order, *ids])
|
32
34
|
Recommendable.query(klass, ids).order(order).limit(limit).offset(offset)
|
33
35
|
end
|
34
36
|
|
35
37
|
private
|
36
38
|
|
39
|
+
# Sanitizes ids using klass type mapping
|
40
|
+
# @private
|
41
|
+
def sanitize_ids(ids, klass)
|
42
|
+
ids.map{ |id| klass.new(klass.primary_key => id).send(klass.primary_key) }.compact
|
43
|
+
end
|
44
|
+
|
37
45
|
# Removes an item from a user's set of recommendations
|
38
46
|
# @private
|
39
47
|
def unrecommend(obj)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recommendable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|