protected <T> List<T> doSearch(Query<T> query, int limit, int offset){
// TODO this is a very raw impl: need some work certainly
try {
Connection conn = this.getConnection();
ClassInfo ci = ClassInfo.getClassInfo(query.getQueriedClass());
// doesn't index a table that has already been indexed
if(!tableIndexMap.containsKey(ci.tableName)){
List<String> colList = ci.getUpdateFieldsColumnNames();
String cols = null;
if(!colList.isEmpty()){
cols = "";
// removes auto generated IDs from index
int sz = colList.size();
for (int i=0; i<sz; i++) {
if("h2".equals(dbMode)) cols+=colList.get(i).toUpperCase();
// !!! mysql mode means case INsensitive to lowercase !!!!
else if("mysql".equals(dbMode)) cols+=colList.get(i).toLowerCase();
else cols+=colList.get(i).toUpperCase();
if(i<sz-1) cols += ",";
}
}
// creates the index
FullText.createIndex(conn, "PUBLIC", ci.tableName.toUpperCase(), cols);
tableIndexMap.put(ci.tableName, true);
}
String searchString = "";
Iterator<QueryFilterSearch> it = query.getSearches().iterator();
boolean first = true;
while(it.hasNext()){
if(!first){
searchString += " ";
}else {
first = false;
}
searchString += it.next().match;
}
ResultSet rs = FullText.searchData(conn, searchString, limit, offset);
List<T> res = new ArrayList<T>();
Field idField = ci.getIdField();
Class<?> idClass = idField.getType();
while(rs.next()) {
//String queryStr = rs.getString("QUERY");
//String score = rs.getString("SCORE");
//Array columns = rs.getArray("COLUMNS");