Skip to content

Commit

Permalink
Removes amatch dependency
Browse files Browse the repository at this point in the history
- amatch causing issues on Windows systems
- This change necessitates the removal of `--fuzzy` option from search
functions until a replacement matching algorithm is found
  • Loading branch information
ttscoff committed Nov 22, 2021
1 parent e8af0a3 commit e29672d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 62 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 2.0.12

#### FIXED

- Remove amatch gem dependency due to compatibility issues with Windows systems (also removes `--fuzzy` option from all search commands)

### 2.0.11

#### NEW
Expand Down
14 changes: 0 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ PATH
remote: .
specs:
doing (2.0.12)
amatch (~> 0.4, >= 0.4.0)
chronic (~> 0.10, >= 0.10.2)
deep_merge (~> 1.2, >= 1.2.1)
gli (~> 2.19, >= 2.19.2)
Expand All @@ -18,9 +17,6 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
amatch (0.4.0)
mize
tins (~> 1.0)
aruba (1.0.4)
childprocess (>= 2.0, < 5.0)
contracts (~> 0.16.0)
Expand Down Expand Up @@ -75,8 +71,6 @@ GEM
concurrent-ruby (~> 1.0)
middleware (0.1.0)
minitest (5.14.4)
mize (0.4.0)
protocol (~> 2.0)
multi_test (0.1.2)
parallel (1.21.0)
parallel_tests (3.7.3)
Expand All @@ -87,20 +81,14 @@ GEM
middleware
thor
thread_safe
protocol (2.0.0)
ruby_parser (~> 3.0)
rake (13.0.6)
rdoc (6.3.3)
redcarpet (3.5.1)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)
ruby_parser (3.18.1)
sexp_processor (~> 4.16)
safe_yaml (1.0.5)
sexp_processor (4.16.0)
sync (0.5.0)
sys-uname (1.2.2)
ffi (~> 1.1)
temple (0.8.2)
Expand All @@ -109,8 +97,6 @@ GEM
thor (1.1.0)
thread_safe (0.3.6)
tilt (2.0.10)
tins (1.29.1)
sync
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
yard (0.9.26)
Expand Down
71 changes: 42 additions & 29 deletions bin/doing
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ command %i[reset begin] do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -219,6 +219,7 @@ command %i[reset begin] do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |global_options, options, args|
options[:fuzzy] = false
if options[:section]
options[:section] = wwid.guess_section(options[:section]) || options[:section].cap_first
end
Expand Down Expand Up @@ -296,8 +297,8 @@ command :note do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -317,6 +318,7 @@ command :note do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |_global_options, options, args|
options[:fuzzy] = false
if options[:section]
options[:section] = wwid.guess_section(options[:section]) || options[:section].cap_first
end
Expand Down Expand Up @@ -854,8 +856,8 @@ command :cancel do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -874,6 +876,7 @@ command :cancel do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |_global_options, options, args|
options[:fuzzy] = false
if options[:section]
section = wwid.guess_section(options[:section]) || options[:section].cap_first
else
Expand Down Expand Up @@ -956,8 +959,8 @@ command :finish do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand Down Expand Up @@ -995,6 +998,7 @@ command :finish do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |_global_options, options, args|
options[:fuzzy] = false
unless options[:auto]
if options[:took]
took = wwid.chronify_qty(options[:took])
Expand Down Expand Up @@ -1086,8 +1090,8 @@ command %i[again resume] do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -1114,6 +1118,7 @@ command %i[again resume] do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |_global_options, options, _args|
options[:fuzzy] = false
tags = options[:tag].nil? ? [] : options[:tag].to_tags

options[:case] = options[:case].normalize_case
Expand Down Expand Up @@ -1195,8 +1200,8 @@ command :tag do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -1216,6 +1221,7 @@ command :tag do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |_global_options, options, args|
options[:fuzzy] = false
raise MissingArgument, 'You must specify at least one tag' if args.empty? && !options[:autotag]

raise InvalidArgument, '--search and --tag can not be used together' if options[:search] && options[:tag]
Expand Down Expand Up @@ -1331,8 +1337,8 @@ command [:mark, :flag] do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -1352,6 +1358,7 @@ command [:mark, :flag] do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |_global_options, options, _args|
options[:fuzzy] = false
mark = settings['marker_tag'] || 'flagged'

raise InvalidArgument, '--search and --tag can not be used together' if options[:search] && options[:tag]
Expand Down Expand Up @@ -1459,8 +1466,8 @@ command :show do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand Down Expand Up @@ -1510,6 +1517,7 @@ command :show do |c|
c.arg_name 'FORMAT'
c.flag %i[o output]
c.action do |global_options, options, args|
options[:fuzzy] = false
raise DoingRuntimeError, %(Invalid output type "#{options[:output]}") if options[:output] && options[:output] !~ Doing::Plugins.plugin_regex(type: :export)

tag_filter = false
Expand Down Expand Up @@ -1646,8 +1654,8 @@ command %i[grep search] do |c|
c.desc 'Only show items with recorded time intervals'
c.switch [:only_timed], default_value: false, negatable: false

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -1663,6 +1671,7 @@ command %i[grep search] do |c|
c.switch %i[i interactive], default_value: false, negatable: false

