Guest User

Untitled

a guest
May 26th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. public List<GroupPost> findBySubject(final String subject, final Group group, final User user, final int offset,
  2. final int limit) {
  3. if (user == null && group == null) {
  4. return findBySQL("select * from group_posts,to_tsquery('english','" + SQLUtils.vectorize(subject)
  5. + "') query where query @@ vectors order by ts_rank_cd(vectors,query) desc", GroupPost.class,
  6. offset, limit);
  7. } else if (user != null && group == null) {
  8. return findBySQL(
  9. "select gp.* from group_posts gp,to_tsquery('english','"
  10. + SQLUtils.vectorize(subject)
  11. + "') query where query @@ gp.vectors and gp.group_id in (select group_id from users_group_membership where user_id=?) order by ts_rank_cd(gp.vectors,query) desc",
  12. GroupPost.class, offset, limit, user.getId());
  13. } else if (user == null && group != null) {
  14. return findBySQL(
  15. "select gp.* from group_posts gp,groups g,to_tsquery('english','"
  16. + SQLUtils.vectorize(subject)
  17. + "') query where query @@ gp.vectors and g.id=? and gp.group_id=g.id order by ts_rank_cd(gp.vectors,query) desc",
  18. GroupPost.class, offset, limit, group.getId());
  19. } else {
  20. return findBySQL(
  21. "select gp.* from group_posts gp,groups g,to_tsquery('english','"
  22. + SQLUtils.vectorize(subject)
  23. + "') query where query @@ gp.vectors and g.id=? and gp.group_id=g.id and gp.group_id in (select group_id from users_group_membership where user_id=?) order by ts_rank_cd(gp.vectors,query) desc",
  24. GroupPost.class, offset, limit, group.getId(), user.getId());
  25. }
  26. }
  27.  
  28. public int countBySubject(final String subject, final Group group, final User user) {
  29. if (user == null && group == null) {
  30. return countSQL("select count(*) from group_posts,to_tsquery('english','" + SQLUtils.vectorize(subject)
  31. + "') query where query @@ vectors");
  32. } else if (user != null && group == null) {
  33. return countSQL(
  34. "select count(*) from group_posts gp,to_tsquery('english','"
  35. + SQLUtils.vectorize(subject)
  36. + "') query where query @@ gp.vectors and gp.group_id in (select group_id from users_group_membership where user_id=?)",
  37. user.getId());
  38. } else if (user == null && group != null) {
  39. return countSQL("select count(*) from group_posts gp,groups g,to_tsquery('english','"
  40. + SQLUtils.vectorize(subject)
  41. + "') query where query @@ gp.vectors and g.id=? and gp.group_id=g.id", group.getId());
  42. } else {
  43. return countSQL(
  44. "select count(*) from group_posts gp,groups g,to_tsquery('english','"
  45. + SQLUtils.vectorize(subject)
  46. + "') query where query @@ gp.vectors g.id=? and gp.group_id=g.id and gp.group_id in (select group_id from users_group_membership where user_id=?)",
  47. group.getId(), user.getId());
  48. }
  49. }
Add Comment
Please, Sign In to add comment