spinel 0.0.1 → 0.1.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
2
  SHA1:
3
- metadata.gz: a55bbe4e834685bcef3003c6a53a4722d0d4b3e7
4
- data.tar.gz: bb615a4d0d4c79069686ecd73575f9e228c27942
3
+ metadata.gz: da5beee409ee144651696f28780f01ac1674568c
4
+ data.tar.gz: 95e3ac8b09ad14410d4aa209a3b5403ed886d601
5
5
  SHA512:
6
- metadata.gz: 2a887be953fc67ce0688d578c71faadeeb86badddc9e0b58a92c37abae19010fe412e4f81fcb64b14171f1452c1b63cae042050b2fa9ce64a70344cd94ae94f1
7
- data.tar.gz: 492dc54d734cf244b04d506468d394e7d0c3c1955b54f5c8a7d7542a63bc45ae6f5305e265ad222a58b5457e6259fa5ff163f21f22792b1282affbf4d546b381
6
+ metadata.gz: 772acc69c9303650862441440df10b16509c8ed0a3935c00da3a8d80d93c9cf383ee110e7727f85dfd6d9ac0a2e5f272e8fc08f4bd22e8acc91e4826ce591dde
7
+ data.tar.gz: 30de09fa646a5229a3efae3c192fa186146aa3cd5b7b732f6e5c5fa606c1a190c52b78c2a944ec5fecfd0281e20e9079220962d44afb6e0326670ce711d9d0a8
data/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # Spinel
2
2
 
3
- SpinelRedisをバックエンドに用いた軽量なサジェストシステムです。
3
+ Spinel is Redis based lightweight text search engine.
4
+ SpinelはRedisをバックエンドに用いた軽量なテキスト検索システムです。
4
5
 
5
- ## Installation
6
+ ## コンセプト
7
+
8
+ Spinelはテキスト検索システムですが、余計なことはいたしません。
9
+ 形態素解析やストップワードの除去などはSpinelよりも上位の層で行う必要があります。
10
+ 大規模な全文検索を行う場合にはSolrやElasticsearchの使用を検討してください。
11
+
12
+ ## インストール / Installation
6
13
 
7
14
  Add this line to your application's Gemfile:
8
15
 
@@ -22,18 +29,88 @@ Or install it yourself as:
22
29
  $ gem install spinel
23
30
  ```
24
31
 
25
- ## Usage
32
+ ## 使い方 / Usage
33
+
34
+ ### データ登録 / registration
35
+
36
+ ```ruby
37
+ backend = Spinel.backend
38
+ backend.add id: 1, body: 'and all with pearl and ruby glowing'
39
+ backend.add id: 2, body: 'a yellow or orange variety of ruby spinel'
40
+ backend.add id: 3, body: 'a colour called pearl yellow'
41
+ backend.add id: 4, body: 'a mandarin orange net sack'
42
+ backend.add id: 5, body: 'a spinel used as a gemstone usually dark red'
43
+ backend.add id: 6, body: 'today is hotter than usual'
44
+ backend.add id: 7, body: 'call on a person'
45
+ backend.add id: 8, body: 'that gem is shining'
46
+ backend.add id: 9, body: 'polish shoes to a bright shine'
47
+ ```
48
+
49
+ データの登録時には最低限の要素として `id` 及び `body` が必要になります。
50
+ ドキュメントの内容を示すキーである `body` は後述する設定によって変更することも可能です。
51
+
52
+ `score` がキー含まれていた場合は特別に処理されます。
53
+ `score`はドキュメントの優先度を指定できるキーであり、検索結果の順序に関係します。
26
54
 
27
- ### Configuration
55
+ ### 検索 / search
56
+
57
+ ```ruby
58
+ matcher = Spinel.matcher
59
+ matcher.matches 'ruby'
60
+ # => [{"id"=>2, "body"=>"a yellow or orange variety of ruby spinel"}, {"id"=>1, "body"=>"and all with pearl and ruby glowing"}]
61
+ matcher.matches 'usu'
62
+ # => [{"id"=>6, "body"=>"today is hotter than usual"}, {"id"=>5, "body"=>"a spinel used as a gemstone usually dark red"}]
63
+ ```
64
+
65
+ ### 設定 / Configuration
66
+
67
+ 設定はブロックにより行うことが出来ます。
68
+ 以下の例で示されているデフォルト値で運用する場合には設定は必要ありません。
28
69
 
29
70
  ```ruby
30
71
  Spinel.configure do |config|
31
- config.redis = 'redis://127.0.0.1:6379/0'
32
- config.min_complete = 3
33
- config.cache_expire = 300
72
+ config.redis = 'redis://127.0.0.1:6379/0'
73
+ config.min_complete = 2
74
+ config.cache_expire = 600
75
+ config.match_limit = 10
76
+ config.document_key = :body
77
+ config.namespace = 'spinel'
34
78
  end
