Yes, you can achieve this by building a dynamic query using Criteria API.
Your specification could look like:
Specification<Article> forWords(Collection<String> words) {
if(words == null || words.isEmpty())
throw new RuntimeException("List of words cannot be empty.");
return (root, query, builder) -> words.stream()
.map(String::toLowerCase)
.map(word -> "%" + word + "%")
.map(word -> builder.like(builder.lower(root.get("text")), word))
.reduce(builder::or)
.get();
}
and then it can be executed on JpaSpecificationExecutor<Article>
-enabled repository:
List<String> words = ...; //your logic to get words
List<Article> matches = articleRepository.findAll(forWords(words));