fulltext_searchable 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ require 'digest/md5'
7
7
  # 全文検索インデックスとして機能するモデル。
8
8
  #
9
9
  class FulltextIndex < ActiveRecord::Base
10
+ BOOLEAN_META_CHARACTER_REGEXP = /^[\+\-><\(\)~*"]*/
10
11
  self.table_name = FulltextSearchable::TABLE_NAME
11
12
  self.primary_key = :_id
12
13
  after_create :set_grn_insert_id
@@ -37,6 +38,7 @@ class FulltextIndex < ActiveRecord::Base
37
38
  if phrase.is_a? String
38
39
  phrase = phrase.split(/[\s ]/).reject{|word| word.blank? }
39
40
  end
41
+ phrase.map!{|word| word.gsub(BOOLEAN_META_CHARACTER_REGEXP, '')}
40
42
 
41
43
  # モデルで絞り込む
42
44
  model_keywords = []
@@ -1,3 +1,3 @@
1
1
  module FulltextSearchable
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -89,6 +89,14 @@ describe FulltextIndex do
89
89
  FulltextIndex.match('営業 状態').items.count.should == 2
90
90
  FulltextIndex.match(" 営業\t状態 ").items.count.should == 2
91
91
  end
92
+
93
+ it "should ignore special characters and not break when meta characters are passed" do
94
+ "+-><()~*\"".split(//).each do |character|
95
+ FulltextIndex.match(character + '太郎', :model => User).items.count.should == 1
96
+ end
97
+ FulltextIndex.match('++太郎', :model => User).items.count.should == 1
98
+ FulltextIndex.match(['+太郎'], :model => User).items.count.should == 1
99
+ end
92
100
  end
93
101
 
94
102
  context "optimization" do
@@ -8,7 +8,6 @@ CoverMe.config do |c|
8
8
  end
9
9
 
10
10
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
11
- require "rails/test_help"
12
11
  require "rspec/rails"
13
12
 
14
13
  require "factory_girl"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulltext_searchable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -298,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
298
  version: '0'
299
299
  segments:
300
300
  - 0
301
- hash: -4346424986118501563
301
+ hash: -3155726735639838905
302
302
  required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  none: false
304
304
  requirements:
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: '0'
308
308
  segments:
309
309
  - 0
310
- hash: -4346424986118501563
310
+ hash: -3155726735639838905
311
311
  requirements: []
312
312
  rubyforge_project:
313
313
  rubygems_version: 1.8.25