Multiple model search in rails with solr

lrSearching is much easier if you use solr or elastic search, no need to write complex database queries.

If you want to integrate solr with your rails application means there is a gem available https://github.com/sunspot/sunspot

Add to Gemfile:

gem 'sunspot_rails'
gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development

Bundle it!

bundle install

Generate a default configuration file:

rails generate sunspot_rails:install

If sunspot_solr was installed, start the packaged Solr distribution with:

 bundle exec rake sunspot:solr:start

Then add the following code in model file which you going to search

searchable do
  text :<field_name>
end

In your controller queries

@search = Project.solr_search do
fulltext params[:search]
end
@projects = @search.results

Thats all, if you pass search params from your view file, then solr will give you the relevant projects.

Now I will show you how to search multi models in same querie,

simply add the same

searchable do
 text :<field_name>
end

In model files which you need to search, Then in your controller

@search = Sunspot.search(Project,Comment, File) do |s|
 s.fulltext(params[:search])
end

@result = @search.result

will give you the result from project, file and comment models


		
Advertisements

Easy Ruby on Rails install

Whenever I setup new Linux for developing rails application. I feel bit tired of installing all necessary things for rails development.

For that I have written one shell script, that install most of the things requires for rails development. If you want this lazy thing. You can check here

https://github.com/navinspm/easy_rails

And use it , fork the code and update if you feel some thing to be added.

Thanks.

Audio Streaming in Ubuntu using Shoutcast and Internet DJ Control

     If you ever want to stream your rails application audio file using shoutcast I will show you how to do this

firt install and configure shoutcast
cd /tmp
wget http://download.nullsoft.com/shoutcast/tools/sc_serv_1.9.8_Linux.tar.gz

If you get error while trying to execute this command then you don’t have wget command installed to your system. For Debian and Ubunutu use the following command to install it:

Code:
apt-get install wget

Again If you get the error then go to the shoutcast site then download the package

 Next we need to create the folder for our shoutcast server and extract the archive

Code:
mkdir /home/shoutcast
tar -zxf sc_serv_1.9.8_Linux.tar.gz -C ./home/shoutcast

Navigate to the shoutcast folder and clear the config file because it has comments and configuration codes it may confuse you if you see them first time any way its better to clear the file

Code:
cd /home/shoutcast
echo > sc_serv.conf

5. Open the file sc_serv.conf

Code:
nano sc_serv.conf

Paste the following text

Code:
 MaxUser=32
 Password=changeme
 PortBase=8000
LogFile=sc_serv.log
RealTime=1
ScreenLog=1
ShowLastSongs=10
SrcIP=ANY
DestIP=ANY
Yport=80
NameLookups=0
 AdminPassword=adminpass
AutoDumpUsers=0
AutoDumpSourceTime=30
PublicServer=default
AllowRelay=Yes
AllowPublicRelay=Yes
MetaInterval=32768

You should modify these settings:

A. Change the MaxUsers , It can be many users but set minimum as possible
B. Set the Password to a value that you know because you need it to connect to the server in order to stream music to it.
C. Optionally you can change the port by changing the PortBase to some different port.
D. AdminPassword is the web interface password. Web interface is used for banning and kicking users from the server.

6. Start the server

Code:
screen
./sc_serv

Thats all next is to go for broadcaster software in windows and mac SAM broadcaster is a excellent software we have but If you  want to use ubuntu then InternetDJcontrol shortely called as IDJC

IDJC

first we need to install idjc

Code:

sudo apt-get install jackd qjackctl

then

Open Limits.conf

sudo gedit /etc/security/limits.conf

Add the following lines into the file :

@audio - rtprio 99
@audio - memlock unlimited
@audio - nice -19

then run idjc you can find it by searching IDJC in ubuntu search bar This is GUI of IDJC

 main

Go to view-> output you will see the window like this there go to configuration -> connection -> new and fill the details as shown then click OK

host

then in configuration -> format fill the details as follows

configuration image

configuration setting

If all set to correct then above localhost:8000 (8000 may change depends on port you set)  will appear as shown if not check the settings againlocalhost then click the localhost:8000 button if everything goes well the button has need to be stayed as pressed like this  then the green light will glow

connectedand that’s all you may listen your radio on shoutcast.com by searching your radio name which you given at the first time you starts the IDJC , if the green indicator doesnot glow check the shoutcast server running and see the serv.conf file port setting

If you want to use it in your rails application the jplayer fetch the stream and play it well check it on their website jplayer stream player

 

Thank you for reading me…………………

 

Gemmified version of jquery plug-in stick

Sticky is a jQuery plugin that gives you the ability to make any element on your page always stay visible .This is gemmified version of sticky

jQuery sticky 1.0.0 – http://stickyjs.com/

Installation

Add this line to your application’s Gemfile:

gem 'sticky-rails'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install sticky-rails

Usage

Sticky is a jQuery plugin that gives you the ability to make any element on your page always stay visible. , so please check if you are using the jquery on your rails app

//= require jquery

Your app/assets/javascripts/application.js must appear like:

//= require jquery
//= require jquery_ujs
//= require jquery.sticky.js
//= require_tree .

Basic Structure example from http://stickyjs.com/

<script>
  $(document).ready(function(){
    $("#sticker").sticky({topSpacing:0});
  });
</script> 

REMEMBER TO INITIALIZE IT!

If you are going to use coffee script:

$(document).ready ->
  $("sticker").sticky()

Or just javascript:

 $(document).ready(function(){
    $("#sticker").sticky({topSpacing:0});
  });

For more documentation please checkout the sticky-rails 4 repository here: https://github.com/garand/sticky

Gem Author

http://twitter.com/navinspm