Let's say I have a book title and I search for it in a database. The database produces matches, some of which are full matches and some of which are partial matches.
A full match
is when every word in the search result is represented by a word in the search terms. (i.e. there does not have to be a complete overlap on both sides)
I am only concerned with finding the full matches.
So if I type a search for "Ernest Hemingway - The Old Man and the Sea"
and the results return the following:
Charles Nordhoff - Men Against The Sea
Rodman Philbrick - The Young Man and the Sea
Ernest Hemingway - The Old Man and the Sea
Ernest Hemingway - The Sun Also Rises
Ernest Hemingway - A Farewell to Arms
Ernest Hemingway - For Whom the Bell Tolls
Ernest Hemingway - A Moveable Feast
Ernest Hemingway - True at First Light
Men Against The Sea
The Old Man and the Sea
The Old Man and the Sea Dog
There are TWO full matches
in this list: (according to the definition above)
Ernest Hemingway - The Old Man and the Sea
The Old Man and the Sea
To do this in Java, assume I have two variables:
String searchTerms;
List<String> searchResults;
searchTerms
in the example above represents what I typed in: Ernest Hemingway - The Old Man and the Sea
searchResults
represents the list of strings I got back from the database above.
for (String result : searchResults) {
// How to check for a full match?
// (each word in `result` is found in `searchTerms`
}
My question is: in this for-loop
, how do I check whether every word in the result
String has a corresponding word in the searchTerms
String?