c.action do |_global_options, options, args|
options[:fuzzy] = false
raise DoingRuntimeError, %(Invalid output type "#{options[:output]}") if options[:output] && options[:output] !~ Doing::Plugins.plugin_regex(type: :export)

tags_color = settings.key?('tags_color') ? settings['tags_color'] : nil
Expand Down Expand Up @@ -1995,8 +2004,8 @@ command :last do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -2009,6 +2018,7 @@ command :last do |c|
c.flag [:case], must_match: /^[csi]/, default_value: 'smart'

c.action do |global_options, options, _args|
options[:fuzzy] = false
raise InvalidArgument, '--tag and --search can not be used together' if options[:tag] && options[:search]

if options[:tag].nil?
Expand Down Expand Up @@ -2197,8 +2207,8 @@ command :view do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand Down Expand Up @@ -2233,6 +2243,7 @@ command :view do |c|
c.switch %i[i interactive], negatable: false, default_value: false

c.action do |global_options, options, args|
options[:fuzzy] = false
raise DoingRuntimeError, %(Invalid output type "#{options[:output]}") if options[:output] && options[:output] !~ Doing::Plugins.plugin_regex(type: :export)

raise InvalidArgument, '--tag and --search can not be used together' if options[:tag] && options[:search]
Expand Down Expand Up @@ -2424,8 +2435,8 @@ command %i[archive move] do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -2443,6 +2454,7 @@ command %i[archive move] do |c|
c.flag [:before]

c.action do |_global_options, options, args|
options[:fuzzy] = false
if args.empty?
section = settings['current_section']
tags = []
Expand Down Expand Up @@ -2505,8 +2517,8 @@ command :rotate do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand All @@ -2524,6 +2536,7 @@ command :rotate do |c|
c.flag [:before]

c.action do |_global_options, options, args|
options[:fuzzy] = false
if options[:section] && options[:section] !~ /^all$/i
options[:section] = wwid.guess_section(options[:section])
end
Expand Down Expand Up @@ -2728,8 +2741,8 @@ command :import do |c|
c.arg_name 'QUERY'
c.flag [:search]

c.desc 'Use alternative fuzzy matching for search string'
c.switch [:fuzzy], default_value: false, negatable: false
# c.desc '[DEPRECATED] Use alternative fuzzy matching for search string'
# c.switch [:fuzzy], default_value: false, negatable: false

c.desc 'Force exact search string matching (case sensitive)'
c.switch %i[x exact], default_value: false, negatable: false
Expand Down Expand Up @@ -2779,7 +2792,7 @@ command :import do |c|
c.switch [:overlap], negatable: true

c.action do |_global_options, options, args|

options[:fuzzy] = false
if options[:section]
options[:section] = wwid.guess_section(options[:section]) || options[:section].cap_first
end
Expand Down
2 changes: 1 addition & 1 deletion doing.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ spec = Gem::Specification.new do |s|
s.add_runtime_dependency('haml','~>5.0.0', '>= 5.0.0')
s.add_runtime_dependency('chronic','~> 0.10', '>= 0.10.2')
s.add_runtime_dependency('deep_merge', '~> 1.2', '>= 1.2.1')
s.add_runtime_dependency('amatch', '~> 0.4', '>= 0.4.0')
# s.add_runtime_dependency('amatch', '~> 0.4', '>= 0.4.0')
end
2 changes: 1 addition & 1 deletion lib/doing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'csv'
require 'tempfile'
require 'chronic'
require 'amatch'
# require 'amatch'
require 'haml'
require 'json'
require 'logger'
Expand Down
35 changes: 18 additions & 17 deletions lib/doing/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Doing
## This class describes a single WWID item
##
class Item
include Amatch
# include Amatch

attr_accessor :date, :title, :section, :note

Expand Down Expand Up @@ -161,22 +161,23 @@ def tags?(tags, bool = :and, negate: false)
##
def search(search, distance: 3, negate: false, case_type: :smart, fuzzy: false)
text = @title + @note.to_s

if search.is_rx? || !fuzzy
matches = text =~ search.to_rx(distance: distance, case_type: case_type)
else
distance = 0.25 if distance > 1
score = if (case_type == :smart && search !~ /[A-Z]/) || case_type == :ignore
text.downcase.pair_distance_similar(search.downcase)
else
score = text.pair_distance_similar(search)
end

if score >= distance
matches = true
Doing.logger.debug('Fuzzy Match:', %(#{@title}, "#{search}" #{score}))
end
end
matches = text =~ search.to_rx(distance: distance, case_type: case_type)

# if search.is_rx? || !fuzzy
# matches = text =~ search.to_rx(distance: distance, case_type: case_type)
# else
# distance = 0.25 if distance > 1
# score = if (case_type == :smart && search !~ /[A-Z]/) || case_type == :ignore
# text.downcase.pair_distance_similar(search.downcase)
# else
# score = text.pair_distance_similar(search)
# end

# if score >= distance
# matches = true
# Doing.logger.debug('Fuzzy Match:', %(#{@title}, "#{search}" #{score}))
# end
# end

negate ? !matches : matches
end
Expand Down

0 comments on commit e29672d

Please sign in to comment.