Code Monkey home page Code Monkey logo

zinx's Introduction

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

zinx's People

Contributors

gabrielhora avatar

Stargazers

Anatoly Chernov avatar Tatsuya Sato avatar Waldemar Quevedo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.