sphinx 0.9.9.2117 → 0.9.10

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.
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ require ("sphinxapi.php");
4
+
5
+ $cl = new SphinxClient();
6
+ $cl->SetRankingMode(SPH_RANK_SPH04);
7
+ $cl->Query('query');
8
+
9
+ ?>
@@ -1,7 +1,7 @@
1
1
  <?php
2
2
 
3
3
  //
4
- // $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
4
+ // $Id$
5
5
  //
6
6
 
7
7
  //
@@ -18,21 +18,23 @@
18
18
  /////////////////////////////////////////////////////////////////////////////
19
19
 
20
20
  /// known searchd commands
21
- define ( "SEARCHD_COMMAND_SEARCH", 0 );
22
- define ( "SEARCHD_COMMAND_EXCERPT", 1 );
23
- define ( "SEARCHD_COMMAND_UPDATE", 2 );
24
- define ( "SEARCHD_COMMAND_KEYWORDS",3 );
25
- define ( "SEARCHD_COMMAND_PERSIST", 4 );
26
- define ( "SEARCHD_COMMAND_STATUS", 5 );
27
- define ( "SEARCHD_COMMAND_QUERY", 6 );
21
+ define ( "SEARCHD_COMMAND_SEARCH", 0 );
22
+ define ( "SEARCHD_COMMAND_EXCERPT", 1 );
23
+ define ( "SEARCHD_COMMAND_UPDATE", 2 );
24
+ define ( "SEARCHD_COMMAND_KEYWORDS", 3 );
25
+ define ( "SEARCHD_COMMAND_PERSIST", 4 );
26
+ define ( "SEARCHD_COMMAND_STATUS", 5 );
27
+ define ( "SEARCHD_COMMAND_QUERY", 6 );
28
+ define ( "SEARCHD_COMMAND_FLUSHATTRS", 7 );
28
29
 
29
30
  /// current client-side command implementation versions
30
- define ( "VER_COMMAND_SEARCH", 0x116 );
31
+ define ( "VER_COMMAND_SEARCH", 0x117 );
31
32
  define ( "VER_COMMAND_EXCERPT", 0x100 );
32
33
  define ( "VER_COMMAND_UPDATE", 0x102 );
33
34
  define ( "VER_COMMAND_KEYWORDS", 0x100 );
34
35
  define ( "VER_COMMAND_STATUS", 0x100 );
35
36
  define ( "VER_COMMAND_QUERY", 0x100 );
37
+ define ( "VER_COMMAND_FLUSHATTRS", 0x100 );
36
38
 
37
39
  /// known searchd status codes
38
40
  define ( "SEARCHD_OK", 0 );
@@ -57,6 +59,8 @@ define ( "SPH_RANK_WORDCOUNT", 3 ); ///< simple word-count weighting, rank is a
57
59
  define ( "SPH_RANK_PROXIMITY", 4 );
58
60
  define ( "SPH_RANK_MATCHANY", 5 );
59
61
  define ( "SPH_RANK_FIELDMASK", 6 );
62
+ define ( "SPH_RANK_SPH04", 7 );
63
+ define ( "SPH_RANK_TOTAL", 8 );
60
64
 
61
65
  /// known sort modes
62
66
  define ( "SPH_SORT_RELEVANCE", 0 );
@@ -78,6 +82,7 @@ define ( "SPH_ATTR_ORDINAL", 3 );
78
82
  define ( "SPH_ATTR_BOOL", 4 );
79
83
  define ( "SPH_ATTR_FLOAT", 5 );
80
84
  define ( "SPH_ATTR_BIGINT", 6 );
85
+ define ( "SPH_ATTR_STRING", 7 );
81
86
  define ( "SPH_ATTR_MULTI", 0x40000000 );
82
87
 
83
88
  /// known grouping functions
@@ -344,11 +349,6 @@ function sphUnpackI64 ( $v )
344
349
  $mq = floor($m/10000000.0);
345
350
  $l = $m - $mq*10000000.0 + $c;
346
351
  $h = $q*4294967296.0 + $r*429.0 + $mq;
347
- if ( $l==10000000 )
348
- {
349
- $l = 0;
350
- $h += 1;
351
- }
352
352
 
353
353
  $h = sprintf ( "%.0f", $h );
354
354
  $l = sprintf ( "%07.0f", $l );
@@ -358,27 +358,11 @@ function sphUnpackI64 ( $v )
358
358
  }
359
359
 
360
360
 
