Based on your two strings, You're gonna need a custom setting that has a comma separated string of keywords. You may also want to consider a match threshhold. For instance if the subject contains 80% of the keywords, you may want to take action (as subjects are unpredictable usually).
Below is a sample of what you can try. As written, this could cause false positives if the keywords are out of order so you may have to update the code if that is something you care about.
Map<String, SubjectKeywords__c> settings = SubjectKeywords__c.getAll();
for (Email email : emails) {
Set<String> subject = new Set<String>(email.subject.split(' '));
for (SubjectKeywords__c setting : settings) {
Set<String> keywords = new Set<String>(setting.keywords__c.split(','));
integer matchCount = 0;
for (String keyword : keywords) {
if (subject.contains(keyword)) {
matchCount += 1;
}
}
// Check to see if match count is above a set threshold (say, 80%)
// if (matchCount / keywords.size() >= settings.threshhold__c / 100) {
// }
// Check to see if match count is exact if you do not want to use a threshold
// if (matchCount == keywords.size()) {
// }
}
}
I'm not super familiar with your language. According to google it's finnish and "osoitteenmuutos" appears to translate to "address change". If that is the case, than maybe you don't want to include the "As Oy" in your search as these seem to be words that may appear in emails related to other topics as well. If you're looking for anything related to address change then your custom setting should only include the keyword "osoitteenmuutos".
This is mostly an uneducated guess though so I apologize if I made any mistakes during translation but the principal remains, you should try to keep your keywords to a minimum for best possible matches.
str1.contains(str2)
instead?