Skip to content

Instantly share code, notes, and snippets.

@lumpidu
Created May 22, 2012 08:08
Show Gist options
  • Save lumpidu/2767499 to your computer and use it in GitHub Desktop.
Save lumpidu/2767499 to your computer and use it in GitHub Desktop.
Post Model
def reindex
# import data from DB Model
Tire.index 'posts' do
delete
create
end
Post.select('id, title, url, created_at, feed_author, feed_location,
feed_summary, feed_timestamp, updated_at, converted_text,
language').includes('feeds').import :per_page => 1000
end
class Post < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :id, :index => :not_analyzed
indexes :title, :analyzer => 'snowball', :boost => 3
indexes :url, :analyzer => 'url'
indexes :created_at, :type => 'date', :include_in_all => false
#indexes :content_raw, :index => :not_analyzed
#indexes :title_sha1, :index => :not_analyzed
indexes :feed_author, :analyzer => 'keyword'
indexes :feed_location, :analyzer => 'keyword'
indexes :feed_summary, :analyzer => 'snowball', :boost => 2
indexes :feed_timestamp, :type => 'date', :include_in_all => false
indexes :updated_at, :type => 'date', :include_in_all => false
indexes :converted_text, :analyzer => 'snowball'
#indexes :converted_text_sha1, :index => :not_analyzed
#indexes :converted_html, :index => :not_analyzed
indexes :language, :analyzer => 'keyword'
# why doesn't this work ?
#indexes :converted_text_size, :type => 'integer', :as => 'converted_text.size'
end
def to_indexed_json
to_json(methods: [:feed_id, :converted_text_size])
end
def feed_id
feeds.first.id
end
def converted_text_size
converted_text.size
end
has_and_belongs_to_many :feeds, :join_table => "feed_posts"
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment