riddle 0.9.8.1231.0 → 0.9.8.1533.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Riddle::Configuration::Indexer do
4
+ it "should always be valid" do
5
+ indexer = Riddle::Configuration::Indexer.new
6
+ indexer.should be_valid
7
+ end
8
+
9
+ it "should support Sphinx's indexer settings" do
10
+ settings = %w( mem_limit max_iops max_iosize )
11
+ indexer = Riddle::Configuration::Indexer.new
12
+
13
+ settings.each do |setting|
14
+ indexer.should respond_to(setting.to_sym)
15
+ indexer.should respond_to("#{setting}=".to_sym)
16
+ end
17
+ end
18
+
19
+ it "should render a correct configuration" do
20
+ indexer = Riddle::Configuration::Indexer.new
21
+
22
+ indexer.render.should == <<-INDEXER
23
+ indexer
24
+ {
25
+ }
26
+ INDEXER
27
+
28
+ indexer.mem_limit = "32M"
29
+ indexer.render.should == <<-INDEXER
30
+ indexer
31
+ {
32
+ mem_limit = 32M
33
+ }
34
+ INDEXER
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Riddle::Configuration::Searchd do
4
+ it "should be invalid without a port or pid_file" do
5
+ searchd = Riddle::Configuration::Searchd.new
6
+ searchd.should_not be_valid
7
+
8
+ searchd.port = 3312
9
+ searchd.should_not be_valid
10
+
11
+ searchd.pid_file = "file.pid"
12
+ searchd.should be_valid
13
+
14
+ searchd.port = nil
15
+ searchd.should_not be_valid
16
+ end
17
+
18
+ it "should raise a ConfigurationError if rendering but not valid" do
19
+ searchd = Riddle::Configuration::Searchd.new
20
+ searchd.should_not be_valid
21
+ lambda { searchd.render }.should raise_error(Riddle::Configuration::ConfigurationError)
22
+ end
23
+
24
+ it "should support Sphinx's searchd settings" do
25
+ settings = %w( address port log query_log read_timeout max_children
26
+ pid_file max_matches seamless_rotate preopen_indexes unlink_old )
27
+ searchd = Riddle::Configuration::Searchd.new
28
+
29
+ settings.each do |setting|
30
+ searchd.should respond_to(setting.to_sym)
31
+ searchd.should respond_to("#{setting}=".to_sym)
32
+ end
33
+ end
34
+
35
+ it "should render a correct configuration with valid settings" do
36
+ searchd = Riddle::Configuration::Searchd.new
37
+ searchd.port = 3312
38
+ searchd.pid_file = "file.pid"
39
+
40
+ searchd.render.should == <<-SEARCHD
41
+ searchd
42
+ {
43
+ port = 3312
44
+ pid_file = file.pid
45
+ }
46
+ SEARCHD
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Riddle::Configuration::Source do
4
+ #
5
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Riddle::Configuration::SQLSource do
4
+ it "should be invalid without a host, user, database, and query if there's no parent" do
5
+ source = Riddle::Configuration::SQLSource.new("src1", "mysql")
6
+ source.should_not be_valid
7
+
8
+ source.sql_host = "localhost"
9
+ source.sql_user = "test"
10
+ source.sql_db = "test"
11
+ source.sql_query = "SELECT * FROM tables"
12
+ source.should be_valid
13
+
14
+ [:name, :type, :sql_host, :sql_user, :sql_db, :sql_query].each do |setting|
15
+ value = source.send(setting)
16
+ source.send("#{setting}=".to_sym, nil)
17
+ source.should_not be_nil
18
+ source.send("#{setting}=".to_sym, value)
19
+ end
20
+ end
21
+
22
+ it "should be invalid without only a name and type if there is a parent" do
23
+ source = Riddle::Configuration::SQLSource.new("src1", "mysql")
24
+ source.should_not be_valid
25
+
26
+ source.parent = "sqlparent"
27
+ source.should be_valid
28
+
29
+ source.name = nil
30
+ source.should_not be_valid
31
+
32
+ source.name = "src1"
33
+ source.type = nil
34
+ source.should_not be_valid
35
+ end
36
+
37
+ it "should raise a ConfigurationError if rendering when not valid" do
38
+ source = Riddle::Configuration::SQLSource.new("src1", "mysql")
39
+ lambda { source.render }.should raise_error(Riddle::Configuration::ConfigurationError)
40
+ end
41
+
42
+ it "should render correctly when valid" do
43
+ source = Riddle::Configuration::SQLSource.new("src1", "mysql")
44
+ source.sql_host = "localhost"
45
+ source.sql_user = "test"
46
+ source.sql_pass = ""
47
+ source.sql_db = "test"
48
+ source.sql_port = 3306
49
+ source.sql_sock = "/tmp/mysql.sock"
50
+ source.mysql_connect_flags = 32
51
+ source.sql_query_pre << "SET NAMES utf8" << "SET SESSION query_cache_type=OFF"
52
+ source.sql_query = "SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents WHERE id >= $start AND id <= $end"
53
+ source.sql_query_range = "SELECT MIN(id), MAX(id) FROM documents"
54
+ source.sql_range_step = 1000
55
+ source.sql_attr_uint << "author_id" << "forum_id:9" << "group_id"
56
+ source.sql_attr_bool << "is_deleted"
57
+ source.sql_attr_timestamp << "posted_ts" << "last_edited_ts" << "date_added"
58
+ source.sql_attr_str2ordinal << "author_name"
59
+ source.sql_attr_float << "lat_radians" << "long_radians"
60
+ source.sql_attr_multi << "uint tag from query; select id, tag FROM tags"
61
+ source.sql_query_post = ""
62
+ source.sql_query_post_index = "REPLACE INTO counters (id, val) VALUES ('max_indexed_id', $maxid)"
63
+ source.sql_ranged_throttle = 0
64
+ source.sql_query_info = "SELECT * FROM documents WHERE id = $id"
65
+
66
+ source.render.should == <<-SQLSOURCE
67
+ source src1
68
+ {
69
+ type = mysql
70
+ sql_host = localhost
71
+ sql_user = test
72
+ sql_pass =
73
+ sql_db = test
74
+ sql_port = 3306
75
+ sql_sock = /tmp/mysql.sock
76
+ mysql_connect_flags = 32
77
+ sql_query_pre = SET NAMES utf8
78
+ sql_query_pre = SET SESSION query_cache_type=OFF
79
+ sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents WHERE id >= $start AND id <= $end
80
+ sql_query_range = SELECT MIN(id), MAX(id) FROM documents
81
+ sql_range_step = 1000
82
+ sql_attr_uint = author_id
83
+ sql_attr_uint = forum_id:9
84
+ sql_attr_uint = group_id
85
+ sql_attr_bool = is_deleted
86
+ sql_attr_timestamp = posted_ts
87
+ sql_attr_timestamp = last_edited_ts
88
+ sql_attr_timestamp = date_added
89
+ sql_attr_str2ordinal = author_name
90
+ sql_attr_float = lat_radians
91
+ sql_attr_float = long_radians
92
+ sql_attr_multi = uint tag from query; select id, tag FROM tags
93
+ sql_query_post =
94
+ sql_query_post_index = REPLACE INTO counters (id, val) VALUES ('max_indexed_id', $maxid)
95
+ sql_ranged_throttle = 0
96
+ sql_query_info = SELECT * FROM documents WHERE id = $id
97
+ }
98
+ SQLSOURCE
99
+ end
100
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Riddle::Configuration::XMLSource do
4
+ it "should be invalid without an xmlpipe command, name and type if there's no parent" do
5
+ source = Riddle::Configuration::XMLSource.new("xml1", "xmlpipe")
6
+ source.should_not be_valid
7
+
8
+ source.xmlpipe_command = "ls /var/null"
9
+ source.should be_valid
10
+
11
+ source.name = nil
12
+ source.should_not be_valid
13
+
14
+ source.name = "xml1"
15
+ source.type = nil
16
+ source.should_not be_valid
17
+ end
18
+
19
+ it "should be invalid without only a name and type if there is a parent" do
20
+ source = Riddle::Configuration::XMLSource.new("xml1", "xmlpipe")
21
+ source.should_not be_valid
22
+
23
+ source.parent = "xmlparent"
24
+ source.should be_valid
25
+
26
+ source.name = nil
27
+ source.should_not be_valid
28
+
29
+ source.name = "xml1"
30
+ source.type = nil
31
+ source.should_not be_valid
32
+ end
33
+
34
+ it "should raise a ConfigurationError if rendering when not valid" do
35
+ source = Riddle::Configuration::XMLSource.new("xml1", "xmlpipe")
36
+ lambda { source.render }.should raise_error(Riddle::Configuration::ConfigurationError)
37
+ end
38
+
39
+ it "should render correctly when valid" do
40
+ source = Riddle::Configuration::XMLSource.new("xml1", "xmlpipe")
41
+ source.xmlpipe_command = "ls /var/null"
42
+
43
+ source.render.should == <<-XMLSOURCE
44
+ source xml1
45
+ {
46
+ type = xmlpipe
47
+ xmlpipe_command = ls /var/null
48
+ }
49
+ XMLSOURCE
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Riddle::Configuration do
4
+ it "should render all given indexes and sources, plus the indexer and search sections" do
5
+ config = Riddle::Configuration.new
6
+
7
+ config.searchd.port = 3312
8
+ config.searchd.pid_file = "file.pid"
9
+
10
+ source = Riddle::Configuration::XMLSource.new("src1", "xmlpipe")
11
+ source.xmlpipe_command = "ls /dev/null"
12
+
13
+ index = Riddle::Configuration::Index.new("index1")
14
+ index.path = "/path/to/index1"
15
+ index.sources << source
16
+
17
+ config.indexes << index
18
+ generated_conf = config.render
19
+
20
+ generated_conf.should match(/index index1/)
21
+ generated_conf.should match(/source src1/)
22
+ generated_conf.should match(/indexer/)
23
+ generated_conf.should match(/searchd/)
24
+ end
25
+ end
@@ -30,4 +30,9 @@ describe Riddle::Client::Filter do
30
30
  filter = Riddle::Client::Filter.new("field", 5.4..13.5, true)
