Monday, October 19, 2009

BrokenCompass: How to go about it

Once you are done with installation and index creation for brokencompass, can play around with the search capabilities of it..

Point 01. ruby script/console
==> Output
Adding BrokenCompass Version: 1.0
Loading index... [broken_compass/advertisment.index]

Point 02. Searching in all fields, i.e not using extended_mode
Advertisment.look_in_brokencompass("train")
==> Returns an inference hash like this
{
# Time elapsed in the execution(in seconds)
:time_elapsed=>0.00617599487304688,

# Field(s) which is/are available for indexing
:fields=>["location", "title", "description"],

# Weight given to different attributes to ranks result items
:column_weight=>{:description=>10, :location=>10, :title=>10},

# Count of total records found
:total_record_count=>44,

# Boolean field to unload indexes from memory once query is fired
:eager_unload=>false,

# Boolean field for extended_mode, set to true when using attribute(column) level searches
:extended_mode=>false,

# Boolean field for PLURAL forms of search word
:plural_forms=>true,

# Result set with weighted scores
:weighted_records=>[[14844, 20], [17445, 20], ... , [15148, 10]]}

# Limit to result set
:limit=>20,

# Offset to result set
:offset=>0,
}


Point 03. Searching in extended mode i.e specifically in some attribute(from the attributes used in sql query for index creation)
Advertisment.look_in_brokencompass("'job'@title", :extended_mode => true)
==> Returns an inference hash same as above
{
:column_weight=>{:description=>10, :location=>10, :title=>10},
:total_record_count=>1419,
:time_elapsed=>0.0523371696472168,
:fields=>["location", "title", "description"],
:eager_unload=>false,
:limit=>20,
:extended_mode=>true,
:offset=>0,
:plural_forms=>true,
:weighted_records=>[[14607, 20], [17685, 20], ...... , [13727, 10]]
}


Point 04. Searching in extended mode and also using other possible options
Advertisment.look_in_brokencompass("'job'@title", :extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20})
==> Returns an inference hash same as above
{
:column_weight=>{:description=>20, :location=>10, :title=>40},
:total_record_count=>1419,
:time_elapsed=>0.0521509647369385,
:fields=>["location", "title", "description"],
:eager_unload=>false,
:limit=>5,
:extended_mode=>true,
:offset=>4,
:plural_forms=>true,
:weighted_records=>[[17947, 80], [17946, 80], [9597, 80], [12556, 80], [25975, 80]]
}

Point 05. To retrieve data results from above mentioned conditions and critriea
Advertisment.find_with_brokencompass("'job'@title", :brokencompass => {:extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20}})
==> Returns an result-set array of type Advertisment

Point 06. To user "and" & "or" operators in extended mode
Advertisment.look_in_brokencompass("'job'@title | 'career'@description", :extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20})
==> Returns an result-set array of type Advertisment
Advertisment.look_in_brokencompass("'job'@title & 'career'@description", :extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20})
==> Returns an result-set array of type Advertisment

In case of any further queries please contact me at praveen[dot]kumar[dot]sinha[at]gmail[dot]com

BrokenCompass - Install instructions

BrokenCompass up and running in flat 5 mins

Step: 01
Install BrokenCompass plugin
ruby script/plugin install http://brokencompass.googlecode.com/svn/trunk
from inside of rails app root directory.

Step: 02
Add BrokenCompass configuration yml file
Create file
config/brokencompass.yml

Add content like
#brokencompass.yml............. STARTS
index-sources:
advertisment:
sql: "select id,title,description,location from advertisments"
table_name: advertisments

query:
sql: "select id,content,dynamic_fields from queries"
table_name: queries

# Database connection adapter
connection_adapter:
adapter: "mysql"
host: "localhost"
username: "username"
password: "password"
database: "myapp_development"

#brokencompass.yml............. ENDS

