wvanbergen-scoped_search 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,10 +87,12 @@ module ScopedSearch
87
87
  tokens = []
88
88
  matches = query.scan(pattern).flatten.compact
89
89
  matches.each { |match|
90
- tokens << :not unless match.index('-').nil?
91
- # Remove any escaped quotes and any dashes - the dash usually the first character.
90
+ tokens << :not if match.index('-') == 0
91
+ # Remove any escaped quotes
92
+ # Remove any dashes preceded by a space or at the beginning of a token
92
93
  # Remove any additional spaces - more that one.
93
- tokens << match.gsub(/[-"]/,'').gsub(/[ ]{2,}/, ' ')
94
+ cleaned_token = match.gsub(/"/,'').gsub(/^-| -/,'').gsub(/[ ]{2,}/, ' ')
95
+ tokens << cleaned_token if cleaned_token.length > 0
94
96
  }
95
97
  return tokens
96
98
  end
@@ -1,7 +1,7 @@
1
1
  # Regular expression tokens to be used for parsing.
2
2
  module RegTokens
3
3
 
4
- WORD = '[\w]+'
4
+ WORD = '[\w-]+'
5
5
  SPACE = '[ ]'
6
6
  STRING = '["][\w ]+["]'
7
7
  OR = 'OR'
@@ -76,7 +76,17 @@ class QueryLanguageTest < Test::Unit::TestCase
76
76
  assert_equal 1, parsed.length
77
77
  assert_equal 'willem', parsed[0].first
78
78
  assert_equal :not, parsed[0].last
79
-
79
+
80
+ parsed = parse_query('hallo-world')
81
+ assert_equal 1, parsed.length
82
+ assert_equal 'hallo-world', parsed.first.first
83
+
84
+ parsed = parse_query('hallo -world')
85
+ assert_equal 2, parsed.length
86
+ assert_equal 'hallo', parsed.first.first
87
+ assert_equal 'world', parsed.last.first
88
+ assert_equal :not, parsed.last.last
89
+
80
90
  parsed = parse_query('123 -"456 789"')
81
91
  assert_equal 2, parsed.length
82
92
  assert_equal '123', parsed[0].first
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wvanbergen-scoped_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-10-11 00:00:00 -07:00
13
+ date: 2008-10-24 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16