31
31
  filter.query_message.should == query_contents(:filter_floats_exclude)
32
32
  end
33
+
34
+ it "should render a filter that is an array of boolean values correctly" do
35
+ filter = Riddle::Client::Filter.new("field", [false, true])
36
+ filter.query_message.should == query_contents(:filter_boolean)
37
+ end
33
38
  end
@@ -0,0 +1,17 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe "Riddle" do
4
+ it "should escape characters correctly" do
5
+ invalid_chars = ['(', ')', '|', '-', '!', '@', '~', '"', '/']
6
+ invalid_chars.each do |char|
7
+ base = "string with '#{char}' character"
8
+ Riddle.escape(base).should == base.gsub(char, "\\#{char}")
9
+ end
10
+
11
+ # Not sure why this doesn't work within the loop...
12
+ Riddle.escape("string with & character").should == "string with \\& character"
13
+
14
+ all_chars = invalid_chars.join('') + '&'
15
+ Riddle.escape(all_chars).should == "\\(\\)\\|\\-\\!\\@\\~\\\"\\/\\&"
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.1231.0
4
+ version: 0.9.8.1533.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-29 00:00:00 +11:00
12
+ date: 2009-09-28 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,11 +26,42 @@ files:
26
26
  - lib/riddle/client/message.rb
27
27
  - lib/riddle/client/response.rb
28
28
  - lib/riddle/client.rb
29
+ - lib/riddle/configuration/distributed_index.rb
30
+ - lib/riddle/configuration/index.rb
31
+ - lib/riddle/configuration/indexer.rb
32
+ - lib/riddle/configuration/remote_index.rb
33
+ - lib/riddle/configuration/searchd.rb
34
+ - lib/riddle/configuration/section.rb
35
+ - lib/riddle/configuration/source.rb
36
+ - lib/riddle/configuration/sql_source.rb
37
+ - lib/riddle/configuration/xml_source.rb
38
+ - lib/riddle/configuration.rb
39
+ - lib/riddle/controller.rb
29
40
  - lib/riddle.rb
41
+ - lib/tabtab_definitions.rb
30
42
  - MIT-LICENCE
31
- - README
43
+ - README.textile
44
+ - spec/functional/excerpt_spec.rb
45
+ - spec/functional/keywords_spec.rb
46
+ - spec/functional/search_spec.rb
47
+ - spec/functional/update_spec.rb
48
+ - spec/unit/client_spec.rb
49
+ - spec/unit/configuration/distributed_index_spec.rb
50
+ - spec/unit/configuration/index_spec.rb
51
+ - spec/unit/configuration/indexer_spec.rb
52
+ - spec/unit/configuration/searchd_spec.rb
53
+ - spec/unit/configuration/source_spec.rb
54
+ - spec/unit/configuration/sql_source_spec.rb
55
+ - spec/unit/configuration/xml_source_spec.rb
56
+ - spec/unit/configuration_spec.rb
57
+ - spec/unit/filter_spec.rb
58
+ - spec/unit/message_spec.rb
59
+ - spec/unit/response_spec.rb
60
+ - spec/unit/riddle_spec.rb
32
61
  has_rdoc: true
33
62
  homepage: http://riddle.freelancing-gods.com
63
+ licenses: []
64
+
34
65
  post_install_message:
35
66
  rdoc_options:
36
67
  - --title
@@ -55,9 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
86
  requirements: []
56
87
 
57
88
  rubyforge_project: riddle
58
- rubygems_version: 1.0.1
89
+ rubygems_version: 1.3.5
59
90
  signing_key:
