soulheart 0.2.2 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b940c579f757c257a88e570248db8b58e960c1b2
4
- data.tar.gz: f4b963e11a35ee654f71480f12ace35d65b9c213
2
+ SHA256:
3
+ metadata.gz: cdb795313ac11f814661f05f909345f831b473a8ae77fdef354918820012f13e
4
+ data.tar.gz: 5cf89e90855b28a0d721fb9feeb359c80fb35243f8f42e90297af5b02c49f3dd
5
5
  SHA512:
6
- metadata.gz: 5c932ab836432de24dbb7f8d040926a64fb93b57d2dc4dc5fbd7b007703013ddba084092537c7b9895ce14398d12caaea1e82a02bc40518c1e9a6ad204505e11
7
- data.tar.gz: a5381685e30a771b118a39ea6c02f1831c078ec964687ddb75c1d372c146c4003cbf0f8288c09e90e223b7a9d5763f985bbc2ff9fb6aa7f9bfe59f6e001dafc0
6
+ metadata.gz: f8e8b2f350377d635fceb04a0da5247bfafe464240454ccda378831c6323eb3e01e9db059716744f0439eb3a7c2cf0ee99347c1abe2db70ed1de30ff2d9b3406
7
+ data.tar.gz: bbea122eeaf96cd47222c8d91256760b53a84e696b0e6a638fb146155579942f51643161f4f8e357206e250a03d41f9d6b512d37c513097a3ad241ee992c3cb6
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
- # <img src="https://raw.githubusercontent.com/sethherr/soulheart/master/examples/logo.png" alt="Soulheart" width="200"> Soulheart [![Build Status](https://travis-ci.org/sethherr/soulheart.svg)](https://travis-ci.org/sethherr/soulheart) [![Code Climate](https://codeclimate.com/github/sethherr/soulheart/badges/gpa.svg)](https://codeclimate.com/github/sethherr/soulheart) [![Test Coverage](https://codeclimate.com/github/sethherr/soulheart/badges/coverage.svg)](https://codeclimate.com/github/sethherr/soulheart/coverage)
1
+ # <img src="https://raw.githubusercontent.com/sethherr/soulheart/master/examples/logo.png" alt="Soulheart" width="200"> Soulheart [![Build Status](https://travis-ci.org/sethherr/soulheart.svg?branch=master)](https://travis-ci.org/sethherr/soulheart) [![Code Climate](https://codeclimate.com/github/sethherr/soulheart/badges/gpa.svg)](https://codeclimate.com/github/sethherr/soulheart) [![Test Coverage](https://codeclimate.com/github/sethherr/soulheart/badges/coverage.svg)](https://codeclimate.com/github/sethherr/soulheart/coverage)
2
2
 
3
3
  Soulheart is a ready-to-use remote data source for autocomplete. The goal is to provide a solid, flexible tool that's downright easy to set up and use.
4
4
 
