Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Default to using the simple language if no language is specified for …

…a full text index on PostgreSQL
  • Loading branch information...
commit 70cb43dc866a0548f5fd8391013a00456292b9f3 1 parent ccc23f4
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Default to using the simple language if no language is specified for a full text index on PostgreSQL (michalbugno)
+
* Add Model.raise_on_typecast_failure=, which makes it possible to not raise errors on invalid typecasts (michalbugno)
* Add schema.rdoc file, which provides an brief description of the various parts of Sequel related to schema modification (jeremyevans)
View
2  lib/sequel_core/adapters/shared/postgres.rb
@@ -128,7 +128,7 @@ def index_definition_sql(table_name, index)
filter = " WHERE #{filter_expr(filter)}" if filter
case index_type
when :full_text
- lang = index[:language] ? "#{literal(index[:language])}, " : ""
+ lang = "#{literal(index[:language] || 'simple')}, "
cols = index[:columns].map {|c| literal(c)}.join(" || ")
expr = "(to_tsvector(#{lang}#{cols}))"
index_type = :gin
View
22 spec/adapters/postgres_spec.rb
@@ -344,7 +344,7 @@ def POSTGRES_DB.ret_commit
end
POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
"CREATE TABLE posts (title text, body text)",
- "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector(title || body))"
+ "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector('simple', title || body))"
]
end
@@ -495,3 +495,23 @@ def POSTGRES_DB.ret_commit
ds.insert(:name=>'a').should == nil
end
end
+
+if POSTGRES_DB.server_version >= 80300
+
+ POSTGRES_DB.create_table! :test6 do
+ text :title
+ full_text_index [:title]
+ end
+
+ context "PostgreSQL tsearch2" do
+
+ specify "should search by indexed column" do
+ # tsearch is by default included from PostgreSQL 8.3
+ ds = POSTGRES_DB[:test6]
+ record = {:title => "oopsla conference"}
+ ds << record
+ actual = ds.full_text_search(:title, "oopsla")
+ actual.should include(record)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.