60
- specification_version: 2
91
+ specification_version: 3
61
92
  summary: API for Sphinx, written in and for Ruby.
62
93
  test_files:
63
94
  - spec/functional/excerpt_spec.rb
@@ -65,6 +96,15 @@ test_files:
65
96
  - spec/functional/search_spec.rb
66
97
  - spec/functional/update_spec.rb
67
98
  - spec/unit/client_spec.rb
99
+ - spec/unit/configuration/distributed_index_spec.rb
100
+ - spec/unit/configuration/index_spec.rb
101
+ - spec/unit/configuration/indexer_spec.rb
102
+ - spec/unit/configuration/searchd_spec.rb
103
+ - spec/unit/configuration/source_spec.rb
104
+ - spec/unit/configuration/sql_source_spec.rb
105
+ - spec/unit/configuration/xml_source_spec.rb
106
+ - spec/unit/configuration_spec.rb
68
107
  - spec/unit/filter_spec.rb
69
108
  - spec/unit/message_spec.rb
70
109
  - spec/unit/response_spec.rb
110
+ - spec/unit/riddle_spec.rb
data/README DELETED
@@ -1,74 +0,0 @@
1
- This client has been written to interface with Sphinx[http://sphinxsearch.com/]. It is written by
2
- {Pat Allan}[http://freelancing-gods.com], and has been influenced by both Dmytro Shteflyuk's Ruby
3
- client and the original PHP client - credit where credit's due, after all.
4
-
5
- It does not follow the same syntax as those two, though (not much point writing this otherwise) -
6
- opting for a more Ruby-like structure.
7
-
8
- The easiest way to install is to grab the gem (available since 0.9.8r1112 only):
9
-
10
- sudo gem install riddle
11
-
12
- However, if you're so inclined, you can grab sourcecode via subversion. If you
13
- are after a specific release, use the tag as follows:
14
-
15
- svn co http://rails-oceania.googlecode.com/svn/patallan/riddle/tags/0.9.8-rc2 riddle
16
-
17
- Or for the most current, just use trunk:
18
-
19
- svn co http://rails-oceania.googlecode.com/svn/patallan/riddle/trunk riddle
20
-
21
- Please note that at the time of writing, the following versions are supported (if you get the appropriate tag):
22
-
23
- * 0.9.8-r871
24
- * 0.9.8-r909
25
- * 0.9.8-r985
26
- * 0.9.8-r1065
27
- * 0.9.8-r1112
28
- * 0.9.8-rc1 (gem version: 0.9.8.1198)
29
- * 0.9.8-rc2 (gem version: 0.9.8.1231)
30
-
31
- To get started, just instantiate a Client object:
32
-
33
- client = Riddle::Client.new # defaults to localhost and port 3312
34
- client = Riddle::Client.new "sphinxserver.domain.tld", 3333 # custom settings
35
-
36
- And then set the parameters to what you want, before running a query:
37
-
38
- client.match_mode = :extended
39
- client.query "Pat Allan @state Victoria"
40
-
41
- The results from a query are similar to the other clients - but here's the details. It's a hash with
42
- the following keys:
43
-
44
- * :matches
45
- * :fields
46
- * :attributes
47
- * :attribute_names
48
- * :words
49
- * :total
50
- * :total_found
51
- * :time
52
- * :status
53
- * :warning (if appropriate)
54
- * :error (if appropriate)
55
-
56
- The key <tt>:matches</tt> returns an array of hashes - the actual search results. Each hash has the
57
- document id (<tt>:doc</tt>), the result weighting (<tt>:weight</tt>), and a hash of the attributes for
58
- the document (<tt>:attributes</tt>).
59
-
60
- The <tt>:fields</tt> and <tt>:attribute_names</tt> keys return list of fields and attributes for the
61
- documents. The key <tt>:attributes</tt> will return a hash of attribute name and type pairs, and
62
- <tt>:words</tt> returns a hash of hashes representing the words from the search, with the number of
63
- documents and hits for each, along the lines of:
64
-
65
- results[:words]["Pat"] #=> {:docs => 12, :hits => 15}
66
-
67
- <tt>:total</tt>, <tt>:total_found</tt> and <tt>:time</tt> return the number of matches available, the
68
- total number of matches (which may be greater than the maximum available), and the time in milliseconds
69
- that the query took to run.
70
-
71
- <tt>:status</tt> is the error code for the query - and if there was a related warning, it will be under
72
- the <tt>:warning</tt> key. Fatal errors will be described under <tt>:error</tt>.
73
-
74
- If you've installed the gem and wondering why there's no tests - check out the svn version. I've kept the specs out of the gem as I have a decent amount of test data in there, which really isn't needed unless you want to submit patches.