MongoTemplate mongoTemplate = new MongoTemplate(new MongoClient(new MongoClientURI(mongoURI)), "news-archive");
Query query = new Query();
List<News> tempList = new ArrayList<>();
if(keyword != null) {
String[] strings
= keyword.
toString().
split(" ");
for (int idx = 0; idx < strings.length; idx++) {
List<News> now = this.newsRepository.findAllByNewsContainingOrTitleContaining(pageable, strings[idx]);
tempList.addAll(now);
}
}
if (category != null) {
query.addCriteria(Criteria.where("category").regex(category.toString()));
}
if(date != null) {
String dateString
= date.
toString().
substring(0, date.
toString().
length()-1);
LocalDateTime ldt = LocalDateTime.parse(dateString);
LocalDateTime lower, upper;
lower = LocalDateTime.of(ldt.getYear(), ldt.getMonth(), ldt.getDayOfMonth(), 0, 0, 0);
upper = LocalDateTime.of(ldt.getYear(), ldt.getMonth(), ldt.getDayOfMonth(), 23, 59, 59);
query.addCriteria(Criteria.where("date").gte(lower).lte(upper));
}
List<News> list = mongoTemplate.find(query, News.class);
List<News> finalList = new ArrayList<>();
if(tempList.size() > 0) {
finalList.addAll(tempList);
finalList.retainAll(list);
} else {
finalList.addAll(list);
}
finalList = finalList.stream().distinct().collect(Collectors.toList());
return finalList;
Replies to Irrelevant to the body
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}