postgres-fulltext-search-helper 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ module Postgres
2
2
  module Fulltext
3
3
  module Search
4
4
  module Helper
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
8
8
  end
@@ -7,7 +7,7 @@ module PostgresFulltextSearchHelper
7
7
 
8
8
  def format_query_for_fulltext(query)
9
9
  parts = query.split(POSTGRES_TSQUERY_SENSITIVE_CHARACTERS).delete_if{|x| x.strip.empty? }
10
- return parts.map{|token| token + ':*'}.join(' & ')
10
+ return parts.map{|token| "(#{token}:* | -#{token}:*)" }.join(' & ')
11
11
  end
12
12
 
13
13
  def search(scope, field_name, query)
@@ -6,24 +6,24 @@ describe PostgresFulltextSearchHelper do
6
6
  it "returns a string that can be used by postgres" do
7
7
  query = "hello"
8
8
 
9
- expect(Helper.format_query_for_fulltext(query)).to eq("hello:*")
9
+ expect(Helper.format_query_for_fulltext(query)).to eq("(hello:* | -hello:*)")
10
10
  end
11
11
 
12
12
  it "whitespace is interpreted as &" do
13
13
  query = "hello world"
14
14
 
15
- expect(Helper.format_query_for_fulltext(query)).to eq("hello:* & world:*")
15
+ expect(Helper.format_query_for_fulltext(query)).to eq("(hello:* | -hello:*) & (world:* | -world:*)")
16
16
  end
17
17
 
18
18
  it "handles sensitive characters" do
19
19
  query = "*:hello &(world)!|"
20
- expect(Helper.format_query_for_fulltext(query)).to eq("hello:* & world:*")
20
+ expect(Helper.format_query_for_fulltext(query)).to eq("(hello:* | -hello:*) & (world:* | -world:*)")
21
21
  end
22
22
 
23
23
  it "adds a filter to a activerecord-style scope" do
24
24
  scope = stub("scope").as_null_object
25
25
 
26
- scope.should_receive(:where).with("to_tsvector('simple', name::text) @@ to_tsquery('simple', ?)", ["hello:* & world:*"])
26
+ scope.should_receive(:where).with("to_tsvector('simple', name::text) @@ to_tsquery('simple', ?)", ["(hello:* | -hello:*) & (world:* | -world:*)"])
27
27
 
28
28
  Helper.search(scope, "name", "hello world")
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres-fulltext-search-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-27 00:00:00.000000000 Z
13
+ date: 2013-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec