soulheart 0.1.3 → 0.1.4

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
2
  SHA1:
3
- metadata.gz: 3e2377142c9db987586cf7355a75bb41223134b6
4
- data.tar.gz: 9d6a719b67686a8be1285fc49d94a0e55bb0cca8
3
+ metadata.gz: 0a9835278571fb659e0eae5ad1d39918bcd41049
4
+ data.tar.gz: e3dbbeecea70b9cf11327f012f3d47e02f64f04b
5
5
  SHA512:
6
- metadata.gz: 5323467ef347623d460b71168ab702533674c790221cef267b5f5422c44a0d5fcb0f59d7f9d2554323e05f76ed57b55fc03800e09b307e2353c5aa1024bac558
7
- data.tar.gz: 9c383b627b46a060d6a3cfbfb2fbe91321867007251509478f11d5c9df16a62c8ecc45c918ff15b400512b62c36d49e1571887114287c0b8153539e7c8bd2d00
6
+ metadata.gz: 01215919be332be2cc67d9885c5bb21380110fa04caf4a424e91f7649aacf696d08c88f24c5a95b0bf88b8329915c93bf1c37976ee3f95b0e96c1cfb7fd2449b
7
+ data.tar.gz: e5b336efcc86b4250cecdb4d61c8427c831dca3eea2ba25f8bf2e362f2cd7ea00612951da3c1160f9f0eb1f9a0e62833b37aab69d20a7507bfafb3ccfbb105bc
@@ -32,8 +32,16 @@ parser = OptionParser.new do |opts|
32
32
  exit
33
33
  end
34
34
 
35
- opts.on('-b', '--batch-size', 'Number of lines to read at a time') do |size|
36
- BATCH_SIZE = size
35
+ opts.on('-A', '--no-all', 'on load: Do not add items into the "all" category (on load)') do |size|
36
+ NO_ALL = true
37
+ end
38
+
39
+ opts.on('-C', '--no-combinatorial', 'Do not create combined categories, do not add items to combined categories (on load)') do |size|
40
+ NO_COMBINATORIAL = true
41
+ end
42
+
43
+ opts.on('-R', '--remove-results', 'Remove results data - breaks the cache, fully clears all loaded data. (on clear)') do |size|
44
+ REMOVE_RESULTS = true
37
45
  end
38
46
 
39
47
  opts.separator ''
@@ -41,6 +49,8 @@ parser = OptionParser.new do |opts|
41
49
  opts.separator ' load FILE Loads data from a FILE - can be a local file or a url. Accepted formats are .json, .tsv and .csv'
42
50
  opts.separator " reset Removes all existing data (optionally pass a file to run load after reset)"
43
51
  opts.separator ''
52
+ opts.separator 'Additional info: https://sethherr.github.io/soulheart/commands/'
53
+ opts.separator ''
44
54
  end
45
55
 
46
56
 
@@ -58,7 +68,7 @@ def load(file)
58
68
 
59
69
  start_time = Time.now.to_i
60
70
  count = 0
61
- loader = Soulheart::Loader.new
71
+ loader = Soulheart::Loader.new({no_all: NO_ALL, no_combinatorial: NO_COMBINATORIAL})
62
72
  lines = []
63
73
  begin
64
74
  if file.match(/(c|t)sv\z/i)
@@ -87,21 +97,23 @@ def load(file)
87
97
  f.close
88
98
  end
89
99
  loader.load(lines)
90
- puts "Loaded a total of #{count} items in #{Time.now.to_i - start_time} second(s)"
100
+ puts "Total time to load: #{Time.now.to_i - start_time} second(s)"
91
101
  end
92
102
 
93
- def clear
94
- Soulheart::Loader.new.clear
103
+ def clear(remove_results)
104
+ Soulheart::Loader.new.clear(remove_results)
95
105
  end
96
106
 
97
107
  parser.parse!
98
- BATCH_SIZE ||= 1000
99
108
 
100
109
  case ARGV[0]
101
110
  when 'load'
111
+ BATCH_SIZE ||= 1000
112
+ NO_ALL ||= false
113
+ NO_COMBINED_CATEGORIES ||= false
102
114
  load ARGV[1]
103
115
  when 'reset'
104
- clear
116
+ clear(REMOVE_RESULTS)
105
117
  load ARGV[1] if ARGV[1]
106
118
  else
107
119
  puts parser.help
@@ -20,6 +20,10 @@ module Soulheart
20
20
  redis.smembers(categories_id).map { |c| normalize(c) }.uniq.sort
21
21
  end