361
- function sphFixUint ( $value )
362
- {
363
- if ( PHP_INT_SIZE>=8 )
364
- {
365
- // x64 route, workaround broken unpack() in 5.2.2+
366
- if ( $value<0 ) $value += (1<<32);
367
- return $value;
368
- }
369
- else
370
- {
371
- // x32 route, workaround php signed/unsigned braindamage
372
- return sprintf ( "%u", $value );
373
- }
374
- }
375
-
376
-
377
361
  /// sphinx searchd client class
378
362
  class SphinxClient
379
363
  {
380
364
  var $_host; ///< searchd host (default is "localhost")
381
- var $_port; ///< searchd port (default is 9312)
365
+ var $_port; ///< searchd port (default is 3312)
382
366
  var $_offset; ///< how many records to seek from result-set start (default is 0)
383
367
  var $_limit; ///< how many records to return from result-set starting at offset (default is 20)
384
368
  var $_mode; ///< query matching mode (default is SPH_MATCH_ALL)
@@ -422,7 +406,7 @@ class SphinxClient
422
406
  {
423
407
  // per-client-object settings
424
408
  $this->_host = "localhost";
425
- $this->_port = 9312;
409
+ $this->_port = 3312;
426
410
  $this->_path = false;
427
411
  $this->_socket = false;
428
412
 
@@ -555,16 +539,8 @@ class SphinxClient
555
539
 
556
540
  function _OldConnect ()
557
541
  {
558
- if ( $this->_socket!==false )
559
- {
560
- // we are in persistent connection mode, so we have a socket
561
- // however, need to check whether it's still alive
562
- if ( !@feof ( $this->_socket ) )
563
- return $this->_socket;
564
-
565
- // force reopen
566
- $this->_socket = false;
567
- }
542
+ if ( $this->_socket !== false )
543
+ return $this->_socket;
568
544
 
569
545
  $errno = 0;
570
546
  $errstr = "";
@@ -736,13 +712,7 @@ class SphinxClient
736
712
  /// set ranking mode
737
713
  function SetRankingMode ( $ranker )
738
714
  {
739
- assert ( $ranker==SPH_RANK_PROXIMITY_BM25
740
- || $ranker==SPH_RANK_BM25
741
- || $ranker==SPH_RANK_NONE
742
- || $ranker==SPH_RANK_WORDCOUNT
743
- || $ranker==SPH_RANK_PROXIMITY
744
- || $ranker==SPH_RANK_MATCHANY
745
- || $ranker==SPH_RANK_FIELDMASK );
715
+ assert ( $ranker>=0 && $ranker<SPH_RANK_TOTAL );
746
716
  $this->_ranker = $ranker;
747
717
  }
748
718
 
@@ -1207,7 +1177,16 @@ class SphinxClient
1207
1177
  list ( $doc, $weight ) = array_values ( unpack ( "N*N*",
1208
1178
  substr ( $response, $p, 8 ) ) );
1209
1179
  $p += 8;
1210
- $doc = sphFixUint($doc);
1180
+
1181
+ if ( PHP_INT_SIZE>=8 )
1182
+ {
1183
+ // x64 route, workaround broken unpack() in 5.2.2+
1184
+ if ( $doc<0 ) $doc += (1<<32);
1185
+ } else
1186
+ {
1187
+ // x32 route, workaround php signed/unsigned braindamage
1188
+ $doc = sprintf ( "%u", $doc );
1189
+ }
1211
1190
  }
1212
1191
  $weight = sprintf ( "%u", $weight );
1213
1192
 
@@ -1246,11 +1225,15 @@ class SphinxClient
1246
1225
  while ( $nvalues-->0 && $p<$max )
1247
1226
  {
1248
1227
  list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4;
1249
- $attrvals[$attr][] = sphFixUint($val);
1228
+ $attrvals[$attr][] = sprintf ( "%u", $val );
1250
1229
  }
1230
+ } else if ( $type==SPH_ATTR_STRING )
1231
+ {
1232
+ $attrvals[$attr] = substr ( $response, $p, $val );
1233
+ $p += $val;
1251
1234
  } else
1252
1235
  {
1253
- $attrvals[$attr] = sphFixUint($val);
1236
+ $attrvals[$attr] = sprintf ( "%u", $val );
1254
1237
  }
1255
1238
  }
1256
1239
 
@@ -1317,6 +1300,7 @@ class SphinxClient
1317
1300
  if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false;
1318
1301
  if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false;
