Thursday, September 29, 2011

Running Thinking Sphinx in two applications

Here i'm gonna explain you how to run thinking sphinx in two applications.
Solved Answer: thinking sphinx undefined local variable
Solution for " thinking sphinx undefined local variable "
Answer: This can be done by running thinking sphinx server on two ports
for example: you have two rails applications on your server.
now by default thinking sphinx runs on port 9312

step 1: stop thinking sphinx server if running on first application by typing " rake ts:stop " in your           terminal.
step 2: go to first application folder and delete the files " development.sphinx.conf, test.sphinx.conf and production.sphinx.conf " which are in config folder.
step 3: find the file named sphinx.yml in same config folder, if it doesn't exist create new file with name   " sphinx.yml "
step 4: edit the file sphinx.yml, place this below code in it.
#################################################################################
development:
  port: 9313
test:
  port: 9314
production:
  port: 9315
#################################################################################
IMPORTANT NOTE: SPACE BEFORE THE WORD PORT SHOULD BE TWO SPACES, IF NOT IT DOESN'T WORK.

step 5: now open terminal and go to your application folder and type " rake ts:config "
           thinking sphinx will create new file
           " development.sphinx.conf "
           ( if you have done indexing for testing and production mode then those two files will also be created. )
           you can check that file where you can see in line no 7
           " listen = 127.0.0.1:9313 "
           listen port will be same as you assigned in sphinx.yml file.
step 6: do the same procedure for second application but with different port numbers
           for example:
#################################################################################
           development:
             port: 9316
           test:
             port: 9317
           production:
             port: 9318
#################################################################################
step 7: now start your rails applications on different ports ( i.e ex: " rails s -p 4000 " )
           and thinking sphinx servers on both applications ( rake ts:start )

thats it.

was this helpfull please let me know if you have queries.
please post comments and let me know some feedback.








Wednesday, September 28, 2011

Rails Thinking Sphinx

Here i'm gonna explain you how to use thinking sphinx in rails application.
this can be done in 5 steps 
step 1:  install the gem thinking sphinx.
           i have installed through terminal ( ubuntu linux ) by typing 
           " sudo gem install thinking-sphinx "
           this will install the gem for you.
           include this gem in gem file of your rails application.
           i.e gem 'thinking-sphinx'
           now run bundle install.
step 2:  open the model file for which you want to add search module.
           here i'm taking an example model  " student "
           in this model file student.rb we have two fields 
           1.name
           2.school
           here we are making search on this two fields " name " and " school ". 
           now, add this code in student.rb file
#################################################################################
              define_index do
                  indexes :name
                  indexes :school
              end
#################################################################################
           here we are telling the thinking-sphinx gem to make indexing on these two fields.
step 3:  open the controller file i.e students_controller.rb 
           go to " index " method 
           here basically you will have 
           " @students = Student.all "
           now change this to 
           " @students = Student.search params[:search] "
           here we are adding parameter "search " to make search on the model student.
step 4:  open the view file of index method i.e index.html.erb
           add this form in it
#################################################################################
                            <%= form_tag students_path, :method => :get do  %>
                                   <p>
                                         <%= text_field_tag :search  % >                              
                                   </p>
                                  <p class="button">
                                         <%= submit_tag "Search" %>
                                 </p>
                            <% end %>
#################################################################################
            here we are adding search field to input search request and return the result.
step 5: open terminal and start thinking sphinx indexing by typing
              " rake ts:index "
           next, start thinking sphinx server by typing 
              " rake ts:start "
           you can stop thinking sphinx by typing
             " rake ts:stop "
start you rails server and check it out.
Note: unless you start thinking sphinx server you cant even view page.
thats it. 
was this helpfull please let me know if you have queries.
please post comments and let me know some feedback. 


  

Thursday, June 9, 2011

Installation steps for ruby on ubuntu linux.

Before Installing Ruby on Ubuntu Check following libraries:

you can install them from terminal or software center.

1. openssl
2. readline-common
3. libreadline6-dev
4. libedit2
5. coreutils
6. libssl0.9.8
7. zlib
8. zlib1g-dev
9. zlib1g-dbg
10.zlib1g
11.libssl-dev
12.libopenssl - ruby
13.libreadline6
14.libyaml-dev

==================
=>libmysql-ruby
=>libmysqlclient-dev
=>mysql-server
=>mysql-client
=================

Install Ruby on Ubuntu:

1.  Download Source from http://ftp.ruby-lang.org/pub/ruby/
2.  Extract => tar zxpvf ----
3.  ./configure --prefix=/usr
4.  make
5.  sudo make install

Install Ruby Gems

1.  Download tar file from http://rubygems.org/
2.  Extract
3.  run command => sudo ruby setup.rb

Install Rails:

1. run command from Terminal => sudo gem install rails

Some important gems need to install:

1. mysql
2. mongrel
3. mongrel_cluster

some important gem commands:
1. sudo gem update
2. gem search  => search all local gems
3. gem search --remote  => search remote
4. gem help
5. gem env  => Gem Environment