22
22
 
23
+ def hidden_category_array
24
+ redis.smembers(hidden_categories_id).map { |c| normalize(c) }.uniq.sort
25
+ end
26
+
23
27
  def combinatored_category_array
24
28
  1.upto(sorted_category_array.size).
25
29
  flat_map { |n| sorted_category_array.combination(n).
@@ -29,7 +33,7 @@ module Soulheart
29
33
  def set_category_combos_array
30
34
  redis.expire category_combos_id, 0
31
35
  array = combinatored_category_array
32
- array.last.replace('all')
36
+ array.any? ? array.last.replace('all') : array << 'all'
33
37
  redis.sadd category_combos_id, array
34
38
  array
35
39
  end
@@ -46,6 +50,10 @@ module Soulheart
46
50
  "#{base_id}categories:"
47
51
  end
48
52
 
53
+ def hidden_categories_id
54
+ "#{categories_id}hidden:"
55
+ end
56
+
49
57
  def category_id(name = 'all')
50
58
  "#{categories_id}#{name}:"
51
59
  end
@@ -1,5 +1,10 @@
1
1
  module Soulheart
2
2
  class Loader < Base
3
+ def initialize(defaults={})
4
+ @no_all = defaults[:no_all]
5
+ @no_combinatorial = defaults[:no_combinatorial]
6
+ end
7
+
3
8
  def default_items_hash(text, category)
4
9
  category ||= 'default'
5
10
  {
@@ -14,9 +19,19 @@ module Soulheart
14
19
  }
15
20
  end
16
21
 
22
+ def add_to_categories_array(category)
23
+ if @no_combinatorial
24
+ return if redis.smembers(hidden_categories_id).include?(category)
25
+ redis.sadd hidden_categories_id, category
26
+ elsif !redis.smembers(categories_id).include?(category)
27
+ redis.sadd categories_id, category
28
+ end
29
+ end
30
+
17
31
  def delete_categories
18
32
  redis.expire category_combos_id, 0
19
33
  redis.expire categories_id, 0
34
+ redis.expire hidden_categories_id, 0
20
35
  end
21
36
 
22
37
  def reset_categories(categories)
@@ -65,12 +80,20 @@ module Soulheart
65
80
  end
66
81
  set_category_combos_array.each do |category_combo|
67
82
  items.each do |item|
68
- next unless category_combo.match(item['category']) || category_combo == 'all'
83
+ if category_combo == item['category']
84
+ next
85
+ elsif category_combo == 'all'
86
+ next if @no_all
87
+ elsif !category_combo.match(item['category'])
88
+ next
89
+ elsif @no_combinatorial
90
+ next
91
+ end
69
92
  add_item(item, category_id(category_combo), true) # send it base
70
93
  i += 1
71
94
  end
72
95
  end
73
- puts "Total items (including combinatored categories): #{i}"
96
+ puts "Total items (including combinatorial categories): #{i}"
74
97
  end
75
98
 
76
99
  def clean_hash(item)
@@ -87,19 +110,16 @@ module Soulheart
87
110
  item.keys.select{ |k| !%w(category priority term aliases data).include?(k) }.each do |key|
88
111
  item['data'].merge!({"#{key}" => item.delete(key)})
89
112
  end
90
- unless redis.smembers(categories_id).include?(item['category'])
91
- redis.sadd categories_id, item['category']
92
- end
113
+ add_to_categories_array(item['category'])
93
114
  item
94
115
  end
95
116
 
96
117
  def add_item(item, category_base_id=nil, cleaned=false)
97
118
  item = clean(item) unless cleaned
98
119
  category_base_id ||= category_id(item['category'])
99
-
100
120
  priority = (-item['priority'])
101
121
  redis.pipelined do
102
- redis.zadd(no_query_id(category_base_id), priority, item['term']) # Add to master set for queryless searches
122
+ redis.zadd(no_query_id(category_base_id), priority, item['term']) # Add to master set for queryless searches
103
123
  # store the raw data in a separate key to reduce memory usage, if it's cleaned it's done
104
124
  redis.hset(results_hashes_id, item['term'], MultiJson.encode(item['data'])) unless cleaned
105
125
  phrase = ([item['term']] + (item['aliases'] || [])).join(' ')
@@ -1,3 +1,3 @@
1
1
  module Soulheart
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soulheart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Herr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-22 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hiredis
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  requirements: []
166
166
  rubyforge_project:
167
- rubygems_version: 2.2.2
167
+ rubygems_version: 2.4.8
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Simple, fast autocomplete server for Ruby and Rails