1 16 package org.javabb.action; 17 18 import java.util.List ; 19 20 import org.javabb.action.infra.BaseAction; 21 import org.javabb.component.PostFormatter; 22 import org.javabb.transaction.PostTransaction; 23 import org.javabb.vo.Post; 24 25 import com.opensymphony.xwork.Action; 26 27 28 36 public class SearchAction extends BaseAction { 37 38 public static final String EMPTY = "empty"; 39 40 private String query; 41 42 private int page; 43 private int totalRowsFound; 44 private boolean empty = false; 45 46 private List posts; 47 private PostTransaction postTransaction; 48 49 private PostFormatter postFormatter; 50 51 public String searchInPosts(){ 52 posts = postTransaction.findInPosts(query, page); 53 return SUCCESS; 54 } 55 56 59 public void setPostFormatter(PostFormatter postFormatter) { 60 this.postFormatter = postFormatter; 61 } 62 63 68 public String execute() { 69 70 return Action.SUCCESS; 71 72 } 73 74 79 public String search() { 80 log.debug("Search: [query]:" + query); 81 82 if(query != null){ 83 if(query.indexOf(" ") > 0 && query.indexOf(" AND ") == -1){ 84 query = query.replaceAll(" ", " AND "); 85 } 86 } 87 posts = postTransaction.findByQuery(query, page); 88 if(posts.isEmpty()) { 89 empty = true; 90 log.debug("Search: [No rows found]"); 91 return EMPTY; 92 } 93 totalRowsFound = postTransaction.getTotalRowsOfLucene(query); 94 log.debug("Search: [total rows]:" + totalRowsFound); 95 96 return SUCCESS; 97 } 98 99 100 104 public String formatPostWithoutBBCode(Post post) { 105 return postFormatter.formatWithoutBBCode(post); 106 } 107 108 109 public boolean isEmpty() { 110 return empty; 111 } 112 113 114 public void setEmpty( boolean empty ) { 115 this.empty = empty; 116 } 117 118 119 public List getPosts() { 120 return posts; 121 } 122 123 124 public void setPosts( List posts ) { 125 126 this.posts = posts; 127 } 128 129 130 public PostTransaction getPostTransaction() { 131 132 return postTransaction; 133 } 134 135 136 public void setPostTransaction( PostTransaction postTransaction ) { 137 138 this.postTransaction = postTransaction; 139 } 140 141 142 public String getQuery() { 143 144 return query; 145 } 146 147 148 public void setQuery( String query ) { 149 150 this.query = query; 151 } 152 153 154 public int getPage() { 155 156 return page; 157 } 158 159 160 public void setPage( int page ) { 161 162 this.page = page; 163 } 164 165 public int getTotalRowsFound() { 166 return totalRowsFound; 167 } 168 169 public void setTotalRowsFound(int totalRowsFound) { 170 this.totalRowsFound = totalRowsFound; 171 } 172 173 174 } 175 | Popular Tags |