1.implement fuzzy search

main
Gary 10 months ago
parent 749e0469f9
commit aa1fe8082f

@ -278,10 +278,24 @@ public class JournalService {
public List<Journal> fuzzySearch(String keyword) { public List<Journal> fuzzySearch(String keyword) {
// TODO Auto-generated method stub Specification<Journal> specification = fuzzySpecification(keyword);
return Collections.emptyList(); return journalDao.findAll(specification);
} }
private Specification<Journal> fuzzySpecification(String keyword) {
return new Specification<Journal>() {
private static final long serialVersionUID = 1L;
@Override
public Predicate toPredicate(Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
List<Predicate> predicateList = new ArrayList<Predicate>();
predicateList.add(criteriaBuilder.like(root.get("journalNo").as(String.class),"%"+keyword+"%"));
predicateList.add(criteriaBuilder.like(root.get("title").as(String.class),"%"+keyword+"%"));
query.orderBy(criteriaBuilder.desc(root.get("journalNo").as(Integer.class)));
return criteriaBuilder.or( predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
public boolean isLatest10ByJournalId(String journalId) { public boolean isLatest10ByJournalId(String journalId) {
return null!=journalDao.isLatest10ByJournalId(journalId); return null!=journalDao.isLatest10ByJournalId(journalId);

@ -1,6 +1,7 @@
package com.luoo.music.service; package com.luoo.music.service;
import com.luoo.music.dao.JournalSongDao; import com.luoo.music.dao.JournalSongDao;
import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.JournalSong; import com.luoo.music.pojo.JournalSong;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -155,7 +156,22 @@ public class JournalSongService {
} }
public List<JournalSong> fuzzySearch(String keyword) { public List<JournalSong> fuzzySearch(String keyword) {
// TODO Auto-generated method stub Specification<JournalSong> specification = fuzzySpecification(keyword);
return Collections.emptyList(); return journalSongDao.findAll(specification);
}
private Specification<JournalSong> fuzzySpecification(String keyword) {
return new Specification<JournalSong>() {
private static final long serialVersionUID = 1L;
@Override
public Predicate toPredicate(Root<JournalSong> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
List<Predicate> predicateList = new ArrayList<Predicate>();
predicateList.add(criteriaBuilder.like(root.get("name").as(String.class),"%"+keyword+"%"));
predicateList.add(criteriaBuilder.like(root.get("artist").as(String.class),"%"+keyword+"%"));
predicateList.add(criteriaBuilder.like(root.get("album").as(String.class),"%"+keyword+"%"));
predicateList.add(criteriaBuilder.like(root.get("journalNo").as(String.class),"%"+keyword+"%"));
query.orderBy(criteriaBuilder.asc(root.get("name")));
return criteriaBuilder.or(predicateList.toArray(new Predicate[predicateList.size()]));
}
};
} }
} }

Loading…
Cancel
Save