Permalink
Browse files

some examples

  • Loading branch information...
grosser committed Jan 5, 2009
1 parent 4bedd47 commit 16aabe90a0933b3df524983eab1e959e5a935289
Showing with 33 additions and 0 deletions.
  1. +13 −0 examples/he_search.rb
  2. +20 −0 examples/person.rb
View
@@ -0,0 +1,13 @@
+# a module to include in your controllers
+# params:
+# q => search word
+# search => {name=>something}
+# order => name DESC
+# define the constant PER_PAGE in your controller so it can be used here
+module Modules
+ module HeSearch
+ def current_objects
+ @current_objects ||= current_model.fulltext_results(params[:q],:page=>params[:page],:per_page=>self.class.const_get('PER_PAGE'),:attributes=>params[:search],:order=>params[:order])
+ end
+ end
+end
View
@@ -0,0 +1,20 @@
+# this is a person indexed by hyperestraier
+# it should have name/city/country:string about:text online:boolean
+class Person < ActiveRecord::Base
+ acts_as_searchable(
+ :ignore_timestamp=>true, #do not add timestamps to search_backend
+ :searchable_fields => [:name,:website,:city,:about],
+ :attributes => {"@title"=>:name,:name=>nil,:city=>nil,:country=>nil}#attribute results
+ #add @title for higher search weight on this attribute
+ )
+ attr_accessor :html_snippet #so we get nice html snippets for our search results...
+
+ #customize the length/widths of the fetched snippets
+ search_backend.connection.set_snippet_width(150,20,20)#total,beginning(>0!),around
+
+ #only index a person when it is online
+ def add_to_index_with_online_check
+ add_to_index_without_online_check if online?
+ end
+ alias_method_chain :add_to_index, :online_check
+end

0 comments on commit 16aabe9

Please sign in to comment.