Improve search
This commit is contained in:
parent
a89e7953a0
commit
a64f31cffe
|
@ -20,6 +20,7 @@ import android.os.AsyncTask;
|
|||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.android.client.API;
|
||||
|
@ -340,10 +341,25 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
apiResponse = new APIResponse();
|
||||
Results results = new Results();
|
||||
List<app.fedilab.android.client.Entities.Status> statuses = new TimelineCacheDAO(contextReference.get(), db).search(tag, max_id);
|
||||
results.setStatuses(statuses);
|
||||
if( statuses != null && statuses.size() > 0 ) {
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
List<app.fedilab.android.client.Entities.Status> statusesNew = null;
|
||||
if( statuses != null){
|
||||
statusesNew = new ArrayList<>();
|
||||
for(app.fedilab.android.client.Entities.Status status: statuses){
|
||||
if (tag != null) {
|
||||
String[] searches = tag.split(" ");
|
||||
for (String search : searches) {
|
||||
if (status.getContent().contains(search) || status.getSpoiler_text().contains(search)) {
|
||||
statusesNew.add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
results.setStatuses(statusesNew);
|
||||
|
||||
apiResponse.setResults(results);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -152,12 +153,21 @@ public class TimelineCacheDAO {
|
|||
String instance = Helper.getLiveInstance(context);
|
||||
try {
|
||||
Cursor c;
|
||||
if( word != null && max_id != null) {
|
||||
c = db.query(Sqlite.TABLE_TIMELINE_CACHE, null, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\" AND " + Sqlite.COL_STATUS_ID +" < '" + max_id +"' AND " + Sqlite.COL_CACHE + " LIKE '%" + word +"%'", null, null, null, Sqlite.COL_STATUS_ID+ " DESC", "40");
|
||||
return cursorToListStatus(c);
|
||||
}else if (word != null){
|
||||
c = db.query(Sqlite.TABLE_TIMELINE_CACHE, null, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\" AND " + Sqlite.COL_CACHE + " LIKE '%" + word +"%'", null, null, null, Sqlite.COL_STATUS_ID+ " DESC", "40");
|
||||
return cursorToListStatus(c);
|
||||
if (word != null){
|
||||
String[] searches = word.split(" ");
|
||||
StringBuilder query = new StringBuilder(" (");
|
||||
for(String search: searches){
|
||||
query.append(Sqlite.COL_CACHE + " LIKE '%").append(search).append("%' OR ");
|
||||
}
|
||||
query = new StringBuilder(query.substring(0, query.length() - 3));
|
||||
query.append(") ");
|
||||
if (max_id != null) {
|
||||
c = db.query(Sqlite.TABLE_TIMELINE_CACHE, null, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\" AND " + Sqlite.COL_STATUS_ID + " < '" + max_id + "' AND " + query, null, null, null, Sqlite.COL_STATUS_ID + " DESC", "40");
|
||||
return cursorToListStatus(c);
|
||||
} else {
|
||||
c = db.query(Sqlite.TABLE_TIMELINE_CACHE, null, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\" AND " + query, null, null, null, Sqlite.COL_STATUS_ID + " DESC", "40");
|
||||
return cursorToListStatus(c);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue