Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrielhora/zinx
Simple Sphinx Search DSL in Ruby
https://github.com/gabrielhora/zinx
Last synced: about 1 month ago
JSON representation
Simple Sphinx Search DSL in Ruby
- Host: GitHub
- URL: https://github.com/gabrielhora/zinx
- Owner: gabrielhora
- Created: 2012-03-15T23:26:02.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-04-04T21:41:29.000Z (over 12 years ago)
- Last Synced: 2024-11-18T03:06:35.469Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 133 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Zinx
Zinx is a Ruby DSL for the [Sphinx Search Engine](http://www.sphinxsearch.com) (which is used in a lot of [big sites](http://sphinxsearch.com/info/powered/)). 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_queryfilter 'field2', 'value2'
group :attr, 'field2'
add_queryreset_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