picky-client 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +24 -0
- data/lib/picky-client.rb +10 -0
- data/lib/{search → picky-client}/convenience.rb +1 -1
- data/lib/{search → picky-client}/engine.rb +8 -7
- data/lib/{search → picky-client}/serializer.rb +1 -1
- data/spec/{search → picky-client}/convenience_spec.rb +2 -2
- data/spec/{search → picky-client}/engine_spec.rb +11 -11
- data/spec/{search → picky-client}/serializer_spec.rb +4 -4
- metadata +15 -15
- data/README.textile +0 -3
- data/lib/search-engine.rb +0 -10
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= Picky Client
|
2
|
+
|
3
|
+
== Usage
|
4
|
+
|
5
|
+
1. Define a client instance, and save it (as an example) in a constant:
|
6
|
+
|
7
|
+
<tt>FullSearch = Picky::Client::Full.new :host => 'some_host', :port => 1234, :path => '/path/to/search'</tt>
|
8
|
+
|
9
|
+
2. Use it in your controllers to search:
|
10
|
+
|
11
|
+
<tt>result = FullSearch.search :query => 'some query', :offset => 123 # This gets you a hash</tt>
|
12
|
+
|
13
|
+
3. Then, to make access easier (if needed):
|
14
|
+
|
15
|
+
<tt>result.extend Picky::Convenience</tt>
|
16
|
+
|
17
|
+
4. This gets you the following methods on result:
|
18
|
+
|
19
|
+
* <tt>empty?</tt>
|
20
|
+
* <tt>ids(limit=20)</tt>
|
21
|
+
* <tt>clear_ids</tt>
|
22
|
+
* <tt>allocations</tt>
|
23
|
+
* <tt>allocations_size</tt>
|
24
|
+
* <tt>total</tt>
|
data/lib/picky-client.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$KCODE = 'UTF-8' unless RUBY_VERSION > '1.8.7'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
this = File.dirname __FILE__
|
8
|
+
require File.join(this, '/picky-client/engine')
|
9
|
+
require File.join(this, '/picky-client/serializer')
|
10
|
+
require File.join(this, '/picky-client/convenience')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Picky
|
4
4
|
# Frontend for the search client.
|
5
5
|
#
|
6
6
|
# Configure a search by passing the options in the initializer:
|
@@ -11,7 +11,7 @@ module Search
|
|
11
11
|
# TODO Rewrite such that instead of an http request we connect through tcp.
|
12
12
|
# Or use EventMachine.
|
13
13
|
#
|
14
|
-
module
|
14
|
+
module Client
|
15
15
|
|
16
16
|
class Base
|
17
17
|
|
@@ -41,23 +41,23 @@ module Search
|
|
41
41
|
options
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Merges the given params, overriding the defaults.
|
46
46
|
#
|
47
47
|
def defaultize params = {}
|
48
48
|
default_params.merge params
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
# Searches the index. Use this method.
|
52
52
|
#
|
53
53
|
# Returns a hash. Extend with Convenience.
|
54
54
|
#
|
55
55
|
def search params = {}
|
56
|
-
return {}
|
57
|
-
|
56
|
+
return {} unless params[:query] && !params[:query].empty?
|
57
|
+
|
58
58
|
send_search params
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# Sends a search to the configured address.
|
62
62
|
#
|
63
63
|
def send_search params = {}
|
@@ -87,6 +87,7 @@ end
|
|
87
87
|
|
88
88
|
# Extend hash with to_query method.
|
89
89
|
#
|
90
|
+
require 'active_support/core_ext/object/to_query'
|
90
91
|
class Hash
|
91
92
|
def to_query namespace = nil
|
92
93
|
collect do |key, value|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Picky::Convenience do
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
@convenience = {
|
@@ -10,7 +10,7 @@ describe Search::Convenience do
|
|
10
10
|
:offset => 123,
|
11
11
|
:total => 12345,
|
12
12
|
:duration => 0.12345
|
13
|
-
}.extend
|
13
|
+
}.extend Picky::Convenience
|
14
14
|
end
|
15
15
|
|
16
16
|
# describe 'replace_ids_with' do
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Picky::Client do
|
4
4
|
|
5
5
|
describe 'defaultize' do
|
6
6
|
context 'no default params' do
|
7
7
|
before(:each) do
|
8
|
-
@base =
|
8
|
+
@base = Picky::Client::Base.new
|
9
9
|
end
|
10
10
|
it 'should return unchanged' do
|
11
11
|
@base.defaultize( :a => :b ).should == { :a => :b }
|
@@ -13,11 +13,11 @@ describe Search::Engine do
|
|
13
13
|
end
|
14
14
|
context 'default params' do
|
15
15
|
before(:each) do
|
16
|
-
|
17
|
-
@base =
|
16
|
+
Picky::Client::Base.default_params 'c' => 'd'
|
17
|
+
@base = Picky::Client::Base.new
|
18
18
|
end
|
19
19
|
after(:each) do
|
20
|
-
|
20
|
+
Picky::Client::Base.default_params
|
21
21
|
end
|
22
22
|
it 'should return changed' do
|
23
23
|
@base.defaultize( 'a' => 'b' ).should == { 'a' => 'b', 'c' => 'd' }
|
@@ -30,7 +30,7 @@ describe Search::Engine do
|
|
30
30
|
|
31
31
|
describe 'Base' do
|
32
32
|
before(:each) do
|
33
|
-
@base =
|
33
|
+
@base = Picky::Client::Base.new
|
34
34
|
end
|
35
35
|
it 'should have a default_configuration method' do
|
36
36
|
lambda { @base.default_configuration }.should_not raise_error
|
@@ -48,7 +48,7 @@ describe Search::Engine do
|
|
48
48
|
|
49
49
|
describe "Full" do
|
50
50
|
before(:each) do
|
51
|
-
@full =
|
51
|
+
@full = Picky::Client::Full.new
|
52
52
|
end
|
53
53
|
describe "defaults" do
|
54
54
|
it "should set host to 'localhost'" do
|
@@ -64,7 +64,7 @@ describe Search::Engine do
|
|
64
64
|
|
65
65
|
describe "cattr_accessors" do
|
66
66
|
before(:each) do
|
67
|
-
@full =
|
67
|
+
@full = Picky::Client::Full.new :host => :some_host, :port => :some_port, :path => :some_path
|
68
68
|
end
|
69
69
|
it "should have a writer for the host" do
|
70
70
|
@full.host = :some_host
|
@@ -94,7 +94,7 @@ describe Search::Engine do
|
|
94
94
|
before(:each) do
|
95
95
|
@query = nil
|
96
96
|
end
|
97
|
-
it "should return a Search::Results for
|
97
|
+
it "should return a Search::Results for bla" do
|
98
98
|
@full.search(:query => @query).should be_kind_of(Hash)
|
99
99
|
end
|
100
100
|
it "should return an empty Search::Results" do
|
@@ -105,7 +105,7 @@ describe Search::Engine do
|
|
105
105
|
before(:each) do
|
106
106
|
@query = ''
|
107
107
|
end
|
108
|
-
it "should return a Search::Results
|
108
|
+
it "should return a Search::Results" do
|
109
109
|
@full.search(:query => @query).should be_kind_of(Hash)
|
110
110
|
end
|
111
111
|
it "should return an empty Search::Results" do
|
@@ -117,7 +117,7 @@ describe Search::Engine do
|
|
117
117
|
|
118
118
|
describe "Live" do
|
119
119
|
before(:each) do
|
120
|
-
@live =
|
120
|
+
@live = Picky::Client::Live.new
|
121
121
|
end
|
122
122
|
describe "defaults" do
|
123
123
|
it "should set host to 'localhost'" do
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Picky::Serializer do
|
4
4
|
|
5
5
|
describe "serialize-deserialize" do
|
6
6
|
it "should serialize and deserialize certain values" do
|
7
7
|
results = stub :results
|
8
8
|
results.stub! :serialize => {}
|
9
9
|
|
10
|
-
deserialized =
|
10
|
+
deserialized = Picky::Serializer.deserialize Picky::Serializer.serialize(results)
|
11
11
|
|
12
12
|
deserialized.should == {}
|
13
13
|
end
|
@@ -24,13 +24,13 @@ describe Search::Serializer do
|
|
24
24
|
:duration => 0.12345
|
25
25
|
}
|
26
26
|
|
27
|
-
|
27
|
+
Picky::Serializer.serialize(results).should == "\x04\b{\t:\x10allocations[\b[\t000[\ri\x06i\ai\bi\ti\ni\vi\fi\r[\t000[\ri\x0Ei\x0Fi\x10i\x11i\x12i\x13i\x14i\x15[\t000[\fi\x16i\x17i\x18i\x19i\x1Ai\ei\x1C:\voffseti\x01{:\ntotali\x0290:\rdurationf\x0F0.12345\x00\xF2|"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "deserialize" do
|
32
32
|
it "should deserialize" do
|
33
|
-
results =
|
33
|
+
results = Picky::Serializer.deserialize "\x04\b{\t:\x10allocations[\b[\t000[\ri\x06i\ai\bi\ti\ni\vi\fi\r[\t000[\ri\x0Ei\x0Fi\x10i\x11i\x12i\x13i\x14i\x15[\t000[\fi\x16i\x17i\x18i\x19i\x1Ai\ei\x1C:\voffseti\x01{:\ntotali\x0290:\rdurationf\x0F0.12345\x00\xF2|"
|
34
34
|
|
35
35
|
results.should be_kind_of(Hash)
|
36
36
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-29 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -25,16 +25,16 @@ executables: []
|
|
25
25
|
extensions: []
|
26
26
|
|
27
27
|
extra_rdoc_files:
|
28
|
-
- README.
|
28
|
+
- README.rdoc
|
29
29
|
files:
|
30
|
-
- lib/
|
31
|
-
- lib/
|
32
|
-
- lib/
|
33
|
-
- lib/
|
34
|
-
- spec/
|
35
|
-
- spec/
|
36
|
-
- spec/
|
37
|
-
- README.
|
30
|
+
- lib/picky-client/convenience.rb
|
31
|
+
- lib/picky-client/engine.rb
|
32
|
+
- lib/picky-client/serializer.rb
|
33
|
+
- lib/picky-client.rb
|
34
|
+
- spec/picky-client/convenience_spec.rb
|
35
|
+
- spec/picky-client/engine_spec.rb
|
36
|
+
- spec/picky-client/serializer_spec.rb
|
37
|
+
- README.rdoc
|
38
38
|
has_rdoc: true
|
39
39
|
homepage: http://floere.github.com/picky
|
40
40
|
licenses: []
|
@@ -68,6 +68,6 @@ signing_key:
|
|
68
68
|
specification_version: 3
|
69
69
|
summary: picky Search Engine Client
|
70
70
|
test_files:
|
71
|
-
- spec/
|
72
|
-
- spec/
|
73
|
-
- spec/
|
71
|
+
- spec/picky-client/convenience_spec.rb
|
72
|
+
- spec/picky-client/engine_spec.rb
|
73
|
+
- spec/picky-client/serializer_spec.rb
|
data/README.textile
DELETED
data/lib/search-engine.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
$KCODE = 'UTF-8' unless RUBY_VERSION > '1.8.7'
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
|
-
require 'active_support'
|
6
|
-
|
7
|
-
this = File.dirname __FILE__
|
8
|
-
require File.join(this, '/search/engine')
|
9
|
-
require File.join(this, '/search/serializer')
|
10
|
-
require File.join(this, '/search/convenience')
|