Note:
0. Nothing is optional in the yml(everything is mandatory)
1. Add as many items in index-sources as you want, but every item name should match model names(for which they will be used).
2. Make sure to include the Id field so that index created can be mapped to record identifier.
3. Provide the connection adapter details in connection_adapter section(so as to answer, where to read data from)
4. If you are not minding the spaces in yml(then you have messed up the configuration, so don't try to remove spaces :) from yml, wanna know more about yml? )


Step: 03
Run rake task to create indexes for the first time
rake brokencompass:create_index
from inside of rails app root directory.

Step: 04 (This is required, when one is re-creating the indexes from scratch)
Run rake task to re-create indexes
rake brokencompass:index
from inside of rails app root directory.

Step: 05 (To delete any of the indexes so created, delete corresponding "xxxx.index" file from broken_compass
from inside of rails app root directory.

Friday, October 9, 2009

BrokenCompass

New in-memory full text search engine in ruby and in rails "BrokenCompass".
Coming soon....
keep an eye on this space..

Wednesday, July 29, 2009

svn: This client is too old to work with working copy

Hello folks,

I am still very much alive, i don't know ho missed me or not(am sure no one :D). There is lot happening in life now-a-days will talk about it later, first a quickie about SVN.

If you are working on some project then you must be aware of something called SVN, it is an open source version control system. Recently got hit with something really weired.

I work on Ubuntu but as my ubuntu doesn't have anything even close to 80% of tortoise SVN i tried using windows for that(using virtual windows and samba) to carry on my SVN activities that is really really easy when it is done using TortoiseSVN.

But the time i tried "svn update" from Linux shell command it gave me
praveen@praveen-laptop:~/NetBeansProjects/projectone$ svn update
svn: This client is too old to work with working copy '.'. You need
to get a newer Subversion client, or to downgrade this working copy.
See http://subversion.tigris.org/faq.html#working-copy-format-change
for details.


And i was like what to do now, so followed the instruction and it worked(at least worked for me :) ). So what i did is
Step 01: Downloaded a file http://svn.collab.net/repos/svn/trunk/tools/client-side/change-svn-wc-format.py http://svn.apache.org/repos/asf/subversion/trunk/tools/client-side/change-svn-wc-format.py
Step 02: Executed the following command
praveen@praveen-laptop:~$ python change-svn-wc-format.py /path/to/project 1.5
i.e my project got downgraded to version 1.5

And it worked :)

AS NOTE: usage: change-svn-wc-format.py Working_Copy SVN_VERSION

Next Time something like this happens, you know how to do it.

Monday, June 1, 2009

How to run GPRS from airtel on ROKR E6 motorola

Hey hi guys and gals,
Just after a long time i am writing something on mobile device, actually it is something which shows how stupid I am :D
I was planned to go for a small trip to my home town (I will write a post about it too, but for the time being 'the issue').
I live in Delhi(India) and so this is something for the locale or some one who is facing almost the same that i faced about a week ago, and it was of how to make GPRS active on my best Motorola rokr e6(where it is very much assumed that i have an Airtel post paid mobile connection). I was in urgent need of some way or the other to connect to net as have lot and lot of dependency on it and even if i am off from office i have work to do :D (sounds as if i am very busy person, let me be :D) so i opted for GPRS from my mobile and i know e6 comes with GPRS features, but some how or the other it was not working.
I asked airtel people about it, they were just resending the setting to my phone, which was very much accepted and installed too but the main issue was still there "GPRS was not working", according to them this is all they can do and there was actually not in that, they were sending a GPRS connection premade with the name of "Mobile-office" which contained an APN: airtelgprs.com and an primary gateway ip: 202.56.231.117 and the port was 8080 and nothing more nothing less but damn it was not working, call center executive were helpless what to do so again and again tried different hooks but nothing worked out and i again called the executive and she said something which made me feel how stupid of me, being so much in technology was not able to figure out this small thing and it was that i have to manually enable the GPRS, which is manually accessed from the bar which shows the reception quality, programs and players running and which by default is placed just below the top set of icons, enabled the GPRS from there and restarted my phone(which call center guys usually asks to do) and it worked :)