1319
1302
  if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false;
1303
+ if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false;
1320
1304
 
1321
1305
  /////////////////
1322
1306
  // build request
@@ -1328,6 +1312,7 @@ class SphinxClient
1328
1312
  if ( $opts["single_passage"] ) $flags |= 4;
1329
1313
  if ( $opts["use_boundaries"] ) $flags |= 8;
1330
1314
  if ( $opts["weight_order"] ) $flags |= 16;
1315
+ if ( $opts["query_mode"] ) $flags |= 32;
1331
1316
  $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags
1332
1317
  $req .= pack ( "N", strlen($index) ) . $index; // req index
1333
1318
  $req .= pack ( "N", strlen($words) ) . $words; // req words
@@ -1626,8 +1611,38 @@ class SphinxClient
1626
1611
  $this->_MBPop ();
1627
1612
  return $res;
1628
1613
  }
1614
+
1615
+ //////////////////////////////////////////////////////////////////////////
1616
+ // flush
1617
+ //////////////////////////////////////////////////////////////////////////
1618
+
1619
+ function FlushAttrs ()
1620
+ {
1621
+ $this->_MBPush ();
1622
+ if (!( $fp = $this->_Connect() ))
1623
+ {
1624
+ $this->_MBPop();
1625
+ return false;
1626
+ }
1627
+
1628
+ $req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0
1629
+ if ( !( $this->_Send ( $fp, $req, 8 ) ) ||
1630
+ !( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) )
1631
+ {
1632
+ $this->_MBPop ();
1633
+ return false;
1634
+ }
1635
+
1636
+ $tag = -1;
1637
+ if ( strlen($response)==4 )
1638
+ list(,$tag) = unpack ( "N*", $response );
1639
+
1640
+ $this->_MBPop ();
1641
+ return $tag;
1642
+ }
1643
+
1629
1644
  }
1630
1645
 
1631
1646
  //
1632
- // $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
1633
- //
1647
+ // $Id$
1648
+ //
@@ -57,7 +57,7 @@ indexer
57
57
 
58
58
  searchd
59
59
  {
60
- port = 9312
60
+ port = 3312
61
61
  log = /opt/sphinx-0.9.9-id64/var/log/searchd.log
62
62
  query_log = /opt/sphinx-0.9.9-id64/var/log/query.log
63
63
  read_timeout = 5
@@ -57,7 +57,7 @@ indexer
57
57
 
58
58
  searchd
59
59
  {
60
- port = 9312
60
+ port = 3312
61
61
  log = /opt/sphinx-0.9.9/var/log/searchd.log
62
62
  query_log = /opt/sphinx-0.9.9/var/log/query.log
63
63
  read_timeout = 5
@@ -3,15 +3,13 @@ SQLyog Enterprise - MySQL GUI v5.20
3
3
  Host - 5.0.27-community-nt : Database - sphinx_test
4
4
  *********************************************************************
5
5
  Server version : 5.0.27-community-nt
6
- */
7
-
6
+ */
8
7
 
9
8
  SET NAMES utf8;
10
9
 
11
10
  SET SQL_MODE='';
12
11
 
13
- DROP database `sphinx_test`;
14
- CREATE database `sphinx_test`;
12
+ CREATE database IF NOT EXISTS `sphinx_test`;
15
13
 
16
14
  USE `sphinx_test`;
17
15
 
data/sphinx.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sphinx}
8
- s.version = "0.9.9.2117"
8
+ s.version = "0.9.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dmytro Shteflyuk"]
12
- s.date = %q{2009-12-04}
12
+ s.date = %q{2009-11-04}
13
13
  s.description = %q{An easy interface to Sphinx standalone full-text search engine. It is implemented as plugin for Ruby on Rails, but can be easily used as standalone library.}
14
14
  s.email = %q{kpumuk@kpumuk.info}
