server: fix include children in search
This commit is contained in:
parent
5561d65b08
commit
69b32c6440
11
server.rb
11
server.rb
|
@ -169,6 +169,7 @@ def search(terms)
|
|||
statements << @db.prepare("SELECT id FROM part WHERE mpn LIKE ?")
|
||||
statements << @db.prepare("SELECT id FROM part WHERE description LIKE ?")
|
||||
statements << @db.prepare("SELECT property_value.part AS id FROM property_value JOIN property ON property.id = property_value.property WHERE property.name = 'category' AND property_value.value LIKE ?")
|
||||
children = @db.prepare("SELECT id FROM part WHERE family = ?")
|
||||
term_ids = []
|
||||
terms.each do |term|
|
||||
ids = Set.new
|
||||
|
@ -176,17 +177,13 @@ def search(terms)
|
|||
statements.each do |statement|
|
||||
statement.execute("%#{term}%").each do |row|
|
||||
ids << row["id"]
|
||||
children.execute(row["id"]).each do |child|
|
||||
ids << child["id"]
|
||||
end
|
||||
end
|
||||
end
|
||||
term_ids << ids
|
||||
end
|
||||
# get all children
|
||||
statement = @db.prepare("SELECT id FROM part WHERE family IN (?)")
|
||||
term_ids.each do |term_id|
|
||||
statement.execute(term_id.to_a * ",").each do |row|
|
||||
term_id << row["id"]
|
||||
end
|
||||
end
|
||||
# AND terms
|
||||
ids = term_ids.shift
|
||||
term_ids.each do |term_id|
|
||||
|
|
Loading…
Reference in New Issue