Sometimes even i can skip something which is right in front of my eyes or one can right in front of my screen (it happens with developers).
So guys or gals if you have faced something stupid like this please comment and let every body know :), at least i did
chow people it is the to hit bed, I am dead tired right now after this vacation :D

Friday, May 8, 2009

Some life updates

Actually this month is happening... as life is as usual.
Just resigned from MPST(MPS Technologies Limited) and am stretching my legs and thank god that even summers are chilling now-a-days so it is all very pleasant.
and I voted too this central elections (it is only applicable if you known about current Indian political status of India).
And ya the most happening thing that i did this week was i took the test drive of Toyota innova, and to be fare i thought i was disappointed for the gear knob vibrations from toyota but latter on, i thought every other car is only way behind it.... so why give it a bad name.. so it is good and perfect if you care about your family and wanna visit places.. it is a nice car that's for sure.
And as was expected, I also visited the tata showroom to ask in for tata most famous car after nano, exactly the safari The tata safari... and not going against my expectations, they didn't had any car to give the test drive and according to them they give test drive on vehicles which are ordered for other customers, now that's bad.
And here is a car comparison that i have not done before..
Innova is
  • good interiors
  • good exteriors
  • not so good vibrating gear in diesel
  • it doesn't rules the road
  • No 4*4 wheel drive
  • but very stable and great family car
  • Service is prompt i will buy innova if i can park it in near future

About Safari
  • "Reclaim you life" slogans fits in, but is life so lost??
  • Great exteriors and equally bad interiors
  • finish is not finished yet, come on guys increase the price by 2 lakhs but don't decrease the expectations
  • Why is roof mounted AC looks as if it is not part of roof (learn something from innova)
  • Service (Needs a big big improvement)
  • And please do have a separate car to test drive

:)

I was so mentally boosting myself to buy a safari but they have shattered my dreams, what to do and why to do!! both questions are playing

Any how people its late in night and that too of no-work... i want to fit my "Reclaim your sleep" slogan now.

bbye and good luck

Saturday, May 2, 2009

Pretty urls with name or title in ruby on rails

Hi folks,

Something on which is very old.. might not be very interesting for many of you who are into rails development. I am talking about the pretty-urls the SEO stuff(forget all this, it is for good readability of url).

So what my basic funda that i have gathered from last three years is that, every resource is identified by an identifier in rails(generally called id, in terms of database), but displaying the id doesn't sounds legal to me.. so to hide the ids and to have a nice looking readable

we can have title or name fields in the database's relation(table) and to make use of pretty urls, we make corresponding column like stripped_title or stripped_name.
create a file "make_pretty_url.rb" in initializers in config and append the following code.


puts "===================================================="
puts "Adding engine to make pretty url(s)"
puts "===================================================="
module ActiveRecord
class Base
after_create :make_or_update_pretty_url_name

def make_or_update_pretty_url_name
parent_column = nil
stripped_column = self.attributes.collect {|x| x.to_s.include?("stripped_") ? x : nil}.flatten.compact.first
if stripped_column
parent_column = stripped_column.gsub("stripped_","")
if self.send(parent_column)
self.send("#{stripped_column}=",stripp_it(self.send(parent_column)))
if self.class.find(:all, :conditions => ["#{stripped_column} = ?",self.send(stripped_column)]).length > 0
self.send("#{stripped_column}=","#{self.send(stripped_column)}-#{self.id.to_s}")
end
self.send("save")
end
end
end

def stripp_it(str)
str.strip.downcase.gsub(/[^a-z0-9]/,"-").gsub(/(-)+/,"-").gsub(/(-)+$/,"")
end
end
end


it will automatically create stripped_{column_name} and will take care of duplicates and instead of using find_by_id(), find_by_stripped_{column_name} will be used to get the resource and "make_or_update_pretty_url_name" method will also be available for any manual work too.

Hope this just adds in the knowledge base of stuff, and if there is anything about it, let me know through comments..

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...