Skip to content

Commit

Permalink
Merge pull request #340 from jonathanhefner/search-exclude-downcased-…
Browse files Browse the repository at this point in the history
…acronym-bigrams

Exclude downcased acronym bigrams
  • Loading branch information
jonathanhefner authored Oct 21, 2023
2 parents 81c82e0 + 09e7614 commit 71fc833
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/sdoc/search_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def derive_bigrams(name)
# Example: "ActiveSupport::Cache::Store" => ":ActiveSupport:Cache:Store"
strings = [":#{name}".gsub("::", ":")]

# Example: ":ActiveModel:API" => ":activemodel:api"
strings.concat(strings.map(&:downcase))
# Example: ":ActiveSupport:HashWithIndifferentAccess" => ":AS:HWIA"
strings.concat(strings.map { |string| string.gsub(/([A-Z])[a-z]+/, '\1') })
# Example: ":AbstractController:Base#action_name" => " AbstractController Base action_name"
strings.concat(strings.map { |string| string.tr(":#", " ") })
# Example: ":AbstractController:Base#action_name" => ":AbstractController:Base#actionname"
strings.concat(strings.map { |string| string.tr("_", "") })
# Example: ":ActiveModel:API" => ":activemodel:api"
strings.concat(strings.map(&:downcase))

# Example: ":ActiveModel:Name#<=>" => [":ActiveModel", ":Name", "#<=>"]
strings.map! { |string| string.split(/(?=[ :#])/) }.flatten!
Expand Down
4 changes: 2 additions & 2 deletions spec/search_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def hoge_fuga; end
_(bigrams).wont_include "GR"
end

it "includes downcased bigrams" do
it "includes downcased bigrams except for acronym bigrams" do
bigrams = SDoc::SearchIndex.derive_bigrams("AbcDefGhi::RstUvwXyz")

bigrams.grep(/[A-Z]/).each do |uppercase|
bigrams.grep(/[A-Z]/).grep_v(/[A-Z]{2}/).each do |uppercase|
_(bigrams).must_include uppercase.downcase
end
end
Expand Down

0 comments on commit 71fc833

Please sign in to comment.