Class: Lutaml::UmlRepository::Queries::SearchQuery
Constant Summary
collapse
- SEARCHERS =
{
class: :search_classes,
attribute: :search_attributes,
association: :search_associations,
}.freeze
- RESULT_KEYS =
{
class: :classes,
attribute: :attributes,
association: :associations,
}.freeze
Instance Method Summary
collapse
-
#full_text_search(query_string, fields: [:name], case_sensitive: false) ⇒ Object
-
#get_all_associations ⇒ Object
-
#search(query_string, types: %i[class attribute association],, fields: [:name], case_sensitive: false) ⇒ Object
-
#search_associations(query, fields: %i[ name owner_end member_end owner_end_attribute_name member_end_attribute_name documentation ],, case_sensitive: false) ⇒ Object
-
#search_attributes(query, fields: [:name], case_sensitive: false) ⇒ Object
-
#search_by_stereotype(query, case_sensitive: false) ⇒ Object
-
#search_classes(query, fields: %i[name documentation],, case_sensitive: false) ⇒ Object
-
#search_packages(query, case_sensitive: false) ⇒ Object
#class_type_for, #extract_package_path, #format_cardinality, #format_definition, #normalize_stereotypes, #package_path_for, #parse_cardinality, #qualified_name_for
Methods inherited from BaseQuery
#initialize
Instance Method Details
#full_text_search(query_string, fields: [:name], case_sensitive: false) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 38
def full_text_search(query_string, fields: [:name],
case_sensitive: false)
results = { classes: [], packages: [], total: 0 }
return results if query_string.nil? || query_string.empty?
results[:classes] = search_classes(
query_string, fields: fields, case_sensitive: case_sensitive
)
results[:packages] = search_packages(
query_string, case_sensitive: case_sensitive
)
results[:total] = results[:classes].size + results[:packages].size
results
end
|
#get_all_associations ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 131
def get_all_associations
all_associations = []
if document.is_a?(Lutaml::Uml::Document) && document.associations
all_associations << document.associations
end
indexes[:qualified_names].each_value do |entity|
next unless classifiable_with_associations?(entity)
all_associations << entity.associations
end
all_associations.flatten.uniq
end
|
#search(query_string, types: %i[class attribute association],, fields: [:name], case_sensitive: false) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 21
def search(query_string, types: %i[class attribute association],
fields: [:name], case_sensitive: false)
return empty_result if query_string.nil? || query_string.empty?
results = { classes: [], attributes: [], associations: [] }
types.each do |type|
key = RESULT_KEYS[type]
results[key] = public_send(SEARCHERS[type],
query_string,
fields: fields,
case_sensitive: case_sensitive)
end
results[:total] =
results.values_at(:classes, :attributes, :associations).sum(&:size)
results
end
|
#search_associations(query, fields: %i[
name owner_end member_end
owner_end_attribute_name
member_end_attribute_name documentation
],, case_sensitive: false) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 87
def search_associations(query,
fields: %i[
name owner_end member_end
owner_end_attribute_name
member_end_attribute_name documentation
],
case_sensitive: false)
pattern = pattern_from(query, case_sensitive)
get_all_associations.filter_map do |assoc|
match_field = first_matching_field(assoc, fields, pattern)
next unless match_field
build_search_result(
assoc, :association,
assoc.name || "(unnamed)", match_field,
{ "source" => assoc.owner_end, "target" => assoc.member_end }
)
end.uniq
end
|
#search_attributes(query, fields: [:name], case_sensitive: false) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 67
def search_attributes(query, fields: [:name],
case_sensitive: false)
pattern = pattern_from(query, case_sensitive)
indexes[:qualified_names].filter_map do |class_qname, entity|
next unless entity.is_a?(Lutaml::Uml::Classifier) && entity.attributes
attr_match = find_matching_attribute(entity, fields, pattern)
next unless attr_match
attr, match_field = attr_match
build_search_result(
attr, :attribute,
"#{class_qname}::#{attr.name}", match_field,
{ "class_name" => entity.name, "class_qname" => class_qname },
package_path: (class_qname)
)
end.uniq
end
|
#search_by_stereotype(query, case_sensitive: false) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 108
def search_by_stereotype(query, case_sensitive: false)
pattern = pattern_from(query, case_sensitive)
find_entities_by_stereotype_pattern(pattern).map do |entity|
build_search_result(
entity,
entity.class.name.split("::").last.downcase.to_sym,
"", :stereotype
)
end
end
|
#search_classes(query, fields: %i[name documentation],, case_sensitive: false) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 53
def search_classes(query, fields: %i[name documentation],
case_sensitive: false)
pattern = pattern_from(query, case_sensitive)
indexes[:qualified_names].filter_map do |qname, entity|
next unless entity.is_a?(Lutaml::Uml::Class)
match_field = first_matching_field(entity, fields, pattern)
next unless match_field
build_search_result(entity, :class, qname, match_field)
end.uniq
end
|
#search_packages(query, case_sensitive: false) ⇒ Object
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/lutaml/uml_repository/queries/search_query.rb', line 120
def search_packages(query, case_sensitive: false)
pattern = pattern_from(query, case_sensitive)
indexes[:package_paths].filter_map do |path_string, package|
next unless path_string.to_s.match?(pattern)
build_search_result(package, :package, path_string, :package_path,
package_path: path_string)
end
end
|