Sphinx Client API for Ruby

Apr 05
2007 11:39 · Русский (10,418 views)

The Sphinx Client API is used to communicate with searchd daemon and get search results from Sphinx. It is used in large applications with a lot of data to provide fast, reliable search engine. Ruby API is a port of PHP API, which could be found inside your Sphinx distributive. Below you could find information on how to install and use it.

Warning: If you used this plugin before version 0.3.0 released, check the documentation, because I have fixed any differences between PHP and this API implementation, and all functions has been renamed.

Installation

Sphinx Client API for Ruby has been implemented as plugin for Ruby on Rails (but you able to use it in standalone Ruby application as well, there are no dependencies on other libraries). All you need is to download plugin sources and unpack them to the vendor/plugins/sphinx directory.

Documentation

You can find documentation here. Also you can build the documentation by running following command inside the vendor/plugins/sphinx directory:

rake rdoc

Here is short example:

@sphinx = Sphinx::Client.new
@sphinx.SetSortMode(Sphinx::Client::SPH_SORT_ATTR_ASC, 'created_at')
results = @sphinx.Query('test')

puts "Searched for:"
results['words'].each do |word, info|
  puts "    #{word} found #{info['hits']} times in #{info['docs']} documents"
end
print "\nResults #{results['total']} of #{results['total_found']}; "
puts "Total time: #{results['time']}"
results['matches'].each do |doc|
  puts "Document ##{doc['id']} (weight #{doc['weight']}):"
  doc['attrs'].each do |attr, value|
    puts "    #{attr}: #{value}"
  end
end

Download

The latest version of “Sphinx Client API” is 0.3.1, and it can be downloaded here:

version0.3.1DownloadSphinx Client API

Also you can download client library for current Sphinx 0.9.8 r1112 development snapshot here: Sphinx Client API v0.4.0-r1112. WARNING, this is a current development snapshot rather than tested and approved release. Even though it is already used in production at some sites, it still has some known issues, and might have showstopper ones, too. Please use with care and do report any issues you might run into.

If you have any proposals, want to send feedback or found bugs, please post comments. It’s very important for me!

Changelog

  • v0.3.1 (Dec 9, 2007)
    • Fixed bug with search results sorting order.
  • v0.3.0 (Apr 3, 2007)
    • Fixed bug with processing attributes in query response (thanks to shawn).
    • Fixed bug query processing time round-up (thanks to michael).
    • API updated in compliance with PHP API for Sphinx 0.9.7.
    • RSpec tests added
  • v0.2.0 (Dec 20, 2006)
    • Imporved exceptions handling.
    • API updated in compliance with PHP API for Sphinx 0.9.7 RC2.
  • v0.1.0 (Nov 26, 2006)
    • Initial plugin implementation.

Other plugins

Full list of plugins I have implemented is available here.

4 Responses to 'Sphinx Client API for Ruby'

Subscribe to comments with RSS or TrackBack to 'Sphinx Client API for Ruby'.

1
Quang
said on 2007-06-18 at 7.08 am

Hi, I have a huge data in MySQl. Before I found Sphinx, I intend to build my old indexes and then build a tag cloud base on those indexes.
Now I wonder, can Sphinx and Client API help me in building tag cloud base on Sphinx indexes ?

2
Quang
said on 2007-06-18 at 7.10 am

Sorry, in the previous comment. I mean “my own indexes”, not “my old indexes”.
My English is not good :D !

3
said on 2007-08-14 at 6.27 pm

[...] - Rails wrapper for Ruby API for Sphinx, a full-text search [...]

4
said on 2007-12-09 at 9.33 pm

[...] I have a good news: Sphinx Client API has been updated and now it supports all brand new features of the unstable Sphinx 0.9.8 development snapshot. What does it mean for you as a developer? What features you will get if you would decide to switch to the new version? I will describe most valuable improvements of the Sphinx in this article, and will show how to use them with new Sphinx Client API 0.4.0 r909. [...]

Post a comment

You can use simple HTML-formatting tags (like <a>, <ul> and others). To format your code sample use <code lang="php">$a = "hello";</code> (allowed languages are ruby, php, yaml, html, csharp, javascript). Also you could use <code>$a = "hello";</code> and its syntax would not be highlighted. If you are not using <code> tag, replace < sign with &lt;.

Submit Comment

 
Copyright © 2005 - 2008, Dmytro Shteflyuk