GithubHelp home page GithubHelp logo

isabella232 / thebes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harvesthq/thebes

0.0 0.0 0.0 25 KB

DEPRECATED - Thebes is a thin binding layer for Rails and Sphinx with Riddle

Home Page: https://github.com/harvesthq/thebes

License: MIT License

Ruby 92.45% HTML 7.55%

thebes's Introduction

Thebes

⚠️This project is no longer maintained ⚠️

Thebes is a thin binding layer for Rails and Sphinx via Riddle and Mysql2. Thebes expects you to write Sphinx configuration files by hand and have a rich understanding of Sphinx, but provides configuration files and templates to ease the process.

Installation

To use Thebes, just add it to your Gemfile:

gem 'thebes'

# Or pin Thebes to git
# gem 'thebes',
#   :git => '[email protected]:harvesthq/thebes.git'

Then use bundle install to update your Gemfile.lock. If your project is using Rails, you can take advantage of the generator to create your starting config files:

script/rails g sphinx_config

This will create the three config files that Thebes requires for easy setup:

  • sphinx.yml - Configuration values for your sphinx.conf files.
  • sphinx.conf.erb - The template for your sphinx.conf files.
  • sphinx_servers.yml - Configuration of Rails, which Sphinx servers to connect to.

Flavor to taste, and run rake thebes:build to generate your sphinx configuation.

Querying via Sphinx's custom protocol

Generate a query against Sphinx via Riddle:

result = Thebes::Query.run do |a|
  # a here is an instance of Riddle::Client:
  # http://rdoc.info/github/freelancing-god/riddle/master/Riddle/Client
  a.apply_filter_like_in_riddle
end 

result will be an instance of Riddle::Response. Usually you will want to call .next on it to get your returned values from Sphinx. A more complex usage example:

# sphinx_res is a raw result from Riddle.
#
sphinx_res = Thebes::Query.run do |q|
  
  # In Riddle, filters need to be added to a query before the
  # actual query.
  #
  q.filters << Riddle::Client::Filter.new('active', [1])
  
  # Pull search terms of a query.
  #
  query = params[:search_terms].split(' ').collect {|word|
    "( =#{word} | #{word} | #{word}* )"
  }.join(' ')
  
  q.append_query query, 'documents' # Search index 'documents'.

  # You can change the match_mode or alter the query in other
  # ways.
  #
  # q.match_mode = :expr2
end

ids, weights = [], []
sphinx_res[0][:matches].each do |match|
  ids << match[:attributes]['_id']
  weights << match[:weight]
end

# Fetch documents from the database.
#
@documents = Document.find(ids)

# Sort documents by weight.
#
@documents.sort! {|a,b| weights[ids.index(b.id)] <=> weights[ids.index(a.id)] }

Additionally, you can set procs to be run before the query block or right before the query is run:

# Usually found in config/initializers/thebes.rb
#

# Before the Thebes::Query.run block.
#
Thebes::Query.before_query = Proc.new do |q|
  q.match_mode = :any
  q.max_matches = 10
end

# Just before the query is run.
#
Thebes::Query.before_running = Proc.new do |q|
end

Querying via Sphinxql

Thebes has minimal support for querying Sphinx via the new Sphinxql syntax. Running a query returns a Mysql2::Result object.

# Do a search with SphinxQL.
#
@results = Thebes::Sphinxql::Query.run "SELECT * FROM items WHERE MATCH('Horwitz')"

@ids = @results.collect {|r| r['_id'] }

Deployment Strategy

Always check config/sphinx.conf.erb into your SCM. The config/sphinx.yml and config/sphinx_servers.yml files probably should not be checked in, and any generated config/sphinx.conf files should likely not be checked in.

Steps in a capistrano-style deployment:

  • Copy server-side config/sphinx_servers.yml and config/sphinx.yml files into place.
  • Run rake thebes:build to generate config/sphinx.conf or any other sphinx configuration files.
  • Restart searchd, run the indexer.

If you want to use a cluster of Sphinx servers, several configuration files can be generated by modifying config/sphinx.conf to generate the proper configurations. Then update config/sphinx_servers.yml to tell your running Rails app where to find any new servers.

Contributing

Fork, clone, write a test, write some code, commit, push, send a pull request. Github FTW!

This project was open-sourced by Harvest. We're hiring!

thebes's People

Contributors

mixonic avatar zsombor avatar jorgeleria 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.