5
- - [Demos](https://sethherr.github.io/soulheart/)
6
- - [Usage documentation](https://sethherr.github.io/soulheart/commands/)
5
+ - [Intro page](https://sethherr.github.io/soulheart/)
6
+ - [Usage documentation (commands)](https://sethherr.github.io/soulheart/commands/)
7
7
  - [Example data sources](https://github.com/sethherr/soulheart/tree/master/examples)
8
8
  - [Getting started](#getting-started)
9
9
  - [Deployment](#deployment)
10
10
  - [Testing](#testing)
11
+ - Example usage [with Selectize](https://sethherr.github.io/soulheart/examples_selectize) & [Select2](https://sethherr.github.io/soulheart/examples_select2)
11
12
 
12
13
 
13
14
  ## Features
@@ -29,7 +30,7 @@ Soulheart is a ready-to-use remote data source for autocomplete. The goal is to
29
30
 
30
31
  ## Getting started
31
32
 
32
- See the [Soulheart demo page](https://sethherr.github.io/soulheart/) for a step-by-step explanation of creating an instance and setting up a select box that uses it as a remote data source.
33
+ See the [Soulheart intro page](https://sethherr.github.io/soulheart/) for a step-by-step explanation of setting up a select box that uses Soulheart as a remote data source.
33
34
 
34
35
 
35
36
  ## Deployment
@@ -43,21 +44,40 @@ To update your Heroku deploy of Soulheart, use the [Heroku CLI](https://devcente
43
44
  heroku deploy -a NAME_OF_YOUR_APP_ON_HEROKU
44
45
 
45
46
 
46
- #### In a Rails app
47
+ ## In a Rails app
47
48
 
48
- Soulheart is a gem. Add it to your gemfile:
49
+ Soulheart is a gem. It uses [hiredis](https://github.com/redis/hiredis) on Ruby MRI. Add these lines to your gemfile:
49
50
 
50
51
  gem 'soulheart'
52
+ gem 'hiredis', '~> 0.6.0' # Skip using JRuby
53
+ gem 'redis', '>= 3.2.0', require: ['redis', 'redis/connection/hiredis'] # Skip if using JRuby
51
54
 
52
- And then put this in your routes.rb
55
+
56
+ And add this in your routes.rb:
53
57
 
54
58
  require 'soulheart/server'
55
- mount Soulheart::Server => "/soulhearts"
59
+
60
+ Rails.application.routes.draw do
61
+ # .... your application routes
62
+
63
+ mount Soulheart::Server => '/soulhearts'
64
+ end
56
65
 
57
66
  You can then access the server when your rails app is running. You can run the [Soulheart commands](https://sethherr.github.io/soulheart/commands/) from that directory.
58
67
 
59
- *note: On Heroku Soulheart uses `rackup` to start the server. Because of this, there's a `config.ru` and a `Gemfile.lock`&mdash;to make it (and any forks) directly deployable. These files aren't in the Gem.*
68
+ *Hote: On Heroku Soulheart uses `rackup` to start the server. Because of this, there's a `config.ru`, a `Gemfile.lock` and a `app.json`&mdash;to make it (and any forks of it) directly deployable. These files aren't in the Gem.*
69
+
70
+ ##### Setting redis url
71
+
72
+ You can also set the redis url.
73
+
74
+ ```ruby
75
+ # config/initializers/soulheart.rb
60
76
 
77
+ Soulheart.redis = 'redis://127.0.0.1:6379/0'
78
+ # or you can asign an existing instance of Redis, Redis::Namespace, etc.
79
+ # Soulheart.redis = $redis
80
+ ```
61
81
  ## Testing
62
82
 
63
83
  Tested with rspec. Check out test information at [Code Climate](https://codeclimate.com/github/sethherr/soulheart).
@@ -73,6 +93,6 @@ It requires Redis >= 3.0
73
93
 
74
94
  ## Additional info
75
95
 
76
- This is an extended fork of [Soulmate](https://github.com/seatgeek/soulmate), to bring it up to date, make it slicker, and make it deployable to Heroku.
96
+ This initially started as a fork of [Soulmate](https://github.com/seatgeek/soulmate) to support the features listed, provide demos and make it instantly deployable to Heroku.
77
97
 
78
98
  It's MIT licensed.
data/bin/soulheart CHANGED
@@ -107,7 +107,7 @@ def load(file)
107
107
  lines = []
108
108
  @batch_size.times do
109
109
  break if f.eof?
110
- lines << MultiJson.decode(f.gets)
110
+ lines << JSON.parse(f.gets)
111
111
  count += 1
112
112
  end
113
113
  end
data/lib/soulheart.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'multi_json'
2
-
1
+ require 'json'
3
2
  require 'soulheart/version'
4
3
  require 'soulheart/helpers'
5
4
  require 'soulheart/base'
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'uri'
2
3
  require 'redis'
3
4
 
@@ -28,7 +29,7 @@ module Soulheart
28
29
  def redis
29
30
  @redis ||= (
30
31
  url = URI(@redis_url || ENV['REDIS_URL'] || 'redis://127.0.0.1:6379/0')
31
- ::Redis.new( #
32
+ ::Redis.new(
32
33
  driver: (jruby? ? :ruby : :hiredis),
33
34
  host: url.host,
34
35
  port: url.port,
@@ -55,20 +55,19 @@ module Soulheart
55
55
  # everything will work itself out as soon as the cache expires again.
56
56
  end
57
57
 
58
- def remove_results_hash
59
- # delete the data store
60
- # We don't do this every time we clear because because it breaks the caching feature.
61
- # The option to clear this is only called in testing right now.
62
- # There should be an option to clear it other times though.
58
+ def clear_cache
59
+ # Remove the remove_results_hash
60
+ # has to be called before the cat_ids are cleared
61
+ category_combos.map { |cat| redis.expire(no_query_id(category_id(cat)), 0) }
63
62
  redis.expire results_hashes_id, 0
64
63
  redis.del(results_hashes_id)
65
64
  end
66
65
 
67
- def clear(remove_results=false)
66
+ def clear(should_clear_cache = false)
67
+ clear_cache if should_clear_cache
68
68
  category_combos.each {|cat| delete_data(category_id(cat)) }
69
69
  delete_categories
70
70
  delete_data
71
- remove_results_hash if remove_results
72
71
  end
73
72
 
74
73
  def load(items)
@@ -121,7 +120,7 @@ module Soulheart
121
120
  redis.pipelined do
122
121
  redis.zadd(no_query_id(category_base_id), priority, item['term']) # Add to master set for queryless searches
123
122
  # store the raw data in a separate key to reduce memory usage, if it's cleaned it's done
124
- redis.hset(results_hashes_id, item['term'], MultiJson.encode(item['data'])) unless cleaned
123
+ redis.hset(results_hashes_id, item['term'], item['data'].to_json) unless cleaned
125
124
  phrase = ([item['term']] + (item['aliases'] || [])).join(' ')
126
125
  # Store all the prefixes
127
126
  prefixes_for_phrase(phrase).each do |p|
@@ -65,7 +65,7 @@ module Soulheart
65
65
  return [] unless terms.size > 0
66
66
  results = redis.hmget(results_hashes_id, *terms)
67
67
  results = results.reject(&:nil?) # handle cached results for terms which have since been deleted
68
- results.map { |r| MultiJson.decode(r) }
68
+ results.map { |r| JSON.parse(r) }
69
69
  end
70
70
 
71
71
  def matches
@@ -15,27 +15,27 @@ module Soulheart
15
15
 
16
16
  get '/' do
17
17
  matches = Matcher.new(params).matches
18
- MultiJson.encode(matches: matches)
18
+ {matches: matches}.to_json
19
19
  end
20
20
 
21
21
  get '/categories' do
22
- MultiJson.encode(categories: Base.new.sorted_category_array)
22
+ {categories: Base.new.sorted_category_array}.to_json
23
23
  end
24
24
 
25
25
  get '/info' do
26
26
  info = Soulheart::Base.new.redis.info
27
- MultiJson.encode({
27
+ {
28
28
  soulheart_version: Soulheart::VERSION,
29
29
  current_time: Time.now.utc.strftime('%H:%M:%S UTC'),
30
30
  redis_used_memory: info['used_memory_human'],
31
31
  stop_words: Soulheart.stop_words,
32
32
  normalizer: Soulheart.normalizer,
33
- })
33
+ }.to_json
34
34
  end
35
35
 
36
36
  not_found do
37
37
  content_type 'application/json', charset: 'utf-8'
38
- MultiJson.encode(error: 'not found')
38
+ {error: 'not found'}.to_json
39
39
  end
40
40
  end
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module Soulheart
2
- VERSION = '0.2.2'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soulheart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Herr
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: hiredis
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.4.5
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.4.5
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: redis
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 3.0.6
19
+ version: 3.0.5
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 3.0.6
26
+ version: 3.0.5
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: vegas
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,62 +38,54 @@ dependencies:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: 0.1.0
55
- - !ruby/object:Gem::Dependency
56
- name: json
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: sinatra
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
45
  - - ">="
74
46
  - !ruby/object:Gem::Version
75
- version: '0'
47
+ version: 1.4.4
76
48
  type: :runtime
77
49
  prerelease: false
78
50
  version_requirements: !ruby/object:Gem::Requirement
79
51
  requirements:
80
52
  - - ">="
81
53
  - !ruby/object:Gem::Version
82
- version: '0'
54
+ version: 1.4.4
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: rake
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
- - - ">="
59
+ - - "~>"
88
60
  - !ruby/object:Gem::Version
89
- version: '0'
61
+ version: '10.4'
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
- - - ">="
66
+ - - "~>"
95
67
  - !ruby/object:Gem::Version
96
- version: '0'
68
+ version: '10.4'
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: rspec
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
102
74
  - !ruby/object:Gem::Version
103
- version: '0'
75
+ version: '2.14'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '4.0'
104
79
  type: :development
105
80
  prerelease: false
106
81
  version_requirements: !ruby/object:Gem::Requirement
107
82
  requirements:
108
83
  - - ">="
109
84
  - !ruby/object:Gem::Version
110
- version: '0'
85
+ version: '2.14'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '4.0'
111
89
  description: Simple, fast autocomplete server for Ruby and Rails
112
90
  email:
113
91
  - seth.william.herr@gmail.com
@@ -134,7 +112,7 @@ homepage: https://github.com/sethherr/soulheart
134
112
  licenses:
135
113
  - MIT
136
114
  metadata: {}
137
- post_install_message:
115
+ post_install_message:
138
116
  rdoc_options: []
139
117
  require_paths:
140
118
  - lib
@@ -149,9 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
127
  - !ruby/object:Gem::Version
150
128
  version: '0'
151
129
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.2.2
154
- signing_key:
130
+ rubygems_version: 3.1.4
131
+ signing_key:
155
132
  specification_version: 4
156
133
  summary: Simple, fast autocomplete server for Ruby and Rails
157
134
  test_files: []