Project

zinx

0.0
No commit activity in last 3 years
No release in over 3 years
Simple DSL for Sphinx Search Server
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Zinx

Zinx is a Ruby DSL for the Sphinx Search Engine (which is used in a lot of big sites). It is a simple wrapper around the oficial Ruby API. The main goal is to have a more friendly way of searching Sphinx.

Most methods are just a wrap around the corresponding Sphinx API method. Best thing to do is to read the code, it's quite simple.


Install

gem install zinx

Examples

Configuring

match_mode :extended
ranking_mode :word_count
field_weight 'field1', 1000
field_weights {'field1' => 1000, 'field2' => 50}
index_weight 'index1', 400
index_weights {'index2' => 100, 'index3' => 231}

Simple Search

results = search 'simple'

Filtering

results = search 'simple', :filter => {'field' => 'value'}
# or
results = search 'simple' do
	filter 'field', 'value'
end

Sorting

results = search 'simple', :sort => {:expr => '@weight + 10'}
# or
results = search 'simple' do
	sort :expr, '@weight + 10'
end

Grouping

results = search 'simple', :group => {:attr => 'field'}
# or
results = search 'simple' do
	group :attr, 'field'
end

Select List

results = search 'simple', :select => 'field1, field2, field3'
# or
results = search 'simple' do
	select 'field1, field2, field3'
end

Multiple Queries

# this will return an array of 3 results
results = search 'simple' do
	filter 'field', 'value'
	sort :expr, '@weight + 10'
	add_query

	filter 'field2', 'value2'
	group :attr, 'field2'
	add_query

	reset_groups
	select 'SUM(1) AS total'
	group :attr, 'total'
	add_query
end

Accessing Result Information

results = search 'simple', :select => 'field1, field2, @weight'
# error?
puts results.first.error
# matches
puts results.matches
# accessig fields
puts results.matches.first.field1
puts results.matches.first.weight