Say I have a list of keywords in scala
val keywords = List("pineapple", "lemon")
And a dataframe like so
+---+-------------------------------------------+
|ID |Body |
+---+-------------------------------------------+
|123|I contain both keywords pineapple and lemon|
|456|I sadly don't contain anything... |
|789|Pineapple's are delicious |
+---+-------------------------------------------+
How can I transform this dataframe to have a new column with the keywords that Body contains? The result I'm looking for is something like
+---+-------------------------------------------+------------------+
|ID |Body |Contains_Keywords |
+---+-------------------------------------------+------------------+
|123|I contain both keywords pineapple and lemon|[pineapple, lemon]|
|456|I sadly don't contain anything... |[] |
|789|Pineapple's are delicious |[pineapple] |
+---+-------------------------------------------+------------------+