mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
AD search: make + model for the aircraft, maker + type for components, additive custom terms
Tested against real Federal Register data:
- aircraft searched as make + model ("Cessna" "150L"), which drops the
transport-category ADs that merely contain the model string
- components also searched as maker + type ("Bendix" "magneto"): appliance
ADs usually name a series, not the exact model; "A/B" makers are split
- propellers also searched as maker + "propeller"
- custom terms add to the automatic searches (they used to replace them,
silently turning off engine/component searches); a bare aircraft model is
skipped since make + model covers it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2f5ce1e92
commit
0db17b3ba6
5 files changed
+47
-23
No files matched your search
+34
-13
@@ -24,29 +24,47 @@ class AdWatch
|
||||
|
||||
ENGINE_OR_PROP = /engine|propell?er|\bprop\b/i
|
||||
|
||||
# The aircraft model; each engine and propeller model (and its family);
|
||||
# and every other installed component's make and model, so ADs on
|
||||
# appliances (magnetos, ELTs, radios, filters…) are found too.
|
||||
# What to look for, each a few words that must all appear in the AD:
|
||||
# - the aircraft make + model ("Cessna" "150L": the make keeps unrelated
|
||||
# ADs that happen to contain "150L" out);
|
||||
# - each engine and propeller model, and its family ("O-200A", "O-200");
|
||||
# for a propeller also its maker + "propeller";
|
||||
# - every other installed component as maker + model designator, type +
|
||||
# designator, and maker + type ("Bendix" "magneto"): appliance ADs often
|
||||
# name a series ("S-20") rather than the exact model.
|
||||
def self.default_terms(aircraft)
|
||||
terms = []
|
||||
terms << Term.new(aircraft.model.strip, [ aircraft.model.strip ], nil) if aircraft.model.present?
|
||||
if aircraft.model.present?
|
||||
model = aircraft.model.strip
|
||||
terms << Term.new([ aircraft.make, model ].compact_blank.join(" "), [ maker_words(aircraft.make).first, model ].compact, nil)
|
||||
end
|
||||
aircraft.components.in_use.includes(:component_type).order(:id).each do |c|
|
||||
model = c.model.to_s.strip
|
||||
next if model.blank?
|
||||
if c.component_type&.name.to_s.match?(ENGINE_OR_PROP)
|
||||
type = c.component_type&.name.to_s.strip
|
||||
label = [ c.manufacturer.to_s.strip, model ].compact_blank.join(" ")
|
||||
makers = maker_words(c.manufacturer)
|
||||
if type.match?(ENGINE_OR_PROP)
|
||||
[ model, model_family(model) ].compact.each { |m| terms << Term.new(m, [ m ], c.id) }
|
||||
makers.each { |mk| terms << Term.new(label, [ mk, "propeller" ], c.id) } if type.match?(/prop/i)
|
||||
else
|
||||
label = [ c.manufacturer.to_s.strip, model ].compact_blank.join(" ")
|
||||
# Maker + model, and type + model: ADs often name the maker differently
|
||||
# (a successor company) but say what the part is ("magneto", "ELT").
|
||||
[ c.manufacturer.to_s.strip.split.first, c.component_type&.name.to_s.strip.split.first ].compact_blank.uniq.each do |lead|
|
||||
terms << Term.new(label, ([ lead ] + designators(model)).uniq, c.id)
|
||||
end
|
||||
makers.each { |mk| terms << Term.new(label, [ mk ] + designators(model), c.id) }
|
||||
terms << Term.new(label, [ type ] + designators(model), c.id) if type.present?
|
||||
makers.each { |mk| terms << Term.new(label, [ mk, type ], c.id) } if type.present?
|
||||
end
|
||||
end
|
||||
terms.uniq { _1.words.map(&:downcase) }
|
||||
end
|
||||
|
||||
# The words to search a maker by: each maker in "Continental/Bendix", by its
|
||||
# first word, or the whole name when that's too short to mean much ("Air Example Co").
|
||||
def self.maker_words(maker)
|
||||
maker.to_s.split(%r{\s*[/,&]\s*}).map(&:strip).compact_blank.map do |name|
|
||||
first = name.split.first
|
||||
first.length >= 4 ? first : name
|
||||
end.uniq
|
||||
end
|
||||
|
||||
# The engine family ADs often name instead of the exact model, and that also
|
||||
# catches a different spelling of the suffix: "O-200A" and "O-200-A" -> "O-200",
|
||||
# "IO-550-N" -> "IO-550". Nil when there's no family to add.
|
||||
@@ -63,10 +81,13 @@ class AdWatch
|
||||
with_digits.any? ? with_digits : words
|
||||
end
|
||||
|
||||
# The owner's own list (comma-separated) replaces the defaults.
|
||||
# The automatic searches plus the owner's own terms (comma-separated).
|
||||
def terms
|
||||
custom = @aircraft.ad_watch_terms.to_s.split(/[,;\n]/).map(&:strip).compact_blank
|
||||
custom.any? ? custom.map { Term.new(_1, [ _1 ], nil) } : self.class.default_terms(@aircraft)
|
||||
# The bare aircraft model is already searched with its make, which keeps
|
||||
# out the many unrelated ADs that contain the same characters.
|
||||
custom.reject! { _1.casecmp?(@aircraft.model.to_s.strip) }
|
||||
(self.class.default_terms(@aircraft) + custom.map { Term.new(_1, [ _1 ], nil) }).uniq { _1.words.map(&:downcase) }
|
||||
end
|
||||
|
||||
# Returns the new AdAlerts.
|
||||
|
||||
Reference in new issue
Block a user