Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<GroupPost> findBySubject(final String subject, final Group group, final User user, final int offset,
- final int limit) {
- if (user == null && group == null) {
- return findBySQL("select * from group_posts,to_tsquery('english','" + SQLUtils.vectorize(subject)
- + "') query where query @@ vectors order by ts_rank_cd(vectors,query) desc", GroupPost.class,
- offset, limit);
- } else if (user != null && group == null) {
- return findBySQL(
- "select gp.* from group_posts gp,to_tsquery('english','"
- + SQLUtils.vectorize(subject)
- + "') 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",
- GroupPost.class, offset, limit, user.getId());
- } else if (user == null && group != null) {
- return findBySQL(
- "select gp.* from group_posts gp,groups g,to_tsquery('english','"
- + SQLUtils.vectorize(subject)
- + "') query where query @@ gp.vectors and g.id=? and gp.group_id=g.id order by ts_rank_cd(gp.vectors,query) desc",
- GroupPost.class, offset, limit, group.getId());
- } else {
- return findBySQL(
- "select gp.* from group_posts gp,groups g,to_tsquery('english','"
- + SQLUtils.vectorize(subject)
- + "') 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",
- GroupPost.class, offset, limit, group.getId(), user.getId());
- }
- }
- public int countBySubject(final String subject, final Group group, final User user) {
- if (user == null && group == null) {
- return countSQL("select count(*) from group_posts,to_tsquery('english','" + SQLUtils.vectorize(subject)
- + "') query where query @@ vectors");
- } else if (user != null && group == null) {
- return countSQL(
- "select count(*) from group_posts gp,to_tsquery('english','"
- + SQLUtils.vectorize(subject)
- + "') query where query @@ gp.vectors and gp.group_id in (select group_id from users_group_membership where user_id=?)",
- user.getId());
- } else if (user == null && group != null) {
- return countSQL("select count(*) from group_posts gp,groups g,to_tsquery('english','"
- + SQLUtils.vectorize(subject)
- + "') query where query @@ gp.vectors and g.id=? and gp.group_id=g.id", group.getId());
- } else {
- return countSQL(
- "select count(*) from group_posts gp,groups g,to_tsquery('english','"
- + SQLUtils.vectorize(subject)
- + "') 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=?)",
- group.getId(), user.getId());
- }
- }
Add Comment
Please, Sign In to add comment