Sphinx 0.9.7-RC2 released, Ruby API updated

Posted by Dmytro Shteflyuk on under Ruby & Rails

Today I found that Sphinx search engine has been updated. Major new features include:

  • extended query mode with boolean, field limits, phrases, and proximity support (eg.: @title "hello world"~10 | @body example program);
  • extended sorting mode (eg.: @weight DESC @id ASC);
  • combined phrase+statistical ranking which takes words frequencies into account (currently in extended mode only);
  • official Python API;
  • contributed Perl and Ruby APIs.

I have updated Sphinx Client Library along with Sphinx 0.9.7-RC2 Windows build.

Using Sphinx search engine in Ruby on Rails

Posted by Dmytro Shteflyuk on under Ruby & Rails

Almost all Web-applications needs data search logic and really often this logic should have full-text search capabilities. If you are using MySQL database, you can use its FULLTEXT search, but it’s not efficient when you have a large amout of data. In this case third party search engines used, and one of them (and I think, the most efficient) is Sphinx. In this article I’ll present my port of Sphinx client library for Ruby and show how to use it.

Read the rest of entry »

Ruby on Rails related cheat sheets

Posted by Dmytro Shteflyuk on under Ruby & Rails

There are couple of cheat sheets about Ruby on Rails and related technologies can be found in the web. I decided to collect all of them (almost all) in one post just to keep them in mind. All of them are in full color PDFs or PNGs.

Read the rest of entry »

In-place file upload with Ruby on Rails

Posted by Dmytro Shteflyuk on under Ruby & Rails

My friends often asked me how to upload file using AJAX, and usually they got answer “in no way”. Correct answer, but what if I need to upload file without full page reloading? And, of course, I want to use RJS in this case. Here I’ll explain what to do to get effect very similar to AJAX file upload (btw, Gmail uses this technique).

Read the rest of entry »

Flexible application configuration in Ruby on Rails

Posted by Dmytro Shteflyuk on under Ruby & Rails

In my current project based on Ruby on Rails framework, I need to store application specific configuration somehow. There are several approaches I’ve found in Internet: AppConfig plugin, several methods described on the HowtoAddYourOwnConfigInfo wiki page, but neither one looks “config-like”. Me with my friend, Alexey Kovyrin, discovered all of them and decided to use YAML-file as a configuration format. In my opinion, the ideal configuration file looks like this:

1
2
3
4
5
6
7
8
9
10
11
common:
  support_email
: [email protected]
  root_url
: myhost.com
  photos_max_number
: 6

production
:
  email_exceptions
: true

development
:
  root_url
: localhost:3000
  photos_max_number
: 10

In this example you can see three sections: common will be used as a base configuration for all environments, production and development — environment specific options. Optional sections are production, development, and testing, or any other custom environment name. I’ve placed this file in config/config.yml and created lib/app_config.rb which looks like this:

1
2
3
4
5
6
7
8
# Load application configuration
require 'ostruct'
require 'yaml'
 
config = YAML.load_file("#{Rails.root}/config/config.yml") || {}
app_config = config['common'] || {}
app_config.update(config[Rails.env] || {})
AppConfig = OpenStruct.new(app_config)

Now I’m able to use constructions like AppConfig.support_email and AppConfig.root_url. Looks like I’ve kept all my configs as DRY as possible :-)