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
Thanks for such an amazing information. I have just read it. It really helps.
ReplyDeleteIf you are looking for other articles just visit customcollegevisits.com Thanks