35
79
  ```
36
80
 
81
+ #### redisの接続先
82
+
83
+ デフォルトでは `redis://127.0.0.1:6379/0` に接続しようとします。
84
+ 環境変数に `REDIS_URL` が存在するとき、`redis://127.0.0.1:6379/0` よりも優先してその値を使おうとします。
85
+ 明示的な設定が行われた場合には環境変数よりも設定が優先されます。
86
+
87
+ 明示的な設定において文字列が与えられた場合には、文字列をパースしてredisの接続を作成します。
88
+ [resque/redis-namespace](https://github.com/resque/redis-namespace)等を使いたい場合には、直接指定することも可能です。
89
+
90
+ ```ruby
91
+ Spinel.configure do |config|
92
+ config.redis = Redis::Namespace.new(:ns, redis: Redis.new)
93
+ end
94
+ ```
95
+
96
+ #### 検索結果のキャッシュ / 候補数
97
+
98
+ 高速化の為に、同一のクエリーの検索結果は最後の検索から10分間キャッシュされます。
99
+ `config.cache_expire` はキャッシュの有効期限を設定する項目です。
100
+ また `config.match_limit` はデフォルトの検索候補の最大数を変更します。
101
+
102
+ キャッシュの使用と検索候補数は検索時にオプションとして値を指定することも可能です。
103
+
104
+ ```ruby
105
+ matcher.matches 'ruby', cache: false, limit: 5
106
+ ```
107
+
108
+ ## バージョニング / Versioning
109
+
110
+ Spinelのバージョニングは[Semantic Versioning 2.0.0](http://semver.org/)に基づいて採番されます。
111
+ 現在Spinelは開発初期段階です。
112
+ いつでも、いかなる変更も起こりうります。
113
+
37
114
  ## Contributing
38
115
 
39
116
  1. Fork it ( https://github.com/k-shogo/spinel/fork )
@@ -10,7 +10,7 @@ module Spinel
10
10
 
11
11
  Spinel.redis.pipelined do
12
12
  Spinel.redis.hset(database, id, MultiJson.encode(doc))
13
- prefixes_for_phrase(document_to_phrase(doc)).each do |p|
13
+ prefixes_for_phrase(document_body(doc)).each do |p|
14
14
  Spinel.redis.zadd(base_and(p), document_score(doc), id)
15
15
  end
16
16
  end
@@ -28,7 +28,7 @@ module Spinel
28
28
  prev_id = document_id prev_doc
29
29
  Spinel.redis.pipelined do
30
30
  Spinel.redis.hdel(database, prev_id)
31
- prefixes_for_phrase(document_to_phrase(prev_doc)).each do |p|
31
+ prefixes_for_phrase(document_body(prev_doc)).each do |p|
32
32
  Spinel.redis.zrem(base_and(p), prev_id)
33
33
  end
34
34
  end
data/lib/spinel/helper.rb CHANGED
@@ -8,10 +8,6 @@ module Spinel
8
8
  end.flatten.uniq
9
9
  end
10
10
 
11
- def document_to_phrase doc
12
- [document_body(doc), *Array(document_aliases(doc))].join(' ')
13
- end
14
-
15
11
  def document_validate doc
16
12
  raise ArgumentError, "documents must specify both an id and a body" unless document_id(doc) && document_body(doc)
17
13
  end
@@ -28,9 +24,5 @@ module Spinel
28
24
  doc[Spinel.document_key.to_sym] || doc[Spinel.document_key]
29
25
  end
30
26
 
31
- def document_aliases doc
32
- doc[:aliases] || doc["aliases"]
33
- end
34
-
35
27
  end
36
28
  end
@@ -1,6 +1,6 @@
1
1
  module Spinel
2
2
  MAJOR = 0
3
- MINOR = 0
4
- PATCH = 1
3
+ MINOR = 1
4
+ PATCH = 0
5
5
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
6
6
  end
data/spinel.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Spinel::VERSION
9
9
  spec.authors = ["k-shogo"]
10
10
  spec.email = ["platycod0n.ramosa@gmail.com"]
11
- spec.summary = %q{suggest related words}
12
- spec.description = %q{suggest related words}
11
+ spec.summary = %q{lightweight text search system on Redis}
12
+ spec.description = %q{lightweight text search system on Redis}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-shogo
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
- description: suggest related words
69
+ description: lightweight text search system on Redis
70
70
  email:
71
71
  - platycod0n.ramosa@gmail.com
72
72
  executables: []
@@ -109,5 +109,5 @@ rubyforge_project:
109
109
  rubygems_version: 2.2.2
110
110
  signing_key:
111
111
  specification_version: 4
112
- summary: suggest related words
112
+ summary: lightweight text search system on Redis
113
113
  test_files: []