Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding rake tasks

  • Loading branch information...
commit d2ebd2ea8a9a437d4e8ec048186939bb1788ee61 1 parent 1e287da
@tenderlove tenderlove authored
View
1  .gitignore
@@ -1,3 +1,4 @@
.*.swp
*.tmproj
tags
+pkg
View
9 Manifest.txt
@@ -1,7 +1,12 @@
-History.txt
+.autotest
+CHANGELOG.rdoc
Manifest.txt
-README.txt
+README.rdoc
Rakefile
bin/texticle
lib/texticle.rb
+lib/texticle/full_text_index.rb
+rails/init.rb
+test/helper.rb
+test/test_full_text_index.rb
test/test_texticle.rb
View
44 README.rdoc
@@ -1,32 +1,62 @@
= texticle
-* FIX (url)
+* http://texticle.rubyforge.org/
== DESCRIPTION:
-FIX (describe your package)
+Texticle exposes full text search capabilities from PostgreSQL, and allows
+you to declare full text indexes. Texticle will extend ActiveRecord with
+named_scope methods making searching easy and fun!
== FEATURES/PROBLEMS:
-* FIX (list of features or problems)
+* Only works with PostgreSQL
== SYNOPSIS:
- FIX (code sample of usage)
+ ###
+ # In environment.rb
+
+ config.gem 'texticle'
+
+ ###
+ # Declare your index in your model
+
+ class Product < ActiveRecord::Base
+ index do
+ name
+ description
+ end
+ end
+
+ ###
+ # Use the search method
+
+ Product.search('hello world')
+
+ ###
+ # Full text searches can be sped up by creating indexes. To create the
+ # indexes, add these lines to your Rakefile:
+ require 'rubygems'
+ require 'texticle/tasks'
+
+ # Then run:
+
+ $ rake texticle:create_indexes
== REQUIREMENTS:
-* FIX (list of requirements)
+* Texticle may be used outside rails, but works best with rails.
== INSTALL:
-* FIX (sudo gem install, anything else)
+* sudo gem install texticle
== LICENSE:
(The MIT License)
-Copyright (c) 2009 FIX
+Copyright (c) 2009 Aaron Patterson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
6 lib/texticle/full_text_index.rb
@@ -17,6 +17,12 @@ def create
eosql
end
+ def destroy
+ @model_class.connection.execute(<<-eosql)
+ DROP index #{@name}
+ eosql
+ end
+
def to_s
vectors = []
@index_columns.sort_by { |k,v| k }.each do |weight, columns|
View
26 lib/texticle/tasks.rb
@@ -0,0 +1,26 @@
+require 'rake'
+require 'texticle'
+
+namespace :texticle => [:environment] do
+ task :create_indexes do
+ Dir[File.join(RAILS_ROOT, 'app', 'models', '*.rb')].each do |f|
+ klass = File.basename(f, '.rb').classify.constantize
+ if klass.respond_to?(:full_text_indexes)
+ klass.full_text_indexes.each do |fti|
+ fti.create
+ end
+ end
+ end
+ end
+
+ task :destroy_indexes do
+ Dir[File.join(RAILS_ROOT, 'app', 'models', '*.rb')].each do |f|
+ klass = File.basename(f, '.rb').classify.constantize
+ if klass.respond_to?(:full_text_indexes)
+ klass.full_text_indexes.each do |fti|
+ fti.destroy
+ end
+ end
+ end
+ end
+end
View
3  rails/init.rb
@@ -0,0 +1,3 @@
+require 'texticle'
+
+ActiveRecord::Base.extend(Texticle)
View
13 test/test_full_text_index.rb
@@ -10,6 +10,19 @@ def test_initialize
assert_equal 'value', fti.index_columns['A'].first
end
+ def test_destroy
+ fm = fake_model
+ fti = Texticle::FullTextIndex.new('ft_index', fm) do
+ name
+ value 'A'
+ end
+ fti.destroy
+ assert fm.connected
+ assert_equal 1, fm.executed.length
+ executed = fm.executed.first
+ assert_match "DROP index #{fti.instance_variable_get(:@name)}", executed
+ end
+
def test_create
fm = fake_model
fti = Texticle::FullTextIndex.new('ft_index', fm) do

0 comments on commit d2ebd2e

Please sign in to comment.
Something went wrong with that request. Please try again.