15
15
  s.extra_rdoc_files = [
@@ -21,18 +21,13 @@ Gem::Specification.new do |s|
21
21
  "Rakefile",
22
22
  "VERSION.yml",
23
23
  "init.rb",
24
+ "install.rb",
24
25
  "lib/sphinx.rb",
25
- "lib/sphinx/buffered_io.rb",
26
26
  "lib/sphinx/client.rb",
27
- "lib/sphinx/constants.rb",
28
- "lib/sphinx/indifferent_access.rb",
29
27
  "lib/sphinx/request.rb",
30
28
  "lib/sphinx/response.rb",
31
- "lib/sphinx/server.rb",
32
- "lib/sphinx/timeout.rb",
33
29
  "spec/client_response_spec.rb",
34
30
  "spec/client_spec.rb",
35
- "spec/client_validations_spec.rb",
36
31
  "spec/fixtures/default_search.php",
37
32
  "spec/fixtures/default_search_index.php",
38
33
  "spec/fixtures/excerpt_custom.php",
@@ -81,6 +76,7 @@ Gem::Specification.new do |s|
81
76
  "spec/fixtures/ranking_none.php",
82
77
  "spec/fixtures/ranking_proximity.php",
83
78
  "spec/fixtures/ranking_proximity_bm25.php",
79
+ "spec/fixtures/ranking_sph04.php",
84
80
  "spec/fixtures/ranking_wordcount.php",
85
81
  "spec/fixtures/retries.php",
86
82
  "spec/fixtures/retries_delay.php",
@@ -96,11 +92,12 @@ Gem::Specification.new do |s|
96
92
  "spec/fixtures/update_attributes.php",
97
93
  "spec/fixtures/update_attributes_mva.php",
98
94
  "spec/fixtures/weights.php",
99
- "spec/spec_helper.rb",
100
95
  "spec/sphinx/sphinx-id64.conf",
101
96
  "spec/sphinx/sphinx.conf",
102
97
  "spec/sphinx/sphinx_test.sql",
103
- "sphinx.gemspec"
98
+ "sphinx.gemspec",
99
+ "sphinx.yml.tpl",
100
+ "tasks/sphinx.rake"
104
101
  ]
105
102
  s.homepage = %q{http://github.com/kpumuk/sphinx}
106
103
  s.rdoc_options = ["--charset=UTF-8"]
@@ -109,9 +106,7 @@ Gem::Specification.new do |s|
109
106
  s.summary = %q{Sphinx Client API for Ruby}
110
107
  s.test_files = [
111
108
  "spec/client_response_spec.rb",
112
- "spec/client_spec.rb",
113
- "spec/client_validations_spec.rb",
114
- "spec/spec_helper.rb"
109
+ "spec/client_spec.rb"
115
110
  ]
116
111
 
117
112
  if s.respond_to? :specification_version then
data/sphinx.yml.tpl ADDED
@@ -0,0 +1,3 @@
1
+ config_file: /opt/sphinx/etc/sphinx.conf
2
+ root_dir: /opt/sphinx/bin
3
+ indexes: test1 test2
data/tasks/sphinx.rake ADDED
@@ -0,0 +1,75 @@
1
+ namespace :sphinx do
2
+ desc 'Run indexer for configured indexes'
3
+ task :index do
4
+ config = load_config
5
+ if config[:indexes]
6
+ system "#{config[:root_dir]}/indexer --config \"#{config[:config_file]}\" #{config[:indexes]}"
7
+ else
8
+ puts 'You should specify indexes in sphinx.yml'
9
+ end
10
+ end
11
+
12
+ desc 'Run indexer for all indexes'
13
+ task :index_all do
14
+ config = load_config
15
+ system "#{config[:root_dir]}/indexer --config \"#{config[:config_file]}\" --all"
16
+ end
17
+
18
+ desc 'Rotate configured indexes and restart searchd server'
19
+ task :rotate do
20
+ config = load_config
21
+ if config[:indexes]
22
+ system "#{config[:root_dir]}/indexer --config \"#{config[:config_file]}\" --rotate #{config[:indexes]}"
23
+ else
24
+ puts 'You should specify indexes in sphinx.yml'
25
+ end
26
+ end
27
+
28
+ desc 'Rotate all indexes and restart searchd server'
29
+ task :rotate_all do
30
+ config = load_config
31
+ system "#{config[:root_dir]}/indexer --config \"#{config[:config_file]}\" --rotate --all"
32
+ end
33
+
34
+ desc 'Start searchd server'
35
+ task :start do
36
+ config = load_config
37
+ if File.exists?(config[:pid_file])
38
+ puts 'Sphinx searchd server is already started.'
39
+ else
40
+ system "#{config[:root_dir]}/searchd --config \"#{config[:config_file]}\""
41
+ puts 'Sphinx searchd server started.'
42
+ end
43
+ end
44
+
45
+ desc 'Stop searchd server'
46
+ task :stop do
47
+ config = load_config
48
+ unless File.exists?(config[:pid_file])
49
+ puts 'Sphinx searchd server is not running.'
50
+ else
51
+ pid = File.read(config[:pid_file]).chomp
52
+ kill 'SIGHUP', pid
53
+ puts 'Sphinx searchd server stopped.'
54
+ end
55
+ end
56
+
57
+ desc 'Restart searchd server'
58
+ task :restart => [:stop, :start]
59
+
60
+ def load_config
61
+ return @sphinx_config if @sphinx_config
62
+
63
+ options = YAML.load_file(File.dirname(__FILE__) + '/../../../../config/sphinx.yml') rescue {}
64
+ @sphinx_config = {
65
+ :config_file => options['config_file'] || '/etc/sphinx.conf',
66
+ :root_dir => options['root_dir'] || '/usr/bin',
67
+ :indexes => options['indexes']
68
+ }
69
+ sphinx_config = File.read(@sphinx_config[:config_file]) rescue ''
70
+
71
+ sphinx_config =~ /searchd\s*{.*pid_file\s*=\s*(.*?)\n.*}/m
72
+ @sphinx_config[:pid_file] = $1 || '/var/run/searchd.pid'
73
+ return @sphinx_config
74
+ end
75
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9.2117
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Shteflyuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-04 00:00:00 +02:00
12
+ date: 2009-11-04 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,18 +27,13 @@ files:
27
27
  - Rakefile
28
28
  - VERSION.yml
29
29
  - init.rb
30
+ - install.rb
30
31
  - lib/sphinx.rb
31
- - lib/sphinx/buffered_io.rb
32
32
  - lib/sphinx/client.rb
33
- - lib/sphinx/constants.rb
34
- - lib/sphinx/indifferent_access.rb
35
33
  - lib/sphinx/request.rb
36
34
  - lib/sphinx/response.rb
37
- - lib/sphinx/server.rb
38
- - lib/sphinx/timeout.rb
39
35
  - spec/client_response_spec.rb
40
36
  - spec/client_spec.rb
41
- - spec/client_validations_spec.rb
42
37
  - spec/fixtures/default_search.php
43
38
  - spec/fixtures/default_search_index.php
44
39
  - spec/fixtures/excerpt_custom.php
@@ -87,6 +82,7 @@ files:
87
82
  - spec/fixtures/ranking_none.php
88
83
  - spec/fixtures/ranking_proximity.php
89
84
  - spec/fixtures/ranking_proximity_bm25.php
85
+ - spec/fixtures/ranking_sph04.php
90
86
  - spec/fixtures/ranking_wordcount.php
91
87
  - spec/fixtures/retries.php
92
88
  - spec/fixtures/retries_delay.php
@@ -102,11 +98,12 @@ files:
102
98
  - spec/fixtures/update_attributes.php
103
99
  - spec/fixtures/update_attributes_mva.php
104
100
  - spec/fixtures/weights.php
105
- - spec/spec_helper.rb
106
101
  - spec/sphinx/sphinx-id64.conf
107
102
  - spec/sphinx/sphinx.conf
108
103
  - spec/sphinx/sphinx_test.sql
109
104
  - sphinx.gemspec
105
+ - sphinx.yml.tpl
106
+ - tasks/sphinx.rake
110
107
  has_rdoc: true
111
108
  homepage: http://github.com/kpumuk/sphinx
112
109
  licenses: []
@@ -138,5 +135,3 @@ summary: Sphinx Client API for Ruby
138
135
  test_files:
139
136
  - spec/client_response_spec.rb
140
137
  - spec/client_spec.rb
141
- - spec/client_validations_spec.rb
142
- - spec/spec_helper.rb
@@ -1,26 +0,0 @@
1
- # A simple wrapper around <tt>Net::BufferedIO</tt> performing
2
- # non-blocking select.
3
- #
4
- # @private
5
- class Sphinx::BufferedIO < Net::BufferedIO # :nodoc:
6
- BUFSIZE = 1024 * 16
7
-
8
- if RUBY_VERSION < '1.9.1'
9
- def rbuf_fill
10
- begin
11
- @rbuf << @io.read_nonblock(BUFSIZE)
12
- rescue Errno::EWOULDBLOCK
13
- retry unless @read_timeout
14
- if IO.select([@io], nil, nil, @read_timeout)
15
- retry
16
- else
17
- raise Timeout::Error, 'IO timeout'
18
- end
19
- end
20
- end
21
- end
22
-
23
- def setsockopt(*args)
24
- @io.setsockopt(*args)
